| // Copyright 2019 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // Issue 36021: verify that text/template doesn't prevent the linker from removing |
| func TestLinkerGC(t *testing.T) { |
| t.Skip("skipping in short mode") |
| testenv.MustHaveGoBuild(t) |
| const prog = `package main |
| func (t *T) Unused() { println("THIS SHOULD BE ELIMINATED") } |
| td, err := ioutil.TempDir("", "text_template_TestDeadCodeElimination") |
| if err := ioutil.WriteFile(filepath.Join(td, "x.go"), []byte(prog), 0644); err != nil { |
| cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "x.exe", "x.go") |
| if out, err := cmd.CombinedOutput(); err != nil { |
| t.Fatalf("go build: %v, %s", err, out) |
| slurp, err := ioutil.ReadFile(filepath.Join(td, "x.exe")) |
| if bytes.Contains(slurp, []byte("THIS SHOULD BE ELIMINATED")) { |
| t.Error("binary contains code that should be deadcode eliminated") |