modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue14636.go (about) 1 // +build !nacl,!android,!darwin darwin,!arm 2 // run 3 4 // Copyright 2016 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 package main 9 10 import ( 11 "bytes" 12 "log" 13 "os/exec" 14 "strings" 15 ) 16 17 func main() { 18 checkLinkOutput("", "-B argument must start with 0x") 19 checkLinkOutput("0", "-B argument must start with 0x") 20 checkLinkOutput("0x", "usage") 21 checkLinkOutput("0x0", "-B argument must have even number of digits") 22 checkLinkOutput("0x00", "usage") 23 checkLinkOutput("0xYZ", "-B argument contains invalid hex digit") 24 checkLinkOutput("0x"+strings.Repeat("00", 32), "usage") 25 checkLinkOutput("0x"+strings.Repeat("00", 33), "-B option too long (max 32 digits)") 26 } 27 28 func checkLinkOutput(buildid string, message string) { 29 cmd := exec.Command("go", "tool", "link", "-B", buildid) 30 out, err := cmd.CombinedOutput() 31 if err == nil { 32 log.Fatalf("expected cmd/link to fail") 33 } 34 35 firstLine := string(bytes.SplitN(out, []byte("\n"), 2)[0]) 36 if strings.HasPrefix(firstLine, "panic") { 37 log.Fatalf("cmd/link panicked:\n%s", out) 38 } 39 40 if !strings.Contains(firstLine, message) { 41 log.Fatalf("cmd/link output did not include expected message %q: %s", message, firstLine) 42 } 43 }