Source file
test/fixedbugs/issue14636.go
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "bytes"
13 "log"
14 "os/exec"
15 "strings"
16 )
17
18 func main() {
19 checkLinkOutput("", "-B argument must start with 0x")
20 checkLinkOutput("0", "-B argument must start with 0x")
21 checkLinkOutput("0x", "usage")
22 checkLinkOutput("0x0", "-B argument must have even number of digits")
23 checkLinkOutput("0x00", "usage")
24 checkLinkOutput("0xYZ", "-B argument contains invalid hex digit")
25 checkLinkOutput("0x"+strings.Repeat("00", 32), "usage")
26 checkLinkOutput("0x"+strings.Repeat("00", 33), "-B option too long (max 32 digits)")
27 }
28
29 func checkLinkOutput(buildid string, message string) {
30 cmd := exec.Command("go", "tool", "link", "-B", buildid)
31 out, err := cmd.CombinedOutput()
32 if err == nil {
33 log.Fatalf("expected cmd/link to fail")
34 }
35
36 firstLine := string(bytes.SplitN(out, []byte("\n"), 2)[0])
37 if strings.HasPrefix(firstLine, "panic") {
38 log.Fatalf("cmd/link panicked:\n%s", out)
39 }
40
41 if !strings.Contains(firstLine, message) {
42 log.Fatalf("cmd/link output did not include expected message %q: %s", message, firstLine)
43 }
44 }
45
View as plain text