forked from miekg/yamlfmt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
yamlfmt_test.bash
executable file
·49 lines (41 loc) · 1.22 KB
/
yamlfmt_test.bash
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
file=$(mktemp)
cat <<EOF > $file
repos:
- repo: local
hooks:
- id: documentation_checker
name: documentation_checker
entry: bash ./scripts/pre-commit/docgen.sh
language: system
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.29.0
hooks:
- id: yapf
EOF
gold=$(mktemp)
cat <<EOF > $gold
repos:
- repo: local
hooks:
- id: documentation_checker
name: documentation_checker
entry: bash ./scripts/pre-commit/docgen.sh
language: system
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.29.0
hooks:
- id: yapf
EOF
go install
test $? -eq 0 || { echo "Failed to compile"; exit 1; }
go run yamlfmt.go -w $file
test $? -eq 0 || { echo "Failed to run with replace mode"; exit 1; }
cmp $file $gold || { echo "Unexpected output"; diff $file $gold; exit 1; }
out=$(mktemp)
cat $file | go run yamlfmt.go > $out
test $? -eq 0 || { echo "Failed to run reading stdin"; exit 1; }
cmp $out $gold || { echo "Unexpected output"; diff $out $gold; exit 1; }
file1=$(mktemp)
cp $file $file1
go run yamlfmt.go -w $file $file1 || { echo "Failed to replace multiple files"; exit 1; }
cmp $file1 $gold || { echo "Unexpected output from replacing multiple files"; diff $file1 $gold; exit 1; }