}
func TestEcho(t *testing.T) {
+ t.Parallel()
+
bs, err := helperCommand(t, "echo", "foo bar", "baz").Output()
if err != nil {
t.Errorf("echo: %v", err)
}
func TestCommandRelativeName(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "echo", "foo")
// Run our own binary as a relative path
}
func TestCatStdin(t *testing.T) {
+ t.Parallel()
+
// Cat, testing stdin and stdout.
input := "Input string\nLine 2"
p := helperCommand(t, "cat")
}
func TestEchoFileRace(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "echo")
stdin, err := cmd.StdinPipe()
if err != nil {
}
func TestCatGoodAndBadFile(t *testing.T) {
+ t.Parallel()
+
// Testing combined output and error values.
bs, err := helperCommand(t, "cat", "/bogus/file.foo", "exec_test.go").CombinedOutput()
if _, ok := err.(*exec.ExitError); !ok {
}
func TestNoExistExecutable(t *testing.T) {
+ t.Parallel()
+
// Can't run a non-existent executable
err := exec.Command("/no-exist-executable").Run()
if err == nil {
}
func TestExitStatus(t *testing.T) {
+ t.Parallel()
+
// Test that exit values are returned correctly
cmd := helperCommand(t, "exit", "42")
err := cmd.Run()
}
func TestExitCode(t *testing.T) {
+ t.Parallel()
+
// Test that exit code are returned correctly
cmd := helperCommand(t, "exit", "42")
cmd.Run()
}
func TestPipes(t *testing.T) {
+ t.Parallel()
+
check := func(what string, err error) {
if err != nil {
t.Fatalf("%s: %v", what, err)
// Issue 6270.
func TestStdinClose(t *testing.T) {
+ t.Parallel()
+
check := func(what string, err error) {
if err != nil {
t.Fatalf("%s: %v", what, err)
// This test is run by cmd/dist under the race detector to verify that
// the race detector no longer reports any problems.
func TestStdinCloseRace(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "stdinClose")
stdin, err := cmd.StdinPipe()
if err != nil {
if runtime.GOOS == "windows" {
t.Skip("we don't currently suppore counting open handles on windows")
}
+ // Not parallel: checks for leaked file descriptors
openFDs := func() []uintptr {
var fds []uintptr
}
func TestExtraFiles(t *testing.T) {
+ if testing.Short() {
+ t.Skipf("skipping test in short mode that would build a helper binary")
+ }
+
if haveUnexpectedFDs {
// The point of this test is to make sure that any
// descriptors we open are marked close-on-exec.
maySkipHelperCommand("describefiles")
t.Skip("no operating system support; skipping")
}
+ t.Parallel()
+
listen := func() net.Listener {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
for _, f := range cb.ExtraFiles {
f.Close()
}
-
}
}
// Issue 9173: ignore stdin pipe writes if the program completes successfully.
func TestIgnorePipeErrorOnSuccess(t *testing.T) {
+ t.Parallel()
+
testWith := func(r io.Reader) func(*testing.T) {
return func(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "echo", "foo")
var out strings.Builder
cmd.Stdin = r
}
func TestClosePipeOnCopyError(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "yes")
cmd.Stdout = new(badWriter)
err := cmd.Run()
}
func TestOutputStderrCapture(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "stderrfail")
_, err := cmd.Output()
ee, ok := err.(*exec.ExitError)
}
func TestContext(t *testing.T) {
+ t.Parallel()
+
ctx, cancel := context.WithCancel(context.Background())
c := helperCommandContext(t, ctx, "pipetest")
stdin, err := c.StdinPipe()
// test that environment variables are de-duped.
func TestDedupEnvEcho(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "echoenv", "FOO")
cmd.Env = append(cmd.Environ(), "FOO=bad", "FOO=good")
out, err := cmd.CombinedOutput()
}
func TestString(t *testing.T) {
+ t.Parallel()
+
echoPath, err := exec.LookPath("echo")
if err != nil {
t.Skip(err)
}
func TestStringPathNotResolved(t *testing.T) {
+ t.Parallel()
+
_, err := exec.LookPath("makemeasandwich")
if err == nil {
t.Skip("wow, thanks")
}
+
cmd := exec.Command("makemeasandwich", "-lettuce")
want := "makemeasandwich -lettuce"
if got := cmd.String(); got != want {
// Start twice, which returns an error on the second call, would spuriously
// close the pipes established in the first call.
func TestDoubleStartLeavesPipesOpen(t *testing.T) {
+ t.Parallel()
+
cmd := helperCommand(t, "pipetest")
in, err := cmd.StdinPipe()
if err != nil {
}
func TestLookPathWindows(t *testing.T) {
+ if testing.Short() {
+ maySkipHelperCommand("lookpath")
+ t.Skipf("skipping test in short mode that would build a helper binary")
+ }
+ t.Parallel()
+
tmp := t.TempDir()
printpathExe := buildPrintPathExe(t, tmp)
// Run all tests.
for i, test := range lookPathTests {
+ i, test := i, test
t.Run(fmt.Sprint(i), func(t *testing.T) {
+ t.Parallel()
+
dir := filepath.Join(tmp, "d"+strconv.Itoa(i))
err := os.Mkdir(dir, 0700)
if err != nil {
}
func TestCommand(t *testing.T) {
+ if testing.Short() {
+ maySkipHelperCommand("exec")
+ t.Skipf("skipping test in short mode that would build a helper binary")
+ }
+ t.Parallel()
+
tmp := t.TempDir()
printpathExe := buildPrintPathExe(t, tmp)
// Run all tests.
for i, test := range commandTests {
- dir := filepath.Join(tmp, "d"+strconv.Itoa(i))
- err := os.Mkdir(dir, 0700)
- if err != nil {
- t.Fatal("Mkdir failed: ", err)
- }
- test.run(t, dir, printpathExe)
+ i, test := i, test
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ t.Parallel()
+
+ dir := filepath.Join(tmp, "d"+strconv.Itoa(i))
+ err := os.Mkdir(dir, 0700)
+ if err != nil {
+ t.Fatal("Mkdir failed: ", err)
+ }
+ test.run(t, dir, printpathExe)
+ })
}
}