summaryrefslogtreecommitdiff
path: root/test/testlib
blob: de138b1d19d2d60fadf1c00a2d5841716b079f2e (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Copyright 2012 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.

# These function names are also known to
# (and are the plan for transitioning to) run.go.

# helper (not known to run.go)
# group file list by packages and return list of packages
# each package is a comma-separated list of go files.
pkgs() {
	pkglist=$(grep -h '^package ' $* | awk '{print $2}' | sort -u)
	for p in $pkglist
	do
		echo $(grep -l "^package $p\$" $*) | tr ' ' ,
	done | sort
}

# +build aborts execution if the supplied tags don't match,
# i.e. none of the tags (x or !x) matches GOARCH or GOOS.
+build() {
	if (( $# == 0 )); then
		return
	fi
	for tag; do
		case $tag in
		$GOARCH|$GOOS)
			#echo >&2 "match $tag in $1"
			return # don't exclude.
			;;
		'!'$GOARCH|'!'$GOOS)
			;;
		'!'*)
			# not x where x is neither GOOS nor GOARCH.
			#echo >&2 "match $tag in $1"
			return # don't exclude
			;;
		esac
	done
	# no match.
	exit 0
}

compile() {
	$G $D/$F.go
}

compiledir() {
	for pkg in $(pkgs $D/$F.dir/*.go)
	do
		$G -I . $(echo $pkg | tr , ' ') || return 1
	done
}

errorcheckdir() {
	lastzero=""
	if [ "$1" = "-0" ]; then
		lastzero="-0"
	fi
	pkgs=$(pkgs $D/$F.dir/*.go)
	for pkg in $pkgs.last
	do
		zero="-0"
		case $pkg in
		*.last)
			pkg=$(echo $pkg |sed 's/\.last$//')
			zero=$lastzero
		esac
		errchk $zero $G -D . -I . -e $(echo $pkg | tr , ' ')
	done
}

rundir() {
	lastfile=""
	for pkg in $(pkgs $D/$F.dir/*.go)
	do
		name=$(echo $pkg | sed 's/\.go.*//; s/.*\///')
		$G -D . -I . -e $(echo $pkg | tr , ' ') || return 1
		lastfile=$name
	done
	$L -o $A.out -L . $lastfile.$A
	./$A.out
}

rundircmpout() {
	lastfile=""
	for pkg in $(pkgs $D/$F.dir/*.go)
	do
		name=$(echo $pkg | sed 's/\.go.*//; s/.*\///')
		$G -D . -I . -e $(echo $pkg | tr , ' ') || return 1
		lastfile=$name
	done
	$L -o $A.out -L . $lastfile.$A
	./$A.out 2>&1 | cmp - $D/$F.out
}

build() {
	$G $D/$F.go && $L $F.$A
}

runoutput() {
	go run "$D/$F.go" "$@" > tmp.go
	go run tmp.go
}

run() {
	gofiles=""
	ingo=true
	while $ingo; do
		case "$1" in
		*.go)
			gofiles="$gofiles $1"
			shift
			;;
		*)
			ingo=false
			;;
		esac
	done

	$G $D/$F.go $gofiles && $L $F.$A && ./$A.out "$@"
}

cmpout() {
	$G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
}

errorcheck() {
	zero=""
	if [ "$1" = "-0" ]; then
		zero="-0"
		shift
	fi
	errchk $zero $G -e $* $D/$F.go
}

errorcheckoutput() {
	zero=""
	if [ "$1" = "-0" ]; then
		zero="-0"
		shift
	fi
	go run "$D/$F.go" "$@" > tmp.go
	errchk $zero $G -e tmp.go
}

skip() {
	true
}