blob: 9a9fca2e7b545aba0b6397a1b6d1d5ba2a3a5b30 [file] [log] [blame]
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package exec
import (
"exec";
"io";
"testing";
)
func TestRunCat(t *testing.T) {
cmd, err := exec.Run("/bin/cat", []string{"cat"}, nil,
exec.Pipe, exec.Pipe, exec.DevNull);
if err != nil {
t.Fatalf("opencmd /bin/cat: %v", err);
}
io.WriteString(cmd.Stdin, "hello, world\n");
cmd.Stdin.Close();
buf, err := io.ReadAll(cmd.Stdout);
if err != nil {
t.Fatalf("reading from /bin/cat: %v", err);
}
if string(buf) != "hello, world\n" {
t.Fatalf("reading from /bin/cat: got %q", buf);
}
if err = cmd.Close(); err != nil {
t.Fatalf("closing /bin/cat: %v", err);
}
}
func TestRunEcho(t *testing.T) {
cmd, err := Run("/bin/echo", []string{"echo", "hello", "world"}, nil,
exec.DevNull, exec.Pipe, exec.DevNull);
if err != nil {
t.Fatalf("opencmd /bin/echo: %v", err);
}
buf, err := io.ReadAll(cmd.Stdout);
if err != nil {
t.Fatalf("reading from /bin/echo: %v", err);
}
if string(buf) != "hello world\n" {
t.Fatalf("reading from /bin/echo: got %q", buf);
}
if err = cmd.Close(); err != nil {
t.Fatalf("closing /bin/echo: %v", err);
}
}