summaryrefslogtreecommitdiff
path: root/src/lib/exec_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-02-15 19:35:52 -0800
committerRuss Cox <rsc@golang.org>2009-02-15 19:35:52 -0800
commit6c76acf88cb2c97bf60c34caa01e868f61bad436 (patch)
tree9600ec63eb31a171bc1f911505eae0806b9d33d5 /src/lib/exec_test.go
parent491b1c363470e285bb91b69c32e6a023dcc66643 (diff)
downloadgolang-6c76acf88cb2c97bf60c34caa01e868f61bad436.tar.gz
add os.ForkExec, os.Exec, os.Wait, exec.OpenCmd.
as thread-safe as possible, given the surrounding system. add stub RWLock implementation. R=r DELTA=852 (834 added, 6 deleted, 12 changed) OCL=25046 CL=25053
Diffstat (limited to 'src/lib/exec_test.go')
-rw-r--r--src/lib/exec_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/exec_test.go b/src/lib/exec_test.go
new file mode 100644
index 000000000..740dfa765
--- /dev/null
+++ b/src/lib/exec_test.go
@@ -0,0 +1,51 @@
+// 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 TestOpenCmdCat(t *testing.T) {
+ cmd, err := exec.OpenCmd("/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();
+ var buf [64]byte;
+ n, err1 := io.Readn(cmd.Stdout, buf);
+ if err1 != nil && err1 != io.ErrEOF {
+ t.Fatalf("reading from /bin/cat: %v", err1);
+ }
+ if string(buf[0:n]) != "hello, world\n" {
+ t.Fatalf("reading from /bin/cat: got %q", buf[0:n]);
+ }
+ if err1 = cmd.Close(); err1 != nil {
+ t.Fatalf("closing /bin/cat: %v", err1);
+ }
+}
+
+func TestOpenCmdEcho(t *testing.T) {
+ cmd, err := OpenCmd("/bin/echo", []string("echo", "hello", "world"), nil,
+ exec.DevNull, exec.Pipe, exec.DevNull);
+ if err != nil {
+ t.Fatalf("opencmd /bin/echo: %v", err);
+ }
+ var buf [64]byte;
+ n, err1 := io.Readn(cmd.Stdout, buf);
+ if err1 != nil && err1 != io.ErrEOF {
+ t.Fatalf("reading from /bin/echo: %v", err1);
+ }
+ if string(buf[0:n]) != "hello world\n" {
+ t.Fatalf("reading from /bin/echo: got %q", buf[0:n]);
+ }
+ if err1 = cmd.Close(); err1 != nil {
+ t.Fatalf("closing /bin/echo: %v", err1);
+ }
+}