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