1 // +build !nacl,!js,!wasip1,gc
4 // Copyright 2014 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.
21 // test(" ") // old deprecated & removed syntax
22 test("=") // new syntax
25 func test(sep string) {
27 cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
28 var out, errbuf bytes.Buffer
33 fmt.Println(errbuf.String())
34 fmt.Println(out.String())
39 want := "hello\nhello\nhello\ntrumped\ntrumped\ntrumped\n"
42 fmt.Printf("got %q want %q\n", got, want)
47 cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
48 _, err = cmd.CombinedOutput()
50 fmt.Println("-X linker flag should not accept keys without values")
55 cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go")
56 outx, err := cmd.CombinedOutput()
58 fmt.Println("-X linker flag should not overwrite non-strings")
61 outstr := string(outx)
62 if !strings.Contains(outstr, "main.b") {
63 fmt.Printf("-X linker flag did not diagnose overwrite of main.b:\n%s\n", outstr)
66 if !strings.Contains(outstr, "main.x") {
67 fmt.Printf("-X linker flag did not diagnose overwrite of main.x:\n%s\n", outstr)