tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
tg.grepBoth(okPattern, "go test did not say ok")
}
+
+func TestLinkXImportPathEscape(t *testing.T) {
+ // golang.org/issue/16710
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+ exe := "./linkx" + exeSuffix
+ tg.creatingTemp(exe)
+ tg.run("build", "-o", exe, "-ldflags", "-X=my.pkg.Text=linkXworked", "my.pkg/main")
+ out, err := exec.Command(exe).CombinedOutput()
+ if err != nil {
+ tg.t.Fatal(err)
+ }
+ if string(out) != "linkXworked\n" {
+ tg.t.Log(string(out))
+ tg.t.Fatal(`incorrect output: expected "linkXworked\n"`)
+ }
+}
var strdata []*Symbol
func addstrdata1(ctxt *Link, arg string) {
- i := strings.Index(arg, "=")
- if i < 0 {
+ eq := strings.Index(arg, "=")
+ dot := strings.LastIndex(arg[:eq+1], ".")
+ if eq < 0 || dot < 0 {
Exitf("-X flag requires argument of the form importpath.name=value")
}
- addstrdata(ctxt, arg[:i], arg[i+1:])
+ addstrdata(ctxt, pathtoprefix(arg[:dot])+arg[dot:eq], arg[eq+1:])
}
func addstrdata(ctxt *Link, name string, value string) {