#!/bin/bash # End-to-end check of the memwatch output modes against tiny fixture suites, # always under the watchdog (full.sh / run.sh). Exit 0 when every check passes. # # Usage (from app/): tool/memwatch/quiet_test.sh set -u cd "$(dirname "$0")/../.." || exit 1 tmp=${TMPDIR:-/tmp} dir=$(mktemp -d "${tmp%/}/memwatch-quiet-test.XXXXXX") || exit 1 trap 'rm -rf "$dir"' EXIT export MEMWATCH_DIR="$dir/logs" pass=tool/memwatch/fixtures/passing_fixture_test.dart fail=tool/memwatch/fixtures/failing_fixture_test.dart failures=0 check() { # check local what=$1; shift if "$@"; then echo "ok $what"; else echo "FAIL $what"; failures=$((failures+1)); fi } has() { grep -qF -- "$2" "$1"; } lacks() { ! grep -qF -- "$2" "$1"; } # Stdout is a file here, so quiet is the default. tool/memwatch/full.sh "$pass" > "$dir/pass.out"; status=$? check "passing suite exits 0" [ $status = 0 ] check "passing verdict line" has "$dir/pass.out" "memwatch: PASS: 3 passed, 0 failed, 1 skipped; peak " check "passing output omits test prints" lacks "$dir/pass.out" "memwatch-noise" check "passing output is three lines" [ "$(wc -l < "$dir/pass.out")" -le 3 ] tool/memwatch/full.sh "$fail" > "$dir/fail.out"; status=$? check "failing suite exits 1" [ $status = 1 ] check "failing verdict line" has "$dir/fail.out" "memwatch: FAIL: 1 passed, 2 failed, 0 skipped; peak " check "names the expectation failure" has "$dir/fail.out" "FAILED $fail: plain expectation fails" check "shows the expectation values" has "$dir/fail.out" "Actual: 'memwatch-actual'" check "names the widget failure" has "$dir/fail.out" "FAILED $fail: widget failure with long output" check "shows the widget exception" has "$dir/fail.out" "memwatch-missing-widget" check "shows the failing app frame" has "$dir/fail.out" "$fail:20:5" check "bounds the flood of prints" has "$dir/fail.out" "printed output (last 8 of 2000 lines):" check "quiet failure output under 6 KB" [ "$(wc -c < "$dir/fail.out")" -lt 6000 ] log=$(sed -n 's/^full output: //p' "$dir/fail.out") check "full log keeps every line" has "$log" "memwatch-flood line 0 " MEMWATCH_OUTPUT=full tool/memwatch/full.sh "$fail" > "$dir/full.out"; status=$? check "full mode keeps exit 1" [ $status = 1 ] check "full mode prints the log" has "$dir/full.out" "memwatch-flood line 0 " check "full mode ends with the summary" has "$dir/full.out" "memwatch: FAIL: 1 passed, 2 failed" # A 1 KB cap forces the watchdog to kill the run: the exit status stays 137. CAP_KB=1 tool/memwatch/run.sh "$pass" > "$dir/killed.out"; status=$? check "killed run exits 137" [ $status = 137 ] check "watchdog reports the kill" has "$dir/killed.out" "KILLED at " check "summary reports the kill" has "$dir/killed.out" "memwatch: KILLED: " tool/memwatch/full.sh tool/memwatch/fixtures/missing_test.dart > "$dir/missing.out"; status=$? check "missing test file exits non-zero" [ $status != 0 ] check "missing test file still summarised" has "$dir/missing.out" "memwatch: FAIL: " [ $failures = 0 ] && echo "quiet_test: all checks passed" || echo "quiet_test: $failures checks failed" [ $failures = 0 ]