github.com/NeowayLabs/nash@v0.2.2-0.20200127205349-a227041ffd50/internal/sh/builtin/exec_test.go (about) 1 package builtin_test 2 3 import ( 4 "testing" 5 6 "github.com/madlambda/nash/internal/sh/internal/fixture" 7 ) 8 9 func execSuccess(t *testing.T, scriptContents string) string { 10 shell, cleanup := fixture.SetupShell(t) 11 defer cleanup() 12 13 out, err := shell.ExecOutput("", scriptContents) 14 15 if err != nil { 16 t.Fatalf("unexpected err: %s", err) 17 } 18 return string(out) 19 } 20 21 func execFailure(t *testing.T, scriptContents string) { 22 shell, cleanup := fixture.SetupShell(t) 23 defer cleanup() 24 25 out, err := shell.ExecOutput("", scriptContents) 26 27 if err == nil { 28 t.Fatalf("expected err, got success, output: %s", string(out)) 29 } 30 31 if len(out) > 0 { 32 t.Fatalf("expected empty output, got: %s", string(out)) 33 } 34 }