60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package cmdext
|
|
|
|
import "testing"
|
|
|
|
func TestStdout(t *testing.T) {
|
|
|
|
res1, err := Runner("printf").Arg("hello").Run()
|
|
if err != nil {
|
|
t.Errorf("%v", err)
|
|
}
|
|
if res1.StdErr != "" {
|
|
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
|
}
|
|
if res1.StdOut != "hello" {
|
|
t.Errorf("res1.StdOut == '%v'", res1.StdOut)
|
|
}
|
|
if res1.StdCombined != "hello\n" {
|
|
t.Errorf("res1.StdCombined == '%v'", res1.StdCombined)
|
|
}
|
|
|
|
}
|
|
|
|
func TestStderr(t *testing.T) {
|
|
|
|
res1, err := Runner("python").Arg("-c").Arg("import sys; print(\"error\", file=sys.stderr, end='')").Run()
|
|
if err != nil {
|
|
t.Errorf("%v", err)
|
|
}
|
|
if res1.StdErr != "error" {
|
|
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
|
}
|
|
if res1.StdOut != "" {
|
|
t.Errorf("res1.StdOut == '%v'", res1.StdOut)
|
|
}
|
|
if res1.StdCombined != "error\n" {
|
|
t.Errorf("res1.StdCombined == '%v'", res1.StdCombined)
|
|
}
|
|
|
|
}
|
|
|
|
func TestStdcombined(t *testing.T) {
|
|
res1, err := Runner("python").
|
|
Arg("-c").
|
|
Arg("import sys; import time; print(\"1\", file=sys.stderr, flush=True); time.sleep(0.1); print(\"2\", file=sys.stdout, flush=True); time.sleep(0.1); print(\"3\", file=sys.stderr, flush=True)").
|
|
Run()
|
|
if err != nil {
|
|
t.Errorf("%v", err)
|
|
}
|
|
if res1.StdErr != "1\n3\n" {
|
|
t.Errorf("res1.StdErr == '%v'", res1.StdErr)
|
|
}
|
|
if res1.StdOut != "2\n" {
|
|
t.Errorf("res1.StdOut == '%v'", res1.StdOut)
|
|
}
|
|
if res1.StdCombined != "1\n2\n3\n" {
|
|
t.Errorf("res1.StdCombined == '%v'", res1.StdCombined)
|
|
}
|
|
|
|
}
|