...
1#!/hint/bash
2
3common_setup() {
4 test_tmpdir="$(mktemp -d)"
5 cp -a "$BATS_TEST_DIRNAME/.." "$test_tmpdir/build-aux"
6 mkdir "$test_tmpdir/tools"
7 cp -a "$BATS_TEST_DIRNAME/../../tools/src" "$test_tmpdir/tools/src"
8 cd "$test_tmpdir"
9 cat >Makefile <<-'__EOT__'
10 .DEFAULT_GOAL = tst
11 tst:
12 .PHONY: tst
13 include build-aux/prelude.mk
14 expr-eq-strict-actual: FORCE; printf '%s' $(call quote.shell,$(EXPR)) > $@
15 expr-eq-echo-actual: FORCE; echo $(EXPR) > $@
16 expr-eq-sloppy-actual: FORCE; echo $(foreach w,$(EXPR),$w) > $@
17 __EOT__
18}
19setup() { common_setup; }
20
21common_teardown() {
22 cd /
23 rm -rf -- "$test_tmpdir"
24}
25teardown() { common_teardown; }
26
27# Usage: make_expecting_go_error
28#
29# Run 'make', and expect an error message like:
30#
31# build-aux/kubeapply.mk:16: *** This Makefile requires Go '1.11.4' or newer; you have '1.10.3'. Stop.
32make_expecting_go_error() {
33 not make >& output
34 cat output
35 [[ "$(wc -l <output)" -eq 1 ]]
36 [[ "$(cat output)" == *": *** This Makefile requires Go '1.11.4' or newer; you "*". Stop." ]]
37}
38
39check_expr_eq() {
40 [[ $# = 3 ]]
41 local mode=$1
42 local expr=$2
43 local expected=$3
44
45 case "$mode" in
46 strict) printf '%s' "$expected" > expected;;
47 echo) echo $expected > expected;;
48 sloppy) echo $expected > expected;;
49 esac
50
51 make EXPR="$expr" "expr-eq-${mode}-actual"
52
53 diff -u expected "expr-eq-${mode}-actual"
54}
55
56not() {
57 # This isn't just "I find 'not' more readable than '!'", it
58 # serves an actual purpose. '!' won't trigger an errexit, so
59 # it's no good for assertions. However, it can affect the
60 # return value of a function, and that function can trigger an
61 # errexit.
62 ! "$@"
63}
View as plain text