| 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 |
cd "$(dirname $0)" |
| 18 |
|
| 19 |
source "tests.source" |
| 20 |
|
| 21 |
# Enable next line to test the garbage collector |
| 22 |
#PARAMS="--gc-min-objects 1 --gc-growth-trigger 1" |
| 23 |
|
| 24 |
# Enable next line for a slow and thorough test |
| 25 |
#VALGRIND="valgrind -q" |
| 26 |
|
| 27 |
#VERBOSE=true |
| 28 |
|
| 29 |
init |
| 30 |
|
| 31 |
for TEST in *.jsonnet ; do |
| 32 |
|
| 33 |
GOLDEN_OUTPUT="true" |
| 34 |
GOLDEN_KIND="PLAIN" |
| 35 |
|
| 36 |
|
| 37 |
EXPECTED_EXIT_CODE=0 |
| 38 |
if [ $(echo "$TEST" | cut -b 1-6) == "error." ] ; then |
| 39 |
EXPECTED_EXIT_CODE=1 |
| 40 |
fi |
| 41 |
if [ -r "$TEST.golden" ] ; then |
| 42 |
GOLDEN_OUTPUT=$(cat "$TEST.golden") |
| 43 |
fi |
| 44 |
if [ -r "$TEST.golden_regex" ] ; then |
| 45 |
GOLDEN_KIND="REGEX" |
| 46 |
GOLDEN_OUTPUT=$(cat "$TEST.golden_regex") |
| 47 |
fi |
| 48 |
|
| 49 |
EXT_PARAMS="" |
| 50 |
TLA_PARAMS="" |
| 51 |
if [[ "$TEST" =~ ^tla[.] ]] ; then |
| 52 |
TLA_PARAMS="--tla-str var1=test --tla-code var2='{x:1,y:2}'" |
| 53 |
else |
| 54 |
EXT_PARAMS="--ext-str var1=test --ext-code var2='{x:1,y:2}'" |
| 55 |
fi |
| 56 |
|
| 57 |
if [ -n "$DISABLE_EXT_PARAMS" ]; then |
| 58 |
EXT_PARAMS="" |
| 59 |
fi |
| 60 |
JSONNET_CMD="$VALGRIND $JSONNET_BIN $PARAMS $EXT_PARAMS $TLA_PARAMS" |
| 61 |
test_eval "$JSONNET_CMD" "$TEST" "$EXPECTED_EXIT_CODE" "$GOLDEN_OUTPUT" "$GOLDEN_KIND" |
| 62 |
done |
| 63 |
|
| 64 |
deinit |
| 65 |
|
| 66 |
if [ $FAILED -eq 0 ] ; then |
| 67 |
echo "$0: All $EXECUTED test scripts pass." |
| 68 |
else |
| 69 |
echo "$0: FAILED: $FAILED / $EXECUTED" |
| 70 |
exit 1 |
| 71 |
fi |