1 #!/bin/bash
2 # Run stdlib tests with the tree compiler.
3 set -euo pipefail
4 5 # Pin MOXIEROOT to this checkout. The compiler reads the stdlib from
6 # $MOXIEROOT/src, and an inherited MOXIEROOT (a stale installed tree, e.g.
7 # ~/.local/share/moxie) silently compiles THAT source instead - which showed up
8 # as seven bogus "stdlib test failures" reporting a shadowing violation that
9 # the current tree had already fixed. tests/run.sh pins it the same way.
10 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11 MOXIEROOT="$SCRIPT_DIR"
12 export MOXIEROOT
13 14 MOXIE="${MOXIE:-./moxie}"
15 PASSED=0
16 FAILED=0
17 ERRORS=""
18 19 if [ ! -x "$MOXIE" ]; then
20 echo "FATAL: $MOXIE not found or not executable"
21 exit 1
22 fi
23 24 echo "=== Running stdlib tests with: $MOXIE ==="
25 echo " $($MOXIE version 2>&1)"
26 echo
27 28 # Find all test packages
29 TEST_FILES=$(find ./src -name "*_test.mx" -not -path "./legacy/*")
30 31 # Group by directory
32 DIRS=$(echo "$TEST_FILES" | xargs -n1 dirname | sort -u)
33 34 # Each package is compiled by `moxie test`, the compiler's own harness. It
35 # builds the test main itself, which is what keeps a package's init() legal:
36 # this script used to copy each package into a scratch directory, rename it to
37 # `package main` and generate a main of its own, and that copy cost the package
38 # its init() ("init() is not allowed in main package") and its global stores
39 # ("package globals are immutable outside init") - nine packages failed to build
40 # for that reason and two more for a missing shutdown arm in the generated main.
41 # The harness compiles the package in place, so neither rewrite happens.
42 for dir in $DIRS; do
43 # Skip a directory whose test files declare no test function: the harness
44 # would build it and run nothing.
45 testfuncs=$(grep -h "^func Test" "$dir"/*_test.mx 2>/dev/null | sed 's/func \(Test[^ (]*\).*/\1/')
46 if [ -z "$testfuncs" ]; then
47 continue
48 fi
49 50 shortname=$(echo "$dir" | sed 's|^\./src/||')
51 printf "%-50s" "TEST $shortname"
52 53 if output=$(MOXIEROOT="$MOXIEROOT" "$MOXIE" test "$dir" 2>&1); then
54 echo "PASS"
55 PASSED=$((PASSED + 1))
56 else
57 if echo "$output" | grep -q "compile error\|clang failed\|linker failed"; then
58 echo "FAIL (build)"
59 else
60 echo "FAIL (run)"
61 fi
62 echo "$output" | tail -10
63 ERRORS="$ERRORS FAIL: $shortname\n"
64 FAILED=$((FAILED + 1))
65 fi
66 done
67 68 echo
69 echo "=== Results ==="
70 echo "PASSED: $PASSED"
71 echo "FAILED: $FAILED"
72 if [ -n "$ERRORS" ]; then
73 echo
74 echo "Failures:"
75 printf "$ERRORS"
76 fi
77 78 if [ "$FAILED" -gt 0 ]; then
79 exit 1
80 fi
81