summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/bug369.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
commitccd992355df7192993c666236047820244914598 (patch)
treef00fea65147227b7743083c6148396f74cd66935 /test/fixedbugs/bug369.go
parentInitial commit. (diff)
downloadgolang-1.21-ccd992355df7192993c666236047820244914598.tar.xz
golang-1.21-ccd992355df7192993c666236047820244914598.zip
Adding upstream version 1.21.8.upstream/1.21.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/fixedbugs/bug369.go')
-rw-r--r--test/fixedbugs/bug369.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/fixedbugs/bug369.go b/test/fixedbugs/bug369.go
new file mode 100644
index 0000000..47258fe
--- /dev/null
+++ b/test/fixedbugs/bug369.go
@@ -0,0 +1,61 @@
+// +build !nacl,!js,!wasip1,gc
+// run
+
+// Copyright 2011 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.
+
+// Test that compiling with optimization turned on produces faster code.
+
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+func main() {
+ err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
+ check(err)
+
+ tmpDir, err := ioutil.TempDir("", "bug369")
+ check(err)
+ defer os.RemoveAll(tmpDir)
+
+ tmp := func(name string) string {
+ return filepath.Join(tmpDir, name)
+ }
+
+ check(os.Mkdir(tmp("test"), 0777))
+
+ stdlibimportcfg, err := os.ReadFile(os.Getenv("STDLIB_IMPORTCFG"))
+ check(err)
+ importcfg := string(stdlibimportcfg) + "\npackagefile test/slow=" + tmp("test/slow.o") + "\npackagefile test/fast=" + tmp("test/fast.o")
+ os.WriteFile(tmp("importcfg"), []byte(importcfg), 0644)
+
+ run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=test/slow", "-N", "-o", tmp("test/slow.o"), "pkg.go")
+ run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=test/fast", "-o", tmp("test/fast.o"), "pkg.go")
+ run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=main", "-D", "test", "-o", tmp("main.o"), "main.go")
+ run("go", "tool", "link", "-importcfg="+tmp("importcfg"), "-o", tmp("a.exe"), tmp("main.o"))
+ run(tmp("a.exe"))
+}
+
+func run(name string, args ...string) {
+ cmd := exec.Command(name, args...)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ fmt.Println(string(out))
+ fmt.Println(err)
+ os.Exit(1)
+ }
+}
+
+func check(err error) {
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+}