mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-22 04:08:49 +02:00
ec2db4a727
<!-- Hi, thanks for contributing! Please make sure you read our CONTRIBUTING guide. Also, add tests and the respective documentation changes as well. --> <!-- If applied, this commit will... --> ... <!-- Why is this change being made? --> ... <!-- # Provide links to any relevant tickets, URLs or other resources --> ... --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package shell_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/shell"
|
|
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRunCommand(t *testing.T) {
|
|
t.Run("simple", func(t *testing.T) {
|
|
require.NoError(t, shell.Run(testctx.New(), "", []string{"echo", "oi"}, []string{}, false))
|
|
})
|
|
|
|
t.Run("cmd failed", func(t *testing.T) {
|
|
require.EqualError(
|
|
t,
|
|
shell.Run(testctx.New(), "", []string{"sh", "-c", "exit 1"}, []string{}, false),
|
|
`shell: 'sh -c exit 1': exit status 1: [no output]`,
|
|
)
|
|
})
|
|
|
|
t.Run("cmd with output", func(t *testing.T) {
|
|
require.EqualError(
|
|
t,
|
|
shell.Run(testctx.New(), "", []string{"sh", "-c", `echo something; exit 1`}, []string{}, true),
|
|
`shell: 'sh -c echo something; exit 1': exit status 1: something`,
|
|
)
|
|
})
|
|
|
|
t.Run("with env and dir", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
require.NoError(t, shell.Run(testctx.New(), dir, []string{"sh", "-c", "touch $FOO"}, []string{"FOO=bar"}, false))
|
|
require.FileExists(t, filepath.Join(dir, "bar"))
|
|
})
|
|
}
|