3 //go:build !nacl && !js && !wasip1 && gc
5 // Copyright 2014 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
22 // test(" ") // old deprecated & removed syntax
23 test("=") // new syntax
26 func test(sep string) {
28 cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
29 var out, errbuf bytes.Buffer
34 fmt.Println(errbuf.String())
35 fmt.Println(out.String())
40 want := "hello\nhello\nhello\ntrumped\ntrumped\ntrumped\n"
43 fmt.Printf("got %q want %q\n", got, want)
48 cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
49 _, err = cmd.CombinedOutput()
51 fmt.Println("-X linker flag should not accept keys without values")
56 cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go")
57 outx, err := cmd.CombinedOutput()
59 fmt.Println("-X linker flag should not overwrite non-strings")
62 outstr := string(outx)
63 if !strings.Contains(outstr, "main.b") {
64 fmt.Printf("-X linker flag did not diagnose overwrite of main.b:\n%s\n", outstr)
67 if !strings.Contains(outstr, "main.x") {
68 fmt.Printf("-X linker flag did not diagnose overwrite of main.x:\n%s\n", outstr)