1#!/bin/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
17cd "$(dirname $0)"
18
19source "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
29init
30
31for TEST in *.jsonnet ../examples/*.jsonnet ../examples/terraform/*.jsonnet ../benchmarks/*.jsonnet ../gc_stress/*.jsonnet ; do
32
33    FMT_FILE="$TEST"
34    ORIG_OUTPUT="$(cat $TEST)"
35    GOLDEN_OUTPUT="${ORIG_OUTPUT}"
36    GOLDEN_KIND="PLAIN"
37
38    if [ -r "$TEST.fmt.golden" ] ; then
39        GOLDEN_OUTPUT=$(cat "$TEST.fmt.golden")
40        FMT_FILE="$TEST.fmt.golden"
41    fi
42
43    if [ $(echo "$TEST" | cut -b 1-12) == "error.parse." ] ; then
44        continue  # No point testing these
45    fi
46
47    EXPECTED_EXIT_CODE=0
48    JSONNETFMT_CMD="$VALGRIND "$JSONNETFMT_BIN""
49    test_eval "$JSONNETFMT_CMD" "$FMT_FILE" "$EXPECTED_EXIT_CODE" "$GOLDEN_OUTPUT" "$GOLDEN_KIND"
50
51    # when we're at it, let's test --test (on the same file)
52    test_eval "$JSONNETFMT_CMD --test" "$FMT_FILE" "$EXPECTED_EXIT_CODE" "" "$GOLDEN_KIND"
53done
54
55if [ $FAILED -eq 0 ] ; then
56    echo "$0: All $EXECUTED test scripts pass."
57else
58    echo "$0: FAILED: $FAILED / $EXECUTED"
59    exit 1
60fi
61
62deinit
63