2021-11-23 15:53:12 -03:00
|
|
|
package shell_test
|
|
|
|
|
|
|
|
import (
|
2022-02-05 16:00:49 -03:00
|
|
|
"path/filepath"
|
2021-11-23 15:53:12 -03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/internal/shell"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2022-02-05 16:00:49 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-11-23 15:53:12 -03:00
|
|
|
)
|
|
|
|
|
2022-02-05 16:00:49 -03:00
|
|
|
func TestRunCommand(t *testing.T) {
|
|
|
|
t.Run("simple", func(t *testing.T) {
|
|
|
|
require.NoError(t, shell.Run(context.New(config.Project{}), "", []string{"echo", "oi"}, []string{}, false))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("cmd failed", func(t *testing.T) {
|
|
|
|
require.EqualError(
|
|
|
|
t,
|
|
|
|
shell.Run(context.New(config.Project{}), "", []string{"sh", "-c", "exit 1"}, []string{}, false),
|
|
|
|
`failed to run 'sh -c exit 1': exit status 1`,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("cmd with output", func(t *testing.T) {
|
|
|
|
require.EqualError(
|
|
|
|
t,
|
|
|
|
shell.Run(context.New(config.Project{}), "", []string{"sh", "-c", `echo something; exit 1`}, []string{}, true),
|
|
|
|
`failed to run 'sh -c echo something; exit 1': exit status 1`,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with env and dir", func(t *testing.T) {
|
|
|
|
dir := t.TempDir()
|
|
|
|
require.NoError(t, shell.Run(context.New(config.Project{}), dir, []string{"sh", "-c", "touch $FOO"}, []string{"FOO=bar"}, false))
|
|
|
|
require.FileExists(t, filepath.Join(dir, "bar"))
|
|
|
|
})
|
2021-11-23 15:53:12 -03:00
|
|
|
}
|