Source file
test/sinit_run.go
Documentation: test
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "bytes"
14 "fmt"
15 "io/ioutil"
16 "os"
17 "os/exec"
18 )
19
20 func main() {
21 f, err := ioutil.TempFile("", "sinit-*.o")
22 if err != nil {
23 fmt.Println(err)
24 os.Exit(1)
25 }
26 f.Close()
27
28 cmd := exec.Command("go", "tool", "compile", "-o", f.Name(), "-S", "sinit.go")
29 out, err := cmd.CombinedOutput()
30 os.Remove(f.Name())
31 if err != nil {
32 fmt.Println(string(out))
33 fmt.Println(err)
34 os.Exit(1)
35 }
36
37 if len(bytes.TrimSpace(out)) == 0 {
38 fmt.Println("'go tool compile -S sinit.go' printed no output")
39 os.Exit(1)
40 }
41 if bytes.Contains(out, []byte("initdone")) {
42 fmt.Println("sinit generated an init function")
43 os.Exit(1)
44 }
45 }
46
View as plain text