summaryrefslogtreecommitdiff
path: root/lib/fileset/tests.sh
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2023-11-15 01:19:36 +0100
committerGitHub <noreply@github.com>2023-11-15 01:19:36 +0100
commit7e533bab6df5dc1d065adafceda44a106e3796a4 (patch)
treeec580f2bbfbeca182f93ccb7521f7676da74303e /lib/fileset/tests.sh
parentMerge pull request #267372 from cu1ch3n/update-abella (diff)
parentlib.fileset.fileFilter: Don't run predicate unnecessarily (diff)
downloadnixpkgs-7e533bab6df5dc1d065adafceda44a106e3796a4.tar.gz
Merge pull request #267381 from tweag/fileset.fileFilter-path
`fileset.fileFilter`: Don't run predicate unnecessarily
Diffstat (limited to 'lib/fileset/tests.sh')
-rwxr-xr-xlib/fileset/tests.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh
index 796a03b52f0e..5ef155d25a88 100755
--- a/lib/fileset/tests.sh
+++ b/lib/fileset/tests.sh
@@ -810,6 +810,13 @@ checkFileset 'difference ./. ./b'
## File filter
+# The first argument needs to be a function
+expectFailure 'fileFilter null (abort "this is not needed")' 'lib.fileset.fileFilter: First argument is of type null, but it should be a function instead.'
+
+# The second argument can be a file set or an existing path
+expectFailure 'fileFilter (file: abort "this is not needed") null' 'lib.fileset.fileFilter: Second argument is of type null, but it should be a file set or a path instead.'
+expectFailure 'fileFilter (file: abort "this is not needed") ./a' 'lib.fileset.fileFilter: Second argument \('"$work"'/a\) is a path that does not exist.'
+
# The predicate is not called when there's no files
tree=()
checkFileset 'fileFilter (file: abort "this is not needed") ./.'
@@ -875,6 +882,26 @@ checkFileset 'union ./c/a (fileFilter (file: assert file.name != "a"; true) ./.)
# but here we need to use ./c
checkFileset 'union (fileFilter (file: assert file.name != "a"; true) ./.) ./c'
+# Also lazy, the filter isn't called on a filtered out path
+tree=(
+ [a]=1
+ [b]=0
+ [c]=0
+)
+checkFileset 'fileFilter (file: assert file.name != "c"; file.name == "a") (difference ./. ./c)'
+
+# Make sure single files are filtered correctly
+tree=(
+ [a]=1
+ [b]=0
+)
+checkFileset 'fileFilter (file: assert file.name == "a"; true) ./a'
+tree=(
+ [a]=0
+ [b]=0
+)
+checkFileset 'fileFilter (file: assert file.name == "a"; false) ./a'
+
## Tracing
# The second trace argument is returned