diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-11-09 01:29:38 +0100 |
---|---|---|
committer | github-actions[bot] <github-actions[bot]@users.noreply.github.com> | 2023-11-23 23:16:12 +0000 |
commit | cbe2dac1462a37d4c5f77130b7cd5f61017151f4 (patch) | |
tree | 08a8ee8522db266dee6eefcc03d229be4ea5ee7a /lib/fileset/tests.sh | |
parent | f57f9dba55515eb957a85a3c246e7d5e5c343812 (diff) |
lib.fileset.fileFilter: Predicate attribute for file extension
(cherry picked from commit 6816f28c960c523e6a30f2ad4a1cc812251f5ffb)
Diffstat (limited to 'lib/fileset/tests.sh')
-rwxr-xr-x | lib/fileset/tests.sh | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh index 81376bc451b10..077aefe371c35 100755 --- a/lib/fileset/tests.sh +++ b/lib/fileset/tests.sh @@ -847,7 +847,7 @@ checkFileset 'fileFilter (file: abort "this is not needed") ./.' # The predicate must be able to handle extra attributes touch a -expectFailure 'toSource { root = ./.; fileset = fileFilter ({ name, type }: true) ./.; }' 'called with unexpected argument '\''"lib.fileset.fileFilter: The predicate function passed as the first argument must be able to handle extra attributes for future compatibility. If you'\''re using `\{ name, file \}:`, use `\{ name, file, ... \}:` instead."'\' +expectFailure 'toSource { root = ./.; fileset = fileFilter ({ name, type, hasExt }: true) ./.; }' 'called with unexpected argument '\''"lib.fileset.fileFilter: The predicate function passed as the first argument must be able to handle extra attributes for future compatibility. If you'\''re using `\{ name, file, hasExt \}:`, use `\{ name, file, hasExt, ... \}:` instead."'\' rm -rf -- * # .name is the name, and it works correctly, even recursively @@ -895,6 +895,39 @@ expectEqual \ 'toSource { root = ./.; fileset = union ./d/a ./d/b; }' rm -rf -- * +# Check that .hasExt checks for the file extension +# The empty extension is the same as a file ending with a . +tree=( + [a]=0 + [a.]=1 + [a.b]=0 + [a.b.]=1 + [a.b.c]=0 +) +checkFileset 'fileFilter (file: file.hasExt "") ./.' + +# It can check for the last extension +tree=( + [a]=0 + [.a]=1 + [.a.]=0 + [.b.a]=1 + [.b.a.]=0 +) +checkFileset 'fileFilter (file: file.hasExt "a") ./.' + +# It can check for any extension +tree=( + [a.b.c.d]=1 +) +checkFileset 'fileFilter (file: + all file.hasExt [ + "b.c.d" + "c.d" + "d" + ] +) ./.' + # It's lazy tree=( [b]=1 |