1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00
goreleaser/internal/shell/shell_test.go
Carlos Alexandro Becker 2bf08f11a6
ci: run build/test workflow on windows too (#5263)
Maybe 3rd time is the charm!

This makes the CI build run on windows too, and fix broken tests/featuers on Windows.

Most of the changes are related to ignoring certain tests on windows, or making sure to use the right path separators.

More work to do in the future, probably!

#4293

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-11-16 10:30:39 -03:00

42 lines
1.1 KiB
Go

//go:build !windows
// +build !windows
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"))
})
}