1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Run test executables that obey the BYO protocol.
|
4 | #
|
5 | # TODO: doc/byo.md
|
6 | #
|
7 | # Usage:
|
8 | # test/byo-client.sh run-tests ARGS...
|
9 | #
|
10 | # The ARGS... are run with an environment variable, e.g.
|
11 | #
|
12 | # ./myscript.py
|
13 | # python3 ./myscript.py
|
14 | # ./myscript.sh
|
15 | # dash ./myscript.sh
|
16 | # osh ./myscript.sh
|
17 | #
|
18 | # The client creates a clean process state and directory state for each tests.
|
19 |
|
20 | set -o nounset
|
21 | set -o pipefail
|
22 | set -o errexit
|
23 | shopt -s strict:all 2>/dev/null || true # dogfood for OSH
|
24 |
|
25 | readonly TAB=$'\t'
|
26 |
|
27 | source stdlib/two.sh
|
28 |
|
29 | run-tests() {
|
30 | # argv is the command to run, like bash foo.sh
|
31 | #
|
32 | # It's an array rather than a single command, so you can run the same scripts
|
33 | # under multiple shells:
|
34 | #
|
35 | # bash myscript.sh
|
36 | # osh myscript.sh
|
37 |
|
38 | if test $# -eq 0; then
|
39 | die "Expected argv to run"
|
40 | fi
|
41 |
|
42 | # TODO:
|
43 | # --no-chdir Change directory by default, but this option disables it
|
44 | # --no-stdout-log stdout is not redirected to its own, named file
|
45 | # --max-jobs Parallelism
|
46 | #
|
47 | # And how do we run test binaries that are just one big process?
|
48 | # - Python - inside a file, we probably don't have any tests to run in parallel
|
49 | # - C++ - ditto
|
50 | # - R - we have a few unit tests
|
51 | #
|
52 | # So maybe we need BYO_LIST_TEST_BIN - list the test binaries?
|
53 | # Or mycpp/TEST.sh etc. should list them. Yes that is true!
|
54 | # We can also list things to build.
|
55 | #
|
56 | # BYO_LIST_NINJA=1
|
57 |
|
58 | mkdir -p _tmp
|
59 | local tmp=_tmp/byo-list.txt
|
60 |
|
61 | # First list the tests
|
62 | BYO_COMMAND=list-tests "$@" > $tmp
|
63 |
|
64 | local i=0
|
65 | local status
|
66 |
|
67 | while read -r test_name; do
|
68 |
|
69 | echo "${TAB}${test_name}"
|
70 |
|
71 | set +o errexit
|
72 | BYO_COMMAND=run-test BYO_ARG="$test_name" "$@"
|
73 | status=$?
|
74 | set -o errexit
|
75 |
|
76 | if test $status -eq 0; then
|
77 | echo "${TAB}OK"
|
78 | else
|
79 | echo "${TAB}FAIL with status $status"
|
80 | exit 1
|
81 | fi
|
82 |
|
83 | i=$(( i + 1 ))
|
84 | done < $tmp
|
85 |
|
86 | echo
|
87 | echo "$0: $i tests passed."
|
88 | }
|
89 |
|
90 | # TODO:
|
91 | # BYO_PROBE=1
|
92 | #
|
93 | # must print capabilities
|
94 | #
|
95 | # - testing - success/fail
|
96 | # - benchmarks - output TSV file I think? Or a directory of TSV files?
|
97 | # - BYO_RESULTS
|
98 | # - shell auto-completion
|
99 |
|
100 | "$@"
|