-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
51 lines (46 loc) · 1.2 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main_test
import (
"fmt"
"log"
"os"
"strings"
"testing"
"github.com/edwarnicke/exechelper"
)
func TestImportsGen(t *testing.T) {
cmdStr := "go generate ./testdata"
options := []*exechelper.Option{
exechelper.WithStderr(os.Stderr),
exechelper.WithStdout(os.Stdout),
exechelper.WithEnvirons(os.Environ()...),
}
err := exechelper.Run(cmdStr, options...)
if err != nil {
t.Errorf("failed to run %q: %+v", cmdStr, err)
}
cmdStr = "go build ./testdata"
err = exechelper.Run(cmdStr, options...)
if err != nil {
t.Errorf("failed to run %q: %+v", cmdStr, err)
}
// Extract the GOOS
goos, ok := os.LookupEnv("GOOS")
if !ok {
cmdStr := "go env GOOS"
options := []*exechelper.Option{
exechelper.WithStderr(os.Stderr),
exechelper.WithStdout(os.Stdout),
exechelper.WithEnvirons(os.Environ()...),
}
goosBytes, GoosErr := exechelper.Output(cmdStr, options...)
if GoosErr != nil {
log.Fatalf("error extracting GOOS: %+v", GoosErr)
}
goos = strings.TrimSpace(string(goosBytes))
}
importsFilename := fmt.Sprintf("./testdata/%s", fmt.Sprintf("imports_%s.go", goos))
err = os.Remove(importsFilename)
if err != nil {
t.Errorf("failed to remove %q: %+v", importsFilename, err)
}
}