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 "runtime"
16 "strings"
17 )
18
19 func main() {
20
21
22 checkLinkOutput("0", "-B argument must start with 0x")
23 checkLinkOutput("0x", "cannot open file nonexistent.o")
24 checkLinkOutput("0x0", "-B argument must have even number of digits")
25 checkLinkOutput("0x00", "cannot open file nonexistent.o")
26 checkLinkOutput("0xYZ", "-B argument contains invalid hex digit")
27
28 maxLen := 32
29 if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
30 maxLen = 16
31 }
32 checkLinkOutput("0x"+strings.Repeat("00", maxLen), "cannot open file nonexistent.o")
33 checkLinkOutput("0x"+strings.Repeat("00", maxLen+1), "-B option too long")
34 }
35
36 func checkLinkOutput(buildid string, message string) {
37 cmd := exec.Command("go", "tool", "link", "-B", buildid, "nonexistent.o")
38 out, err := cmd.CombinedOutput()
39 if err == nil {
40 log.Fatalf("expected cmd/link to fail")
41 }
42
43 firstLine := string(bytes.SplitN(out, []byte("\n"), 2)[0])
44 if strings.HasPrefix(firstLine, "panic") {
45 log.Fatalf("cmd/link panicked:\n%s", out)
46 }
47
48 if !strings.Contains(firstLine, message) {
49 log.Fatalf("%s: cmd/link output did not include expected message %q: %s", buildid, message, firstLine)
50 }
51 }
52
View as plain text