summaryrefslogtreecommitdiff
path: root/lib/fileset/tests.sh
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2023-11-01 19:40:45 +0100
committerGitHub <noreply@github.com>2023-11-01 19:40:45 +0100
commitfc28c5e5b79ada17ce17b5c83e07a2949b959fcf (patch)
tree8955af520cba3d6f3539d8b182960b7bd376f31b /lib/fileset/tests.sh
parentMerge pull request #264728 from r-ryantm/auto-update/wander (diff)
parentlib.fileset.difference: init (diff)
downloadnixpkgs-fc28c5e5b79ada17ce17b5c83e07a2949b959fcf.tar.gz
Merge pull request #259065 from tweag/fileset.difference
`lib.fileset.difference`: init
Diffstat (limited to 'lib/fileset/tests.sh')
-rwxr-xr-xlib/fileset/tests.sh98
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh
index 5b756b8fc593..2df0727bde38 100755
--- a/lib/fileset/tests.sh
+++ b/lib/fileset/tests.sh
@@ -684,6 +684,104 @@ tree=(
)
checkFileset 'intersection (unions [ ./a/b ./c/d ./c/e ]) (unions [ ./a ./c/d/f ./c/e ])'
+## Difference
+
+# Subtracting something from itself results in nothing
+tree=(
+ [a]=0
+)
+checkFileset 'difference ./. ./.'
+
+# The tree of the second argument should not be evaluated if not needed
+checkFileset 'difference _emptyWithoutBase (_create ./. (abort "This should not be used!"))'
+checkFileset 'difference (_create ./. null) (_create ./. (abort "This should not be used!"))'
+
+# Subtracting nothing gives the same thing back
+tree=(
+ [a]=1
+)
+checkFileset 'difference ./. _emptyWithoutBase'
+checkFileset 'difference ./. (_create ./. null)'
+
+# Subtracting doesn't influence the base path
+mkdir a b
+touch {a,b}/x
+expectEqual 'toSource { root = ./a; fileset = difference ./a ./b; }' 'toSource { root = ./a; fileset = ./a; }'
+rm -rf -- *
+
+# Also not the other way around
+mkdir a
+expectFailure 'toSource { root = ./a; fileset = difference ./. ./a; }' 'lib.fileset.toSource: `fileset` could contain files in '"$work"', which is not under the `root` \('"$work"'/a\). Potential solutions:
+\s*- Set `root` to '"$work"' or any directory higher up. This changes the layout of the resulting store path.
+\s*- Set `fileset` to a file set that cannot contain files outside the `root` \('"$work"'/a\). This could change the files included in the result.'
+rm -rf -- *
+
+# Difference actually works
+# We test all combinations of ./., ./a, ./a/x and ./b
+tree=(
+ [a/x]=0
+ [a/y]=0
+ [b]=0
+ [c]=0
+)
+checkFileset 'difference ./. ./.'
+checkFileset 'difference ./a ./.'
+checkFileset 'difference ./a/x ./.'
+checkFileset 'difference ./b ./.'
+checkFileset 'difference ./a ./a'
+checkFileset 'difference ./a/x ./a'
+checkFileset 'difference ./a/x ./a/x'
+checkFileset 'difference ./b ./b'
+tree=(
+ [a/x]=0
+ [a/y]=0
+ [b]=1
+ [c]=1
+)
+checkFileset 'difference ./. ./a'
+tree=(
+ [a/x]=1
+ [a/y]=1
+ [b]=0
+ [c]=0
+)
+checkFileset 'difference ./a ./b'
+tree=(
+ [a/x]=1
+ [a/y]=0
+ [b]=0
+ [c]=0
+)
+checkFileset 'difference ./a/x ./b'
+tree=(
+ [a/x]=0
+ [a/y]=1
+ [b]=0
+ [c]=0
+)
+checkFileset 'difference ./a ./a/x'
+tree=(
+ [a/x]=0
+ [a/y]=0
+ [b]=1
+ [c]=0
+)
+checkFileset 'difference ./b ./a'
+checkFileset 'difference ./b ./a/x'
+tree=(
+ [a/x]=0
+ [a/y]=1
+ [b]=1
+ [c]=1
+)
+checkFileset 'difference ./. ./a/x'
+tree=(
+ [a/x]=1
+ [a/y]=1
+ [b]=0
+ [c]=1
+)
+checkFileset 'difference ./. ./b'
## File filter