plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
9b8942d
— Peter John
2026-11-11T00:28:01+05:30
test-all.sh: a deadline per Rust test executable, and failure messages are kept
compiler/cli/tests/cli/main.rs
CHANGED
|
@@ -19,5 +19,6 @@ mod no_fbip_test;
|
|
|
19
19
|
mod old_forms_test;
|
|
20
20
|
mod replay_test;
|
|
21
21
|
mod std_bounds_test;
|
|
22
|
+
mod test_exes_script_test;
|
|
22
23
|
mod test_scope_test;
|
|
23
24
|
mod timeout_test;
|
compiler/cli/tests/cli/test_exes_script_test.rs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//! compiler/scripts/run-test-exes.sh, test-all.sh's runner of the Rust test executables, run
|
|
2
|
+
//! on stub executables: one that passes, one that fails with a message, one that fails only
|
|
3
|
+
//! beside the others, and one that hangs past the deadline.
|
|
4
|
+
use std::os::unix::fs::PermissionsExt;
|
|
5
|
+
use std::process::Command;
|
|
6
|
+
|
|
7
|
+
fn stub(dir: &std::path::Path, name: &str, body: &str) -> String {
|
|
8
|
+
let p = dir.join(name);
|
|
9
|
+
std::fs::write(&p, format!("#!/bin/sh\n{body}\n")).unwrap();
|
|
10
|
+
std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap();
|
|
11
|
+
p.display().to_string()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const FAILING: &str = "echo 'running 1 test'
|
|
15
|
+
echo 'test a::broken ... FAILED'
|
|
16
|
+
echo
|
|
17
|
+
echo 'failures:'
|
|
18
|
+
echo
|
|
19
|
+
echo '---- a::broken stdout ----'
|
|
20
|
+
echo 'assertion failed: the replay ends somewhere else'
|
|
21
|
+
echo
|
|
22
|
+
echo 'failures:'
|
|
23
|
+
echo ' a::broken'
|
|
24
|
+
exit 101";
|
|
25
|
+
|
|
26
|
+
#[test]
|
|
27
|
+
fn aHungExecutableFailsAsATimeoutAndMessagesAreKept() {
|
|
28
|
+
let dir = crate::common::Scratch::new("test_exes_script");
|
|
29
|
+
let work = dir.join("work");
|
|
30
|
+
std::fs::create_dir_all(&work).unwrap();
|
|
31
|
+
let ok = stub(&dir, "stub_ok", "echo 'test result: ok'");
|
|
32
|
+
let bad = stub(&dir, "stub_bad", FAILING);
|
|
33
|
+
// Fails the first time only (a marker file tells), as a test does beside the others.
|
|
34
|
+
let marker = dir.join("flaked");
|
|
35
|
+
let flaky = stub(&dir, "stub_flaky", &format!("if [ -e '{m}' ]; then exit 0; fi\ntouch '{m}'\n{FAILING}", m = marker.display()));
|
|
36
|
+
let hang = stub(&dir, "stub_hang", "exec sleep 30");
|
|
37
|
+
let started = std::time::Instant::now();
|
|
38
|
+
let out = Command::new(crate::common::root().join("compiler/scripts/run-test-exes.sh"))
|
|
39
|
+
.arg(&work)
|
|
40
|
+
.args([&ok, &bad, &flaky, &hang])
|
|
41
|
+
.env("TEST_ALL_DEADLINE", "2")
|
|
42
|
+
.output()
|
|
43
|
+
.expect("run run-test-exes.sh");
|
|
44
|
+
assert!(started.elapsed().as_secs() < 25, "the hung stub was not stopped: {:?}", started.elapsed());
|
|
45
|
+
let text = String::from_utf8_lossy(&out.stdout).to_string();
|
|
46
|
+
let lines: Vec<&str> = text.lines().filter(|l| l.starts_with("ok ") || l.starts_with("FAIL ")).collect();
|
|
47
|
+
assert_eq!(
|
|
48
|
+
lines,
|
|
49
|
+
[
|
|
50
|
+
format!("ok {ok}"),
|
|
51
|
+
format!("FAIL {bad}"),
|
|
52
|
+
format!("ok {flaky} (failed beside the others, passed alone: a::broken)"),
|
|
53
|
+
format!("FAIL {hang} (timeout)"),
|
|
54
|
+
],
|
|
55
|
+
"{text}"
|
|
56
|
+
);
|
|
57
|
+
// The flaky one's message is printed under it.
|
|
58
|
+
assert!(text.contains(" assertion failed: the replay ends somewhere else"), "{text}");
|
|
59
|
+
assert_eq!(std::fs::read_to_string(work.join("exes.failed")).unwrap().trim(), "2");
|
|
60
|
+
let names = std::fs::read_to_string(work.join("exes.names")).unwrap();
|
|
61
|
+
assert!(names.contains("test a::broken ... FAILED") && names.contains("the replay ends somewhere else"), "{names}");
|
|
62
|
+
assert!(names.contains(&format!("{hang}: still running after 2s")), "{names}");
|
|
63
|
+
}
|
compiler/scripts/run-test-exes.sh
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Runs the Rust test executables for test-all.sh: run-test-exes.sh <dir> <exe>...
|
|
3
|
+
# Prints `ok <exe>` or `FAIL <exe>` for each, in the order given, and leaves in <dir> the
|
|
4
|
+
# number that failed (`exes.failed`) and their failing tests and messages (`exes.names`).
|
|
5
|
+
#
|
|
6
|
+
# They run side by side (TEST_ALL_JOBS at a time, default 4: each one also runs its own tests
|
|
7
|
+
# on several threads). Each has TEST_ALL_DEADLINE seconds (default 900): one still running
|
|
8
|
+
# then is stopped and reported as `FAIL <exe> (timeout)`, so a hang can't stall the gate.
|
|
9
|
+
# A test that times itself (a speed ratio) can fail only because the others share the CPU:
|
|
10
|
+
# a failed executable is run once more, alone, and counts only if it fails again (one that
|
|
11
|
+
# timed out is not rerun). A failure's messages (the harness's `---- <test> stdout ----`
|
|
12
|
+
# sections) are printed under it, also when it passed alone, so a flaky failure is not lost.
|
|
13
|
+
dir=$1
|
|
14
|
+
shift
|
|
15
|
+
deadline=${TEST_ALL_DEADLINE:-900}
|
|
16
|
+
# Exit status of a run stopped by its deadline: SIGALRM's (128 + 14).
|
|
17
|
+
timedOut=142
|
|
18
|
+
|
|
19
|
+
# Runs "$@" with the deadline: perl's alarm survives the exec, and SIGALRM ends the process.
|
|
20
|
+
withDeadline() {
|
|
21
|
+
perl -e 'alarm shift; exec @ARGV or exit 127' "$deadline" "$@"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# The failure sections of a test executable's output (between the harness's two `failures:`
|
|
25
|
+
# lines), at most 60 lines, indented.
|
|
26
|
+
messages() {
|
|
27
|
+
awk '/^failures:$/ { n++; next } n == 1' "$1" | head -60 | sed 's/^/ /'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
i=0
|
|
31
|
+
for exe in "$@"; do
|
|
32
|
+
i=$((i + 1))
|
|
33
|
+
printf '%s\t%s\n' "$i" "$exe"
|
|
34
|
+
done > "$dir/list"
|
|
35
|
+
export deadline
|
|
36
|
+
export -f withDeadline
|
|
37
|
+
cut -f1 "$dir/list" | xargs -P "${TEST_ALL_JOBS:-4}" -I{} bash -c '
|
|
38
|
+
exe=$(awk -F "\t" -v n="$1" "\$1 == n { print \$2 }" "$2/list")
|
|
39
|
+
withDeadline "$exe" > "$2/$1.out" 2>&1
|
|
40
|
+
echo $? > "$2/$1.status"
|
|
41
|
+
' _ {} "$dir"
|
|
42
|
+
|
|
43
|
+
fail=0
|
|
44
|
+
names=""
|
|
45
|
+
while IFS=" " read -r n exe; do
|
|
46
|
+
status=$(cat "$dir/$n.status" 2>/dev/null)
|
|
47
|
+
if [ "$status" = "0" ]; then
|
|
48
|
+
echo "ok $exe"
|
|
49
|
+
elif [ "$status" = "$timedOut" ]; then
|
|
50
|
+
echo "FAIL $exe (timeout)"
|
|
51
|
+
fail=$((fail + 1))
|
|
52
|
+
names="$names
|
|
53
|
+
$exe: still running after ${deadline}s
|
|
54
|
+
$(grep -E '^test .* has been running for over' "$dir/$n.out" | head -20)"
|
|
55
|
+
elif withDeadline "$exe" > "$dir/$n.alone" 2>&1; then
|
|
56
|
+
echo "ok $exe (failed beside the others, passed alone:$(grep -E '^test .* FAILED$' "$dir/$n.out" | sed -E 's/^test (.*) \.\.\. FAILED$/ \1/' | tr -d '\n'))"
|
|
57
|
+
messages "$dir/$n.out"
|
|
58
|
+
else
|
|
59
|
+
alone=$?
|
|
60
|
+
cp "$dir/$n.alone" "$dir/$n.out"
|
|
61
|
+
if [ "$alone" = "$timedOut" ]; then echo "FAIL $exe (timeout, run alone)"; else echo "FAIL $exe"; fi
|
|
62
|
+
fail=$((fail + 1))
|
|
63
|
+
names="$names
|
|
64
|
+
$(grep -E '^test .* FAILED$' "$dir/$n.out")
|
|
65
|
+
$(messages "$dir/$n.out")"
|
|
66
|
+
fi
|
|
67
|
+
done < "$dir/list"
|
|
68
|
+
echo "$fail" > "$dir/exes.failed"
|
|
69
|
+
printf '%s' "$names" > "$dir/exes.names"
|
compiler/scripts/test-all.sh
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
# Runs every test: all Rust test executables, the Plum sweep in three modes, and the
|
|
3
3
|
# tree-sitter corpus when the tree-sitter CLI is installed.
|
|
4
4
|
# The Rust executables run side by side (TEST_ALL_JOBS at a time, default 4: each one also
|
|
5
|
-
# runs its own tests on several threads; one that fails is rerun alone
|
|
5
|
+
# runs its own tests on several threads; one that fails is rerun alone; each has
|
|
6
|
+
# TEST_ALL_DEADLINE seconds, default 900, then fails as `(timeout)`), and `plum test` tests its files in parallel
|
|
6
7
|
# (PLUM_TEST_JOBS, default one per core). Output is printed in a fixed order.
|
|
7
8
|
cd "$(dirname "$0")/../.." || exit 1
|
|
8
9
|
fail=0
|
|
@@ -23,33 +24,11 @@ if [ -z "$exes" ]; then
|
|
|
23
24
|
exit 1
|
|
24
25
|
fi
|
|
25
26
|
|
|
26
|
-
#
|
|
27
|
+
# The executables side by side, each with a deadline (compiler/scripts/run-test-exes.sh).
|
|
27
|
-
i=0
|
|
28
|
-
|
|
28
|
+
# shellcheck disable=SC2086
|
|
29
|
-
i=$((i + 1))
|
|
30
|
-
|
|
29
|
+
compiler/scripts/run-test-exes.sh "$tmp" $exes
|
|
31
|
-
done > "$tmp/list"
|
|
32
|
-
cut -f1 "$tmp/list" | xargs -P "${TEST_ALL_JOBS:-4}" -I{} sh -c '
|
|
33
|
-
exe=$(awk -F "\t" -v n="$1" "\$1 == n { print \$2 }" "$2/list")
|
|
34
|
-
"$exe" > "$2/$1.out" 2>&1
|
|
35
|
-
echo $? > "$2/$1.status"
|
|
36
|
-
' _ {} "$tmp"
|
|
37
|
-
|
|
38
|
-
# A test that times itself (a speed ratio) can fail only because the others share the CPU:
|
|
39
|
-
# a failed executable is run once more, alone, and counts only if it fails again.
|
|
40
|
-
while IFS=" " read -r n exe; do
|
|
41
|
-
|
|
30
|
+
fail=$((fail + $(cat "$tmp/exes.failed" 2>/dev/null || echo 1)))
|
|
42
|
-
echo "ok $exe"
|
|
43
|
-
|
|
31
|
+
failed_names="$failed_names$(cat "$tmp/exes.names" 2>/dev/null)"
|
|
44
|
-
echo "ok $exe (failed beside the others, passed alone:$(grep -E '^test .* FAILED$' "$tmp/$n.out" | sed -E 's/^test (.*) \.\.\. FAILED$/ \1/' | tr -d '\n'))"
|
|
45
|
-
else
|
|
46
|
-
cp "$tmp/$n.alone" "$tmp/$n.out"
|
|
47
|
-
echo "FAIL $exe"
|
|
48
|
-
fail=$((fail + 1))
|
|
49
|
-
failed_names="$failed_names
|
|
50
|
-
$(grep -E '^test .* FAILED$' "$tmp/$n.out")"
|
|
51
|
-
fi
|
|
52
|
-
done < "$tmp/list"
|
|
53
32
|
|
|
54
33
|
# A failed sweep's report: each failed test (`✘`, with the assert report indented under it), each
|
|
55
34
|
# `PANIC` and `error:` line, under the `=== file ===` header it belongs to. Summary lines
|