OILS / test / byo-client.sh View on Github | oilshell.org

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