summaryrefslogtreecommitdiff
path: root/src/cmd/gofmt/testdata/test.sh
blob: a1d5d823eb3aa89db6b8a1855d8000d7e735ea25 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# Copyright 2010 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

CMD="../gofmt"
TMP=test_tmp.go
COUNT=0


cleanup() {
	rm -f $TMP
}


error() {
	echo $1
	exit 1
}


count() {
	#echo $1
	let COUNT=$COUNT+1
	let M=$COUNT%10
	if [ $M == 0 ]; then
		echo -n "."
	fi
}


test() {
	count $1

	# compare against .golden file
	cleanup
	$CMD -s $1 > $TMP
	cmp -s $TMP $2
	if [ $? != 0 ]; then
		diff $TMP $2
		error "Error: simplified $1 does not match $2"
	fi

	# make sure .golden is idempotent
	cleanup
	$CMD -s $2 > $TMP
	cmp -s $TMP $2
	if [ $? != 0 ]; then
		diff $TMP $2
		error "Error: $2 is not idempotent"
	fi
}


runtests() {
	smoketest=../../../pkg/go/parser/parser.go
	test $smoketest $smoketest
	test composites.input composites.golden
	# add more test cases here
}


runtests
cleanup
echo "PASSED ($COUNT tests)"