forked from rwxrob/bonzai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.go
58 lines (50 loc) · 1.12 KB
/
run_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
52
53
54
55
56
57
58
// Copyright 2022 Robert S. Muhlestein.
// SPDX-License-Identifier: Apache-2.0
package run_test
import (
"os"
"os/exec"
"testing"
"github.com/rwxrob/bonzai/run"
)
// go coverage detection is bork for this sort of stuff, oh well, we
// did the test even if coverage falsely reports 50%
func TestSysExec(t *testing.T) {
if os.Getenv("TESTING_EXEC") == "1" {
err := run.Exec("go", "version")
if err != nil {
t.Fatal(err)
}
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestSysExec")
cmd.Env = append(os.Environ(), "TESTING_EXEC=1")
err := cmd.Run()
if err != nil {
t.Fatalf("process exited with %v", err)
}
}
func TestSysExec_noargs(t *testing.T) {
err := run.SysExec()
if err == nil {
t.Error("should have failed since no command")
}
}
func TestExec_noargs(t *testing.T) {
err := run.Exec()
if err == nil {
t.Error("should have failed since no command")
}
}
func TestExec_nocmd(t *testing.T) {
err := run.Exec("__inoexist")
if err == nil {
t.Error("should have failed since no command")
}
}
func TestExec(t *testing.T) {
err := run.Exec("go", "version")
if err != nil {
t.Error(err)
}
}