diff options
| author | Egor Tensin <egor@tensin.name> | 2026-10-15 18:19:25 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-10-15 18:19:25 +0500 |
| commit | 1e1d21c2a2266eff74db9d46fa7efd073fb44677 (patch) | |
| tree | 3fc8b8c5c1ed488dd4e0123b8093fc447f9471d9 /test | |
| parent | don't fail if lib/ doesn't exist (diff) | |
| download | test-harness-1e1d21c2a2266eff74db9d46fa7efd073fb44677.tar.gz test-harness-1e1d21c2a2266eff74db9d46fa7efd073fb44677.zip | |
add a couple of basic tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/lib/test.sh | 39 | ||||
| -rw-r--r-- | test/tst-dumb.sh | 13 | ||||
| -rw-r--r-- | test/tst-fail.sh | 16 | ||||
| -rw-r--r-- | test/tst-lib.sh | 34 |
4 files changed, 102 insertions, 0 deletions
diff --git a/test/lib/test.sh b/test/lib/test.sh new file mode 100644 index 0000000..56920a2 --- /dev/null +++ b/test/lib/test.sh @@ -0,0 +1,39 @@ +test_run_harness() { + "$tests_dir/../harness" -d "$test_root_dir" 2>&1 +} + +test_check_harness_log() { + if [ "$#" -lt 1 ]; then + log "usage: ${FUNCNAME[0]} LOG [STR...]" + return 1 + fi + + 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 + fail "Couldn't find the expected string: $str" + return 1 + fi + done +} + +test_check_harness_summary() { + if [ "$#" -ne 3 ]; then + log "usage: ${FUNCNAME[0]} LOG N_OK N_FAILED" + return 1 + fi + + local output="$1" + local n_ok="$2" + local n_failed="$3" + + log "Validating test summary..." + + test_check_harness_log "$output" "OK: $n_ok" + test_check_harness_log "$output" "FAIL: $n_failed" +} diff --git a/test/tst-dumb.sh b/test/tst-dumb.sh new file mode 100644 index 0000000..e391c46 --- /dev/null +++ b/test/tst-dumb.sh @@ -0,0 +1,13 @@ +test_run() { + cat > "$test_root_dir/$test_file" <<'EOF' +test_run() { + log "I'm dumb" +} +EOF + + local output + output="$( test_run_harness )" + + test_check_harness_log "$output" "$test_file | I'm dumb" + test_check_harness_summary "$output" 1 0 +} diff --git a/test/tst-fail.sh b/test/tst-fail.sh new file mode 100644 index 0000000..3c12ee3 --- /dev/null +++ b/test/tst-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" 0 1 +} diff --git a/test/tst-lib.sh b/test/tst-lib.sh new file mode 100644 index 0000000..8d7f876 --- /dev/null +++ b/test/tst-lib.sh @@ -0,0 +1,34 @@ +test_run() { + mkdir -- "$test_root_dir/lib" + cat > "$test_root_dir/lib/foo.sh" <<'EOF' +test_foo() { + log foo +} + +test_bar() { + log bar +} +EOF + cat > "$test_root_dir/lib/baz.sh" <<'EOF' +test_baz() { + log baz +} +EOF + + cat > "$test_root_dir/$test_file" <<'EOF' +test_run() { + test_foo + test_bar + test_baz +} +EOF + + local output + output="$( test_run_harness )" + + test_check_harness_log "$output" "$test_file | foo" + test_check_harness_log "$output" "$test_file | bar" + test_check_harness_log "$output" "$test_file | baz" + + test_check_harness_summary "$output" 1 0 +} |
