2018-03-04 04:15:37 -07:00
|
|
|
// +build !nacl,!js
|
2015-12-17 13:10:25 -07:00
|
|
|
// run
|
|
|
|
|
|
|
|
// Copyright 2014 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.
|
|
|
|
|
|
|
|
// Run the sinit test.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-11-15 11:13:16 -07:00
|
|
|
"io/ioutil"
|
2015-12-17 13:10:25 -07:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2019-11-15 11:13:16 -07:00
|
|
|
"path/filepath"
|
2015-12-17 13:10:25 -07:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2019-11-15 11:13:16 -07:00
|
|
|
var tmpDir string
|
|
|
|
|
2015-12-17 13:10:25 -07:00
|
|
|
func cleanup() {
|
2019-11-15 11:13:16 -07:00
|
|
|
os.RemoveAll(tmpDir)
|
2015-12-17 13:10:25 -07:00
|
|
|
}
|
|
|
|
|
2019-11-15 11:13:16 -07:00
|
|
|
func run(cmdline ...string) {
|
|
|
|
args := strings.Fields(strings.Join(cmdline, " "))
|
2015-12-17 13:10:25 -07:00
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
2015-12-17 14:37:30 -07:00
|
|
|
fmt.Printf("$ %s\n", cmdline)
|
2015-12-17 13:10:25 -07:00
|
|
|
fmt.Println(string(out))
|
|
|
|
fmt.Println(err)
|
|
|
|
cleanup()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-15 11:13:16 -07:00
|
|
|
func runFail(cmdline ...string) {
|
|
|
|
args := strings.Fields(strings.Join(cmdline, " "))
|
2015-12-17 13:10:25 -07:00
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err == nil {
|
2015-12-17 14:37:30 -07:00
|
|
|
fmt.Printf("$ %s\n", cmdline)
|
2015-12-17 13:10:25 -07:00
|
|
|
fmt.Println(string(out))
|
|
|
|
fmt.Println("SHOULD HAVE FAILED!")
|
|
|
|
cleanup()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-11-15 11:13:16 -07:00
|
|
|
var err error
|
|
|
|
tmpDir, err = ioutil.TempDir("", "")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
tmp := func(name string) string {
|
|
|
|
return filepath.Join(tmpDir, name)
|
|
|
|
}
|
|
|
|
|
2015-12-17 13:10:25 -07:00
|
|
|
// helloworld.go is package main
|
2019-11-15 11:13:16 -07:00
|
|
|
run("go tool compile -o", tmp("linkmain.o"), "helloworld.go")
|
|
|
|
run("go tool compile -pack -o", tmp("linkmain.a"), "helloworld.go")
|
|
|
|
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.o"))
|
|
|
|
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.a"))
|
2015-12-17 13:10:25 -07:00
|
|
|
|
|
|
|
// linkmain.go is not
|
2019-11-15 11:13:16 -07:00
|
|
|
run("go tool compile -o", tmp("linkmain1.o"), "linkmain.go")
|
|
|
|
run("go tool compile -pack -o", tmp("linkmain1.a"), "linkmain.go")
|
|
|
|
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.o"))
|
|
|
|
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.a"))
|
2015-12-17 13:10:25 -07:00
|
|
|
cleanup()
|
|
|
|
}
|