diff options
| author | Egor Tensin <egor@tensin.name> | 2026-10-15 21:01:48 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-10-15 21:01:48 +0500 |
| commit | 9f07b36c4480a3e8e2a46906748bee28e7780f10 (patch) | |
| tree | 3c8a875e686be7992ad3724e9db90eaa93f86197 | |
| parent | test: add a new test (diff) | |
| download | test-harness-1.0.2.tar.gz test-harness-1.0.2.zip | |
test: add new tests, fix old onesv1.0.2
| -rw-r--r-- | test/lib/test.sh | 7 | ||||
| -rw-r--r-- | test/tst-fail.sh | 6 | ||||
| -rw-r--r-- | test/tst-filter.sh | 23 | ||||
| -rw-r--r-- | test/tst-should-fail.sh | 16 |
4 files changed, 44 insertions, 8 deletions
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" <<EOF +test_run() { + log "Hello from test #$i" +} +EOF + done + + local output + output="$( test_run_harness )" + + test_check_harness_log "$output" "tst-1.sh | Hello from test #1" + test_check_harness_log "$output" "tst-2.sh | Hello from test #2" + test_check_harness_log "$output" "tst-3.sh | Hello from test #3" + test_check_harness_summary "$output" 3 0 + + output="$( test_run_harness -f '*2*' )" + + test_check_harness_log "$output" "tst-2.sh | Hello from test #2" + test_check_harness_summary "$output" 1 0 +} diff --git a/test/tst-should-fail.sh b/test/tst-should-fail.sh new file mode 100644 index 0000000..98d22f5 --- /dev/null +++ b/test/tst-should-fail.sh @@ -0,0 +1,16 @@ +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 )" + + test_check_harness_log "$output" "$test_file | I'm a failure" + test_check_harness_summary "$output" 1 0 +} |
