11package execute
22
33import (
4+ "bytes"
45 "os"
56 "strings"
67 "testing"
@@ -25,6 +26,49 @@ func TestExec_WithShell(t *testing.T) {
2526 }
2627}
2728
29+ func TestExec_CatTransformString (t * testing.T ) {
30+ input := "1 line 1"
31+
32+ reader := bytes .NewReader ([]byte (input ))
33+ want := " 1\t 1 line 1"
34+
35+ task := ExecTask {Command : "cat" , Shell : false , Args : []string {"-b" }, Stdin : reader }
36+ res , err := task .Execute ()
37+ if err != nil {
38+ t .Errorf (err .Error ())
39+ t .Fail ()
40+ }
41+
42+ if res .Stdout != want {
43+ t .Errorf ("want %q, got %q" , want , res .Stdout )
44+ t .Fail ()
45+ }
46+ }
47+
48+ func TestExec_CatWC (t * testing.T ) {
49+ input := `this
50+ has
51+ four
52+ lines
53+ `
54+
55+ reader := bytes .NewReader ([]byte (input ))
56+ want := "4"
57+
58+ task := ExecTask {Command : "wc" , Shell : false , Args : []string {"-l" }, Stdin : reader }
59+ res , err := task .Execute ()
60+ if err != nil {
61+ t .Errorf (err .Error ())
62+ t .Fail ()
63+ }
64+
65+ got := strings .TrimSpace (res .Stdout )
66+ if got != want {
67+ t .Errorf ("want %q, got %q" , want , got )
68+ t .Fail ()
69+ }
70+ }
71+
2872func TestExec_WithEnvVars (t * testing.T ) {
2973 task := ExecTask {Command : "env" , Shell : false , Env : []string {"GOTEST=1" , "GOTEST2=2" }}
3074 res , err := task .Execute ()
@@ -42,7 +86,6 @@ func TestExec_WithEnvVars(t *testing.T) {
4286 t .Errorf ("want env to show GOTEST2=2 since we passed that variable" )
4387 t .Fail ()
4488 }
45-
4689}
4790
4891func TestExec_WithEnvVarsInheritedFromParent (t * testing.T ) {
0 commit comments