diff options
Diffstat (limited to 'src/cmd/pack/pack_test.go')
-rw-r--r-- | src/cmd/pack/pack_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go index 79d9cde292..b2217c090f 100644 --- a/src/cmd/pack/pack_test.go +++ b/src/cmd/pack/pack_test.go @@ -295,6 +295,37 @@ func TestLargeDefs(t *testing.T) { } } +// Test that "\n!\n" inside export data doesn't result in a truncated +// package definition when creating a .a archive from a .o Go object. +func TestIssue21703(t *testing.T) { + testenv.MustHaveGoBuild(t) + + dir := tmpDir(t) + defer os.RemoveAll(dir) + + const aSrc = `package a; const X = "\n!\n"` + err := ioutil.WriteFile(filepath.Join(dir, "a.go"), []byte(aSrc), 0666) + if err != nil { + t.Fatal(err) + } + + const bSrc = `package b; import _ "a"` + err = ioutil.WriteFile(filepath.Join(dir, "b.go"), []byte(bSrc), 0666) + if err != nil { + t.Fatal(err) + } + + run := func(args ...string) string { + return doRun(t, dir, args...) + } + + goBin := testenv.GoToolPath(t) + run(goBin, "build", "cmd/pack") // writes pack binary to dir + run(goBin, "tool", "compile", "a.go") + run("./pack", "c", "a.a", "a.o") + run(goBin, "tool", "compile", "-I", ".", "b.go") +} + // doRun runs a program in a directory and returns the output. func doRun(t *testing.T, dir string, args ...string) string { cmd := exec.Command(args[0], args[1:]...) |