Skip to content

Commit 945eeed

Browse files
committed
tests: cli: properly check for exit status codes in error cases
POSIX explicitly requires "set -e" to NOT treat "! cmd" as an error even if fails[1]: > The -e setting shall be ignored when executing the compound list > following the while, until, if, or elif reserved word, *a pipeline > beginning with the ! reserved word*, or any command of an AND-OR list > other than the last. *[emphasis added]* And bash has similar documentation on this behaviour[2]. This means that our tests were completely ineffective at detecting error codes from gomtree, and as a result we did not detect the regression in commit 83c9fdb ("refactor: prefactor for adding new subcommands"). The simplest solution (as done in this patch) is to just wrap all of the failing examples in a subshell, which causes the shell to no longer consider them exempt from "set -e". A more complete solution would be to either switch to something like bats entirely or at least use something like their "run" helper function to test for exit status codes correctly. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set [2]: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html Fixes: 5d7f6c3 ("walk: directory is expected to be walked. A file is not.") Fixes: 2d841d5 ("test: testing the double -f comparison") Fixes: f6c295f ("test: cli: add unicode verification test") Fixes: 071977c ("test: cli: add xattr tests") Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 23151ae commit 945eeed

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

test/cli/0003.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
1717
$gomtree -c -k "sha256digest,xattrs" -p ${t}/dir > ${t}/${name}.mtree
1818

1919
setfattr -n user.mtree.testing -v "bananas and lemons" "${t}/dir/file"
20-
! $gomtree -p ${t}/dir -f ${t}/${name}.mtree
20+
(! $gomtree -p ${t}/dir -f ${t}/${name}.mtree)
2121

2222
setfattr -x user.mtree.testing "${t}/dir/file"
23-
! $gomtree -p ${t}/dir -f ${t}/${name}.mtree
23+
(! $gomtree -p ${t}/dir -f ${t}/${name}.mtree)
2424

2525
setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
2626
setfattr -n user.mtree.another -v "another a=b" "${t}/dir/file"
27-
! $gomtree -p ${t}/dir -f ${t}/${name}.mtree
27+
(! $gomtree -p ${t}/dir -f ${t}/${name}.mtree)
2828

2929
setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
3030
setfattr -x user.mtree.another "${t}/dir/file"

test/cli/0009.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${
2424

2525
# Modify it and make sure that it successfully figures out what changed.
2626
echo "othe data" > "${t}/root/$(printf 'this file has \u042a some unicode !!')"
27-
! ${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${t}/root
27+
(! ${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${t}/root)
2828

2929
echo "some data" > "${t}/root/$(printf 'this file has \u042a some unicode !!')"
3030
${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${t}/root

test/cli/0010.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rm -rf ${t}/extract/*.go
1919
${gomtree} -K sha256digest -c -p ${t}/extract/ > ${t}/${name}-2.mtree
2020

2121
# this _ought_ to fail because the files are missing now
22-
! ${gomtree} -f ${t}/${name}-1.mtree -f ${t}/${name}-2.mtree
22+
(! ${gomtree} -f ${t}/${name}-1.mtree -f ${t}/${name}-2.mtree)
2323

2424
popd
2525
rm -rf ${t}

test/cli/0011.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ touch ${t}/foo
1616

1717
## can not walk a file. We're expecting a directory.
1818
## https://github.com/vbatts/go-mtree/issues/166
19-
! ${gomtree} -c -K uname,uid,gname,gid,type,nlink,link,mode,flags,xattr,xattrs,size,time,sha256 -p ${t}/foo
19+
(! ${gomtree} -c -K uname,uid,gname,gid,type,nlink,link,mode,flags,xattr,xattrs,size,time,sha256 -p ${t}/foo)
2020

2121
popd
2222
rm -rf ${t}

0 commit comments

Comments
 (0)