mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
97dcc68f1e
commit
91ceda5c18
13 changed files with 848 additions and 16 deletions
51
src/lib/exec_test.go
Normal file
51
src/lib/exec_test.go
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue