mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-10-03 20:21:01 +00:00
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 commit83c9fdb78b
("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:5d7f6c36e0
("walk: directory is expected to be walked. A file is not.") Fixes:2d841d54bf
("test: testing the double -f comparison") Fixes:f6c295f2e9
("test: cli: add unicode verification test") Fixes:071977cef6
("test: cli: add xattr tests") Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
25 lines
656 B
Bash
25 lines
656 B
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
name=$(basename $0)
|
|
root="$(dirname $(dirname $(dirname $0)))"
|
|
gomtree=$(go run ${root}/test/realpath/main.go ${root}/gomtree)
|
|
t=$(mktemp -d /tmp/go-mtree.XXXXXX)
|
|
|
|
echo "[${name}] Running in ${t}"
|
|
|
|
## testing comparing two files
|
|
|
|
pushd ${root}
|
|
mkdir -p ${t}/extract
|
|
git archive --format=tar HEAD^{tree} . | tar -C ${t}/extract/ -x
|
|
|
|
${gomtree} -K sha256digest -c -p ${t}/extract/ > ${t}/${name}-1.mtree
|
|
rm -rf ${t}/extract/*.go
|
|
${gomtree} -K sha256digest -c -p ${t}/extract/ > ${t}/${name}-2.mtree
|
|
|
|
# this _ought_ to fail because the files are missing now
|
|
(! ${gomtree} -f ${t}/${name}-1.mtree -f ${t}/${name}-2.mtree)
|
|
|
|
popd
|
|
rm -rf ${t}
|