Debian Codegraph @

examples/check.sh

raw
1 #!/usr/bin/env bash
2
3 # Copyright 2015 Google Inc. All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 TEST_SUITE_NAME="${TEST_SUITE_NAME:-$0}"
18
19 cd $(dirname $0)
20
21 JSONNET_BIN="${JSONNET_BIN:-../jsonnet}"
22
23 source ../test_suite/tests.source
24
25 init
26
27 shopt -s nullglob
28
29 FAILED=0
30 SUCCESS=0
31
32 EXAMPLES_DIR="${EXAMPLES_DIR:-./}"
33
34 for I in "$EXAMPLES_DIR"/*.jsonnet.golden ; do
35 TEST=$(basename "$I" .golden)
36 JSONNET_CMD="$JSONNET_BIN --ext-str prefix='Happy Hour ' --ext-code brunch=true --tla-str prefix='Happy Hour ' --tla-code brunch=true"
37 JSONNET_FILE="$EXAMPLES_DIR/$TEST"
38 EXPECTED_EXIT_CODE=0
39 # We run jsonnet again on the output to disregard formatting
40 GOLDEN_OUTPUT="$("$JSONNET_BIN" "$I" 2> /dev/null)"
41 GOLDEN_KIND=PLAIN
42 test_eval "$JSONNET_CMD" "$JSONNET_FILE" "$EXPECTED_EXIT_CODE" "$GOLDEN_OUTPUT" "$GOLDEN_KIND"
43 done
44
45 for I in "$EXAMPLES_DIR"/*.error ; do
46 TEST=$(basename "$I" .error)
47 JSONNET_CMD="$JSONNET_BIN"
48 JSONNET_FILE="$TEST"
49 EXPECTED_EXIT_CODE=1
50 GOLDEN_OUTPUT="$(cat "$I")"
51 GOLDEN_KIND=PLAIN
52 test_eval "$JSONNET_CMD" "$JSONNET_FILE" "$EXPECTED_EXIT_CODE" "$GOLDEN_OUTPUT" "$GOLDEN_KIND"
53 done
54
55 deinit
56
57 if [ "$FAILED" -eq 0 ] ; then
58 echo "$TEST_SUITE_NAME: All $EXECUTED tests executed correctly."
59 else
60 echo "$TEST_SUITE_NAME: $FAILED / $EXECUTED tests failed."
61 exit 1
62 fi