github.com/goreleaser/goreleaser@v1.25.1/internal/shell/shell_test.go (about) 1 package shell_test 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/goreleaser/goreleaser/internal/shell" 8 "github.com/goreleaser/goreleaser/internal/testctx" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestRunCommand(t *testing.T) { 13 t.Run("simple", func(t *testing.T) { 14 require.NoError(t, shell.Run(testctx.New(), "", []string{"echo", "oi"}, []string{}, false)) 15 }) 16 17 t.Run("cmd failed", func(t *testing.T) { 18 require.EqualError( 19 t, 20 shell.Run(testctx.New(), "", []string{"sh", "-c", "exit 1"}, []string{}, false), 21 `shell: 'sh -c exit 1': exit status 1: [no output]`, 22 ) 23 }) 24 25 t.Run("cmd with output", func(t *testing.T) { 26 require.EqualError( 27 t, 28 shell.Run(testctx.New(), "", []string{"sh", "-c", `echo something; exit 1`}, []string{}, true), 29 `shell: 'sh -c echo something; exit 1': exit status 1: something`, 30 ) 31 }) 32 33 t.Run("with env and dir", func(t *testing.T) { 34 dir := t.TempDir() 35 require.NoError(t, shell.Run(testctx.New(), dir, []string{"sh", "-c", "touch $FOO"}, []string{"FOO=bar"}, false)) 36 require.FileExists(t, filepath.Join(dir, "bar")) 37 }) 38 }