cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

fix/drop-hero-notarization-note
goq / scripts / tests / shell-test-discovery.sh
shell-test-discovery.sh 3.0K executable
1#!/usr/bin/env bash23set -euo pipefail45script_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"6repo_dir="$(CDPATH='' cd -- "$script_dir/../.." && pwd -P)"7runner="$repo_dir/scripts/run-shell-tests.sh"8temp_parent="${TMPDIR:-/tmp}"9temp_parent="${temp_parent%/}"10temp_root="$(mktemp -d "$temp_parent/goq-shell-test-discovery.XXXXXX")"1112cleanup() {13 local status=$?14 trap - EXIT INT TERM HUP15 case "$temp_root" in16 "$temp_parent"/goq-shell-test-discovery.??????) rm -rf -- "$temp_root" ;;17 esac18 exit "$status"19}20trap cleanup EXIT INT TERM HUP2122write_passing_test() {23 local path="$1"24 local marker="$2"25 printf '%s\n' \26 '#!/usr/bin/env bash' \27 'set -euo pipefail' \28 "printf '%s\\n' '$marker' >>\"\$GOQ_TEST_MARKERS\"" \29 >"$path"30 chmod 0755 "$path"31}3233assert_failed_with() {34 local expected="$1"35 local output_path="$2"36 shift 23738 if "$@" >"$output_path" 2>&1; then39 printf 'command unexpectedly succeeded: %s\n' "$*" >&240 exit 141 fi42 if ! grep -Fq -- "$expected" "$output_path"; then43 printf 'failure did not contain expected text: %s\n' "$expected" >&244 sed -n '1,120p' "$output_path" >&245 exit 146 fi47}4849ordered_dir="$temp_root/ordered"50ordered_markers="$temp_root/ordered.markers"51mkdir "$ordered_dir"52write_passing_test "$ordered_dir/zeta.sh" zeta53write_passing_test "$ordered_dir/.hidden.sh" hidden54write_passing_test "$ordered_dir/alpha.sh" alpha55GOQ_TEST_MARKERS="$ordered_markers" "$runner" "$ordered_dir" \56 >"$temp_root/ordered.out"57printf '%s\n' hidden alpha zeta >"$temp_root/ordered.expected"58cmp "$temp_root/ordered.expected" "$ordered_markers"59for expected_path in \60 "$ordered_dir/.hidden.sh" \61 "$ordered_dir/alpha.sh" \62 "$ordered_dir/zeta.sh"63do64 grep -Fq "shell_test_discovered=$expected_path" "$temp_root/ordered.out"65 grep -Fq "shell_test_start=$expected_path" "$temp_root/ordered.out"66done6768nonexec_dir="$temp_root/nonexec"69nonexec_markers="$temp_root/nonexec.markers"70mkdir "$nonexec_dir"71write_passing_test "$nonexec_dir/alpha.sh" should-not-run72printf '%s\n' '#!/usr/bin/env bash' 'exit 0' >"$nonexec_dir/zeta.sh"73chmod 0644 "$nonexec_dir/zeta.sh"74assert_failed_with \75 "shell test entry is not executable: $nonexec_dir/zeta.sh" \76 "$temp_root/nonexec.out" \77 env GOQ_TEST_MARKERS="$nonexec_markers" "$runner" "$nonexec_dir"78grep -Fq "shell_test_discovered=$nonexec_dir/zeta.sh" "$temp_root/nonexec.out"79[[ ! -e "$nonexec_markers" ]]8081symlink_dir="$temp_root/symlink"82symlink_markers="$temp_root/symlink.markers"83mkdir "$symlink_dir"84write_passing_test "$symlink_dir/alpha.sh" should-not-run85ln -s alpha.sh "$symlink_dir/zeta.sh"86assert_failed_with \87 "shell test entry must be a regular, non-symlink file: $symlink_dir/zeta.sh" \88 "$temp_root/symlink.out" \89 env GOQ_TEST_MARKERS="$symlink_markers" "$runner" "$symlink_dir"90[[ ! -e "$symlink_markers" ]]9192empty_dir="$temp_root/empty"93mkdir "$empty_dir"94assert_failed_with \95 "no shell tests were discovered in: $empty_dir" \96 "$temp_root/empty.out" \97 "$runner" "$empty_dir"9899printf 'shell_test_discovery_tests=ok\n'