"flag"
"fmt"
"io"
- "io/fs"
"log"
"os"
"os/exec"
libgodir = filepath.Join(GOPATH, "pkg", libbase, "testcarchive")
cc = append(cc, "-I", libgodir)
+ // Force reallocation (and avoid aliasing bugs) for parallel tests that append to cc.
+ cc = cc[:len(cc):len(cc)]
+
if GOOS == "windows" {
exeSuffix = ".exe"
}
var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`)
-// checkIsExecutable verifies that exe exists and has execute permission.
-//
-// (https://golang.org/issue/49693 notes failures with "no such file or
-// directory", so we want to double-check that the executable actually exists
-// immediately after we build it in order to better understand that failure
-// mode.)
-func checkIsExecutable(t *testing.T, exe string) {
- t.Helper()
- fi, err := os.Stat(exe)
- if err != nil {
- t.Fatal(err)
- }
- if runtime.GOOS == "windows" {
- // os.File doesn't check the "execute" permission on Windows files
- // and as a result doesn't set that bit in a file's permissions.
- // Assume that if the file exists it is “executable enough”.
- return
- }
- if fi.Mode()&0111 == 0 {
- t.Fatalf("%s is not executable: %0o", exe, fi.Mode()&fs.ModePerm)
- }
-}
-
// checkLineComments checks that the export header generated by
// -buildmode=c-archive doesn't have any absolute paths in the #line
// comments. We don't want those paths because they are unhelpful for
if err != nil {
t.Fatal(err)
}
- checkIsExecutable(t, "./testp6"+exeSuffix)
argv := cmdToRun("./testp6")
cmd = exec.Command(argv[0], argv[1:]...)
if err != nil {
t.Fatal(err)
}
- checkIsExecutable(t, "./testp7"+exeSuffix)
argv := cmdToRun("./testp7")
cmd = exec.Command(argv[0], argv[1:]...)
if err != nil {
t.Fatal(err)
}
- checkIsExecutable(t, "./testp8"+exeSuffix)
argv := cmdToRun("./testp8")
cmd = exec.Command(argv[0], argv[1:]...)