OILS / stdlib / byo-server-lib.sh View on Github | oilshell.org

29 lines, 11 significant
1# Library to turn a file into a "BYO test server"
2#
3# Usage:
4# source --builtin test/byo-server-lib.sh # from Oils
5# source test/byo-server-lib.sh # can be used with bash
6#
7# The client creates a clean process state and directory state for each tests.
8#
9# (It relies on compgen -A, and maybe declare -f, so it's not POSIX shell.)
10
11byo-maybe-main() {
12 if test -n "${BYO_LIST_TESTS:-}"; then
13 # bash extension that OSH also implements
14 compgen -A function | grep '^test-'
15 exit 0
16 fi
17
18 local test_name=${BYO_TEST_NAME:-}
19 if test -n "$test_name"; then
20 # Shell convention: we name functions test-*
21 $test_name
22
23 # Only run if not set -e. Either way it's equivalent
24 exit $?
25 fi
26
27 # Do nothing if none of those variables is set.
28 # The program continues to its "main".
29}