-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unit
More file actions
executable file
·37 lines (34 loc) · 2.05 KB
/
Copy pathtest_unit
File metadata and controls
executable file
·37 lines (34 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
#
# Run Bats unit tests.
# Unit tests are enforced offline: HTTP(S) is routed through a dead local proxy, so an
# accidental network call fails in under a second instead of hanging the run (a test
# that genuinely needs the network belongs in an integration suite instead).
# Requires Bats (https://github.com/bats-core/bats-core) in addition to the base prerequisites.
#
# Usage: ./test_unit
# ./test_unit test/lib_awk.bats
#
set -euo pipefail # exit on error, undefined vars, or pipe failures
. "$(dirname "$0")"/lib/capture # captured command: per-run log dir, banner + "logs:" pointer, dots, trace (see lib/capture)
# Check that bats is installed
if ! command -v bats >/dev/null; then # command -v returns 0 if the command is found
echo "Error: bats is not installed. See https://github.com/bats-core/bats-core" >&2 # >&2 prints to stderr
exit 1
fi
# --- Offline enforcement ---
# Route HTTP(S) through a dead local proxy: nothing listens on 127.0.0.1:9 (the
# "discard" port), so any accidental network call (e.g. a fixture regression that makes
# a script really clone from Gerrit) fails immediately with a connection error instead
# of hanging the run for minutes or passing only on machines with connectivity.
# git and curl honor these variables; file:// git fixtures are unaffected.
# ./ci and .gitlab-ci.yml set the same variables around their `bats test/` runs.
export http_proxy=http://127.0.0.1:9 # dead proxy for plain HTTP
export https_proxy=http://127.0.0.1:9 # dead proxy for HTTPS (Gerrit URLs)
# Run all tests or a specific test file if provided.
# env -u: scrub this script's own capture exports before running the tests. lib/capture
# (sourced above) exports QUIBBLE_LOG_DIR and _QUIBBLE_LOG_ROOT so child processes share
# the run directory — but the tests must run hermetically: several assert lib/log_dir's
# stamping behavior, which an inherited run dir would short-circuit.
# ${@:-...} uses default value when no arguments given; "$@" passes arguments as-is
env -u QUIBBLE_LOG_DIR -u _QUIBBLE_LOG_ROOT bats "${@:-$(dirname "$0")/test/}"