forked from grafana/grafonnet-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.sh
executable file
·49 lines (43 loc) · 1.04 KB
/
tests.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -eu
jsonnet_fmt_args=(-n 2 --max-blank-lines 2 --sort-imports --string-style s --comment-style s)
x=0
action=${1:-test}
while IFS= read -r -d '' i
do
t="Formatting $i..."
if [[ "$action" == "update" ]]; then
jsonnetfmt -i "${jsonnet_fmt_args[@]}" "$i"
fi
if jsonnetfmt --test "${jsonnet_fmt_args[@]}" "$i";
then
echo "$t OK"
else
echo "$t NOK"
x=1
fi
done < <(find . \( -name '*.jsonnet' -or -name '*.libsonnet' \) -print0)
for i in tests/*/*.jsonnet examples/*.jsonnet
do
json=$(dirname "$i")/$( basename "$i" .jsonnet )_test_output.json
json_e=$(dirname "$i")/$( basename "$i" .jsonnet )_compiled.json
t="Compiling $i..."
if jsonnet -J . "$i" > "$json"
then
echo "$t OK"
else
echo "$t NOK"
x=1
continue
fi
if [[ "$action" == "update" ]]; then cp "$json" "$json_e"; fi
t="Checking $i..."
if diff -urt "$json" "$json_e"
then
echo "$t OK"
else
echo "$t NOK"
x=1
fi
done
exit $x