diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2024-02-13 22:46:11 +0100 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2024-02-26 20:21:50 +0100 |
commit | e3a6e380337820d17c154c54eaf50ab95bba5c0d (patch) | |
tree | a7e1cdc262c9927dc025e856f670c052eb472c98 /lib/fileset/tests.sh | |
parent | c5b544922979418b8ed0d25f66fe344c9ef96fa7 (diff) |
lib.fileset.toList: init
Diffstat (limited to 'lib/fileset/tests.sh')
-rwxr-xr-x | lib/fileset/tests.sh | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh index af8338eb7855f..654a7cefc9f1f 100755 --- a/lib/fileset/tests.sh +++ b/lib/fileset/tests.sh @@ -275,7 +275,6 @@ createTree() { # ) # checkFileset './a' # Pass the fileset as the argument checkFileset() { - # New subshell so that we can have a separate trap handler, see `trap` below local fileset=$1 # Create the tree @@ -283,16 +282,20 @@ checkFileset() { # Process the tree into separate arrays for included paths, excluded paths and excluded files. local -a included=() + local -a includedFiles=() local -a excluded=() local -a excludedFiles=() for p in "${!tree[@]}"; do case "${tree[$p]}" in 1) included+=("$p") + # If keys end with a `/` we treat them as directories, otherwise files + if [[ ! "$p" =~ /$ ]]; then + includedFiles+=("$p") + fi ;; 0) excluded+=("$p") - # If keys end with a `/` we treat them as directories, otherwise files if [[ ! "$p" =~ /$ ]]; then excludedFiles+=("$p") fi @@ -302,6 +305,10 @@ checkFileset() { esac done + # Test that lib.fileset.toList contains exactly the included files. + # The /#/./ part prefixes each element with `./` + expectEqual "toList ($fileset)" "sort lessThan [ ${includedFiles[*]/#/./} ]" + expression="toSource { root = ./.; fileset = $fileset; }" # We don't have lambda's in bash unfortunately, @@ -511,6 +518,19 @@ expectEqual '_toSourceFilter (_create /. { foo = "regular"; }) "/foo" ""' 'true' expectEqual '_toSourceFilter (_create /. { foo = null; }) "/foo" ""' 'false' +## lib.fileset.toList +# This function is mainly tested in checkFileset + +# The error context for an invalid argument must be correct +expectFailure 'toList null' 'lib.fileset.toList: Argument is of type null, but it should be a file set or a path instead.' + +# Works for the empty fileset +expectEqual 'toList _emptyWithoutBase' '[ ]' + +# Works on empty paths +expectEqual 'toList ./.' '[ ]' + + ## lib.fileset.union, lib.fileset.unions |