compiler/
lib/
scripts/
seed/
sublime/
test/
support/
tests/
command
5.2 KiB
driver
3.3 KiB
package-golden
1.6 KiB
reject
1.0 KiB
run
3.5 KiB
runner.rad
10.5 KiB
vim/
.gitignore
336 B
.gitsigners
112 B
CELL_PERMISSIONS
6.8 KiB
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
5.4 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.5 KiB
std.lib.test
808 B
test/driver
raw
| 1 | #!/bin/sh |
| 2 | # Verify test discovery, package selection, and descriptor capacity. |
| 3 | set -eu |
| 4 | ulimit -c 0 |
| 5 | work=$(mktemp -d) |
| 6 | trap 'rm -rf "$work"' EXIT HUP INT TERM |
| 7 | mkdir "$work/selected" |
| 8 | |
| 9 | # The dependency test must not enter the selected package's runner. |
| 10 | printf '%s\n' '/// Test outside the entry package.' '@test fn excluded() { assert false; }' > "$work/dependency.rad" |
| 11 | printf '%s\n' 'use std::testing;' '/// Test in a child module.' \ |
| 12 | '@test fn childTest() throws (testing::TestError) { assert true; }' > "$work/selected/child.rad" |
| 13 | |
| 14 | # Compile through Make so the driver uses the standard memory settings. |
| 15 | compile() { |
| 16 | timeout 300 "${MAKE:-make}" --no-print-directory driver-test-image \ |
| 17 | RAD_BIN="${RAD_BIN:-bin/radiance.rv64.dev}" \ |
| 18 | RAD_EMULATOR="${RAD_EMULATOR:-emulator}" \ |
| 19 | DRIVER_TEST_INPUTS="-pkg dependency -mod $work/dependency.rad -pkg selected -mod $work/selected.rad $1" \ |
| 20 | DRIVER_TEST_FLAGS="${2:-}" \ |
| 21 | DRIVER_TEST_OUTPUT="$work/result.rv64" > "$work/compile.log" 2>&1 |
| 22 | } |
| 23 | |
| 24 | # Check one successful runner and its exact number of executed tests. |
| 25 | run() { |
| 26 | if ! compile "$1"; then |
| 27 | cat "$work/compile.log" |
| 28 | exit 1 |
| 29 | fi |
| 30 | if ! timeout 10 "${RAD_EMULATOR:-emulator}" -run "$work/result.rv64" > "$work/run.log" 2>&1; then |
| 31 | cat "$work/run.log" |
| 32 | exit 1 |
| 33 | fi |
| 34 | grep -Fq "test result: ok. $2 passed; 0 failed" "$work/run.log" |
| 35 | test "$(grep -c '^test selected::' "$work/run.log")" -eq "$2" |
| 36 | } |
| 37 | |
| 38 | printf '%s\n' 'use std::testing;' 'mod child;' \ |
| 39 | '/// Test in the package root.' '@test fn rootTest() throws (testing::TestError) { assert true; }' > "$work/selected.rad" |
| 40 | run "-mod $work/selected/child.rad" 2 |
| 41 | grep -Fq 'test selected::rootTest ... ok' "$work/run.log" |
| 42 | grep -Fq 'test selected::child::childTest ... ok' "$work/run.log" |
| 43 | |
| 44 | printf '%s\n' 'use std::testing;' > "$work/selected.rad" |
| 45 | if compile ''; then |
| 46 | echo 'driver: empty test discovery unexpectedly succeeded' |
| 47 | exit 1 |
| 48 | fi |
| 49 | grep -Fq 'no test functions found' "$work/compile.log" |
| 50 | |
| 51 | # MAX_TESTS is the compiler's supported discovery capacity. |
| 52 | for count in 1024 1025; do |
| 53 | awk -v count="$count" -v directory="$work/selected" 'BEGIN { |
| 54 | print "use std::testing;" |
| 55 | for (i = 0; i < count; i++) { |
| 56 | part = int(i / 256) |
| 57 | path = directory "/part" part ".rad" |
| 58 | if (i % 256 == 0) { |
| 59 | printf "/// Capacity test group.\nmod part%d;\n", part |
| 60 | print "use std::testing;" > path |
| 61 | } |
| 62 | print "/// Generated capacity test." > path |
| 63 | printf "@test fn test%d() throws (testing::TestError) { assert true; }\n", i > path |
| 64 | } |
| 65 | }' > "$work/selected.rad" |
| 66 | inputs='' |
| 67 | for path in "$work/selected"/part*.rad; do |
| 68 | inputs="$inputs -mod $path" |
| 69 | done |
| 70 | if [ "$count" -eq 1024 ]; then |
| 71 | if ! compile "$inputs" '-dump il'; then |
| 72 | cat "$work/compile.log" |
| 73 | exit 1 |
| 74 | fi |
| 75 | grep -Fq 'selected: found 1024 test(s)' "$work/compile.log" |
| 76 | test "$(grep -c 'call.*std::testing::test' "$work/compile.log")" -eq "$count" |
| 77 | run "$inputs" "$count" |
| 78 | else |
| 79 | if compile "$inputs"; then |
| 80 | echo 'driver: test discovery overflow unexpectedly succeeded' |
| 81 | exit 1 |
| 82 | fi |
| 83 | grep -Fq 'Runtime error (EBREAK)' "$work/compile.log" |
| 84 | fi |
| 85 | done |
| 86 | echo 'driver tests: 4 passed' |