mirror of https://github.com/rwxrob/bonzai
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
3 years ago
|
// Copyright 2022 Robert S. Muhlestein.
|
||
|
// SPDX-License-Identifier: Apache-2.0
|
||
3 years ago
|
|
||
3 years ago
|
package Z
|
||
3 years ago
|
|
||
|
import (
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
// go coverage detection is fucked for this sort of stuff, oh well, we
|
||
|
// did the test even if coverage falsely reports 50%
|
||
3 years ago
|
func TestSysExec(t *testing.T) {
|
||
3 years ago
|
if os.Getenv("TESTING_EXEC") == "1" {
|
||
|
err := Exec("go", "version")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
return
|
||
|
}
|
||
3 years ago
|
cmd := exec.Command(os.Args[0], "-test.run=TestSysExec")
|
||
3 years ago
|
cmd.Env = append(os.Environ(), "TESTING_EXEC=1")
|
||
|
err := cmd.Run()
|
||
|
if err != nil {
|
||
|
t.Fatalf("process exited with %v", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func TestSysExec_noargs(t *testing.T) {
|
||
|
err := SysExec()
|
||
3 years ago
|
if err == nil {
|
||
|
t.Error("should have failed since no command")
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func TestExec_noargs(t *testing.T) {
|
||
|
err := Exec()
|
||
3 years ago
|
if err == nil {
|
||
|
t.Error("should have failed since no command")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestExec_nocmd(t *testing.T) {
|
||
|
err := Exec("__inoexist")
|
||
|
if err == nil {
|
||
|
t.Error("should have failed since no command")
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func TestExec(t *testing.T) {
|
||
|
err := Exec("go", "version")
|
||
3 years ago
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
}
|