go/src/lib/exec_test.go
Russ Cox 60ce95d7a1 code changes for array conversion.
as a reminder, the old conversion
was that you could write

	var arr [10]byte;
	var slice []byte;
	slice = arr;

but now you have to write

	slice = &arr;

the change eliminates an implicit &, so that
the only implicit &s left are in the . operator
and in string(arr).

also, removed utf8.EncodeRuneToString
in favor of string(rune).

R=r
DELTA=83  (1 added, 23 deleted, 59 changed)
OCL=27531
CL=27534
2009-04-15 20:27:45 -07:00

51 lines
1.3 KiB
Go

// 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();
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 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);
}
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);
}
}