Skip to content

Commit b2a5a37

Browse files
committed
cmd/dist: add buildtag parsing test
Forgot to 'git add' this test written as part of CL 359314. For #41184. Change-Id: I2ebd48fd62a2053c8b16e5a8c48c1e11d1b86d5b Reviewed-on: https://go-review.googlesource.com/c/go/+/366894 Trust: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b77f5f9 commit b2a5a37

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/cmd/dist/buildtag_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"fmt"
9+
"reflect"
10+
"testing"
11+
)
12+
13+
var buildParserTests = []struct {
14+
x string
15+
matched bool
16+
err error
17+
}{
18+
{"gc", true, nil},
19+
{"gccgo", false, nil},
20+
{"!gc", false, nil},
21+
{"gc && gccgo", false, nil},
22+
{"gc || gccgo", true, nil},
23+
{"gc || (gccgo && !gccgo)", true, nil},
24+
{"gc && (gccgo || !gccgo)", true, nil},
25+
{"!(gc && (gccgo || !gccgo))", false, nil},
26+
{"gccgo || gc", true, nil},
27+
{"!(!(!(gccgo || gc)))", false, nil},
28+
{"compiler_bootstrap", false, nil},
29+
{"cmd_go_bootstrap", true, nil},
30+
{"syntax(error", false, fmt.Errorf("parsing //go:build line: unexpected (")},
31+
{"(gc", false, fmt.Errorf("parsing //go:build line: missing )")},
32+
{"gc gc", false, fmt.Errorf("parsing //go:build line: unexpected tag")},
33+
{"(gc))", false, fmt.Errorf("parsing //go:build line: unexpected )")},
34+
}
35+
36+
func TestBuildParser(t *testing.T) {
37+
for _, tt := range buildParserTests {
38+
matched, err := matchexpr(tt.x)
39+
if matched != tt.matched || !reflect.DeepEqual(err, tt.err) {
40+
t.Errorf("matchexpr(%q) = %v, %v; want %v, %v", tt.x, matched, err, tt.matched, tt.err)
41+
}
42+
}
43+
}

src/cmd/go/go_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,11 @@ func TestGoListTest(t *testing.T) {
11281128
tg.grepStdoutNot(`^testing \[sort.test\]$`, "unexpected test copy of testing")
11291129
tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
11301130

1131-
tg.run("list", "-test", "cmd/dist", "cmd/doc")
1132-
tg.grepStdout(`^cmd/dist$`, "missing cmd/dist")
1131+
tg.run("list", "-test", "cmd/buildid", "cmd/doc")
1132+
tg.grepStdout(`^cmd/buildid$`, "missing cmd/buildid")
11331133
tg.grepStdout(`^cmd/doc$`, "missing cmd/doc")
11341134
tg.grepStdout(`^cmd/doc\.test$`, "missing cmd/doc test")
1135-
tg.grepStdoutNot(`^cmd/dist\.test$`, "unexpected cmd/dist test")
1135+
tg.grepStdoutNot(`^cmd/buildid\.test$`, "unexpected cmd/buildid test")
11361136
tg.grepStdoutNot(`^testing`, "unexpected testing")
11371137

11381138
tg.run("list", "-test", "runtime/cgo")

0 commit comments

Comments
 (0)