rifle

coreutils in one C file, 86 tools, no GNU
git clone https://github.com/tortr-rs/rifle
Log | Files | Refs | README | LICENSE

run.sh (1534B)


      1 #!/bin/sh
      2 # run every case under GNU and under rifle, compare stdout and exit status.
      3 # a case says $X cat f. under GNU that's /usr/bin/env -- cat f. under rifle it's cat found in rifle's bin/, the plain
      4 # name, the way you'd use it, with everything else in the case (ls, find, sort...) still the system's
      5 # usage: tests/run.sh [pattern]
      6 cd "$(dirname "$0")/.."
      7 export LC_ALL=C TZ=UTC
      8 BIN=$PWD/bin
      9 [ -x "$BIN/cat" ] || { echo 'run ./build.sh first' >&2; exit 2; }
     10 T=$(mktemp -d /var/tmp/rifle-test.XXXXXX)
     11 pass=0; fail=0
     12 while IFS= read -r c; do
     13 	case $c in ''|'#'*) continue;; esac
     14 	[ -n "$1" ] && case $c in *"$1"*) ;; *) continue;; esac
     15 	# a case that starts with @ro runs with the whole filesystem read-only (bwrap), for the ones that could do harm
     16 	# if the tool had a bug: rm -rf /
     17 	ro=
     18 	case $c in '@ro '*)
     19 		command -v bwrap >/dev/null || { echo "skipped (no bwrap): $c"; continue; }
     20 		c=${c#@ro }; ro="bwrap --ro-bind / / --dev /dev --proc /proc";;
     21 	esac
     22 	rm -rf "$T/g" "$T/r"; mkdir "$T/g" "$T/r"
     23 	(cd "$T/g" && X="/usr/bin/env --" PATH=/usr/bin:/bin $ro sh -c "$c" </dev/null >"$T/g.out" 2>"$T/g.err"; echo "exit $?" >>"$T/g.out")
     24 	(cd "$T/r" && X="/usr/bin/env PATH=$BIN:/usr/bin:/bin" PATH=/usr/bin:/bin $ro sh -c "$c" </dev/null >"$T/r.out" 2>"$T/r.err"; echo "exit $?" >>"$T/r.out")
     25 	if cmp -s "$T/g.out" "$T/r.out"; then
     26 		pass=$((pass+1))
     27 	else
     28 		fail=$((fail+1))
     29 		printf "FAIL: %s\n" "$c"
     30 		diff "$T/g.out" "$T/r.out" | head -8 | sed 's/^/    /'
     31 	fi
     32 done < tests/cases
     33 rm -rf "$T"
     34 echo "$pass passed, $fail failed"