From 9f07b36c4480a3e8e2a46906748bee28e7780f10 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 15 Oct 2026 21:01:48 +0500 Subject: test: add new tests, fix old ones --- test/lib/test.sh | 7 +++---- test/tst-fail.sh | 6 ++---- test/tst-filter.sh | 23 +++++++++++++++++++++++ test/tst-should-fail.sh | 16 ++++++++++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 test/tst-filter.sh create mode 100644 test/tst-should-fail.sh diff --git a/test/lib/test.sh b/test/lib/test.sh index 56920a2..7fca67b 100644 --- a/test/lib/test.sh +++ b/test/lib/test.sh @@ -1,5 +1,5 @@ test_run_harness() { - "$tests_dir/../harness" -d "$test_root_dir" 2>&1 + "$tests_dir/../harness" -d "$test_root_dir" "$@" 2>&1 } test_check_harness_log() { @@ -11,11 +11,10 @@ test_check_harness_log() { local output="$1" shift - log "Checking output log for a substring..." - local str for str; do - if ! echo "$output" | grep -F $'\n'"$str"$'\n' > /dev/null; then + log "Checking output log for line: $str" + if ! echo "$output" | grep -F --line-regexp "$str" > /dev/null; then fail "Couldn't find the expected string: $str" return 1 fi diff --git a/test/tst-fail.sh b/test/tst-fail.sh index 3c12ee3..8c60cf8 100644 --- a/test/tst-fail.sh +++ b/test/tst-fail.sh @@ -1,15 +1,13 @@ test_run() { cat > "$test_root_dir/$test_file" <<'EOF' -test_should_fail=1 - test_run() { log "I'm a failure" false } EOF - local output - output="$( test_run_harness )" + local output= + output="$( test_run_harness )" || true test_check_harness_log "$output" "$test_file | I'm a failure" test_check_harness_summary "$output" 0 1 diff --git a/test/tst-filter.sh b/test/tst-filter.sh new file mode 100644 index 0000000..3707f6d --- /dev/null +++ b/test/tst-filter.sh @@ -0,0 +1,23 @@ +test_run() { + local i + for i in 1 2 3; do + cat > "$test_root_dir/tst-$i.sh" < "$test_root_dir/$test_file" <<'EOF' +test_should_fail=1 + +test_run() { + log "I'm a failure" + false +} +EOF + + local output + output="$( test_run_harness )" + + test_check_harness_log "$output" "$test_file | I'm a failure" + test_check_harness_summary "$output" 1 0 +} -- cgit v1.3