summary refs log tree commit diff
path: root/lib/fileset/tests.sh
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-11-07 01:04:13 +0100
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2023-11-22 18:46:57 +0000
commit95993214042d6e2ecdea1981c413445d0d2e9013 (patch)
tree2e812c0a1d8cab6e9696f5f5f8e4d18fbd932554 /lib/fileset/tests.sh
parenta8df862a33ceb5f099d2c61fb17c46d191f95e07 (diff)
lib.fileset.maybeMissing: init
(cherry picked from commit 1cc2c2f13d7a548759a55f710fd0222da14c5403)
Diffstat (limited to 'lib/fileset/tests.sh')
-rwxr-xr-xlib/fileset/tests.sh37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh
index 06f92f297d88d..81376bc451b10 100755
--- a/lib/fileset/tests.sh
+++ b/lib/fileset/tests.sh
@@ -413,7 +413,8 @@ expectFailure 'toSource { root = ./.; fileset = cleanSourceWith { src = ./.; };
 \s*Note that this only works for sources created from paths.'
 
 # Path coercion errors for non-existent paths
-expectFailure 'toSource { root = ./.; fileset = ./a; }' 'lib.fileset.toSource: `fileset` \('"$work"'/a\) is a path that does not exist.'
+expectFailure 'toSource { root = ./.; fileset = ./a; }' 'lib.fileset.toSource: `fileset` \('"$work"'/a\) is a path that does not exist.
+\s*To create a file set from a path that may not exist, use `lib.fileset.maybeMissing`.'
 
 # File sets cannot be evaluated directly
 expectFailure 'union ./. ./.' 'lib.fileset: Directly evaluating a file set is not supported.
@@ -1450,6 +1451,40 @@ checkGitTracked
 
 rm -rf -- *
 
+## lib.fileset.maybeMissing
+
+# Argument must be a path
+expectFailure 'maybeMissing "someString"' 'lib.fileset.maybeMissing: Argument \("someString"\) is a string-like value, but it should be a path instead.'
+expectFailure 'maybeMissing null' 'lib.fileset.maybeMissing: Argument is of type null, but it should be a path instead.'
+
+tree=(
+)
+checkFileset 'maybeMissing ./a'
+checkFileset 'maybeMissing ./b'
+checkFileset 'maybeMissing ./b/c'
+
+# Works on single files
+tree=(
+    [a]=1
+    [b/c]=0
+    [b/d]=0
+)
+checkFileset 'maybeMissing ./a'
+tree=(
+    [a]=0
+    [b/c]=1
+    [b/d]=0
+)
+checkFileset 'maybeMissing ./b/c'
+
+# Works on directories
+tree=(
+    [a]=0
+    [b/c]=1
+    [b/d]=1
+)
+checkFileset 'maybeMissing ./b'
+
 # TODO: Once we have combinators and a property testing library, derive property tests from https://en.wikipedia.org/wiki/Algebra_of_sets
 
 echo >&2 tests ok