]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: add buildtag parsing test
authorRuss Cox <rsc@golang.org>
Wed, 24 Nov 2021 15:35:21 +0000 (10:35 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 25 Nov 2021 00:02:52 +0000 (00:02 +0000)
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 <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/dist/buildtag_test.go [new file with mode: 0644]
src/cmd/go/go_test.go

diff --git a/src/cmd/dist/buildtag_test.go b/src/cmd/dist/buildtag_test.go
new file mode 100644 (file)
index 0000000..f64abfd
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright 2021 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.
+
+package main
+
+import (
+       "fmt"
+       "reflect"
+       "testing"
+)
+
+var buildParserTests = []struct {
+       x       string
+       matched bool
+       err     error
+}{
+       {"gc", true, nil},
+       {"gccgo", false, nil},
+       {"!gc", false, nil},
+       {"gc && gccgo", false, nil},
+       {"gc || gccgo", true, nil},
+       {"gc || (gccgo && !gccgo)", true, nil},
+       {"gc && (gccgo || !gccgo)", true, nil},
+       {"!(gc && (gccgo || !gccgo))", false, nil},
+       {"gccgo || gc", true, nil},
+       {"!(!(!(gccgo || gc)))", false, nil},
+       {"compiler_bootstrap", false, nil},
+       {"cmd_go_bootstrap", true, nil},
+       {"syntax(error", false, fmt.Errorf("parsing //go:build line: unexpected (")},
+       {"(gc", false, fmt.Errorf("parsing //go:build line: missing )")},
+       {"gc gc", false, fmt.Errorf("parsing //go:build line: unexpected tag")},
+       {"(gc))", false, fmt.Errorf("parsing //go:build line: unexpected )")},
+}
+
+func TestBuildParser(t *testing.T) {
+       for _, tt := range buildParserTests {
+               matched, err := matchexpr(tt.x)
+               if matched != tt.matched || !reflect.DeepEqual(err, tt.err) {
+                       t.Errorf("matchexpr(%q) = %v, %v; want %v, %v", tt.x, matched, err, tt.matched, tt.err)
+               }
+       }
+}
index d8bed1dac03c3924cbc7f1cd11ef89e663f5bcca..170c882df9e77158b9591370411bc6f728018825 100644 (file)
@@ -1128,11 +1128,11 @@ func TestGoListTest(t *testing.T) {
        tg.grepStdoutNot(`^testing \[sort.test\]$`, "unexpected test copy of testing")
        tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
 
-       tg.run("list", "-test", "cmd/dist", "cmd/doc")
-       tg.grepStdout(`^cmd/dist$`, "missing cmd/dist")
+       tg.run("list", "-test", "cmd/buildid", "cmd/doc")
+       tg.grepStdout(`^cmd/buildid$`, "missing cmd/buildid")
        tg.grepStdout(`^cmd/doc$`, "missing cmd/doc")
        tg.grepStdout(`^cmd/doc\.test$`, "missing cmd/doc test")
-       tg.grepStdoutNot(`^cmd/dist\.test$`, "unexpected cmd/dist test")
+       tg.grepStdoutNot(`^cmd/buildid\.test$`, "unexpected cmd/buildid test")
        tg.grepStdoutNot(`^testing`, "unexpected testing")
 
        tg.run("list", "-test", "runtime/cgo")