2021-09-16 15:38:43 +02:00
|
|
|
//go:build !windows
|
2021-04-08 13:24:49 +02:00
|
|
|
// +build !windows
|
|
|
|
|
2020-10-04 09:41:33 +02:00
|
|
|
package gui
|
|
|
|
|
2022-08-07 14:09:39 +02:00
|
|
|
// this is the new way of running tests. See pkg/integration/integration_tests/commit.go
|
|
|
|
// for an example
|
|
|
|
|
2020-10-04 09:41:33 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
2021-04-05 05:07:25 +02:00
|
|
|
"io"
|
2020-10-04 09:41:33 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2021-04-06 01:02:01 +02:00
|
|
|
"os/exec"
|
2022-06-11 04:42:16 +02:00
|
|
|
"strconv"
|
2020-10-04 09:41:33 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-04-05 05:07:25 +02:00
|
|
|
"github.com/creack/pty"
|
2021-04-05 12:37:18 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/integration"
|
2022-08-07 14:09:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/integration/types"
|
2020-10-04 09:41:33 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test(t *testing.T) {
|
2022-06-11 04:42:16 +02:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration tests in short mode")
|
|
|
|
}
|
|
|
|
|
2022-01-15 11:24:19 +02:00
|
|
|
mode := integration.GetModeFromEnv()
|
2021-04-06 10:20:34 +02:00
|
|
|
includeSkipped := os.Getenv("INCLUDE_SKIPPED") != ""
|
2021-04-06 01:02:01 +02:00
|
|
|
|
2022-06-11 04:42:16 +02:00
|
|
|
parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
|
|
|
|
parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
|
|
|
|
testNumber := 0
|
|
|
|
|
2022-08-07 14:09:39 +02:00
|
|
|
err := integration.RunTestsNew(
|
2021-04-06 01:02:01 +02:00
|
|
|
t.Logf,
|
|
|
|
runCmdHeadless,
|
2022-08-07 14:09:39 +02:00
|
|
|
func(test types.Test, f func(*testing.T) error) {
|
2022-06-11 04:42:16 +02:00
|
|
|
defer func() { testNumber += 1 }()
|
|
|
|
if testNumber%parallelTotal != parallelIndex {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-07 14:09:39 +02:00
|
|
|
t.Run(test.Name(), func(t *testing.T) {
|
2021-04-06 07:20:36 +02:00
|
|
|
err := f(t)
|
2020-10-05 11:55:15 +02:00
|
|
|
assert.NoError(t, err)
|
2021-04-06 01:02:01 +02:00
|
|
|
})
|
|
|
|
},
|
2022-01-15 11:24:19 +02:00
|
|
|
mode,
|
2021-10-22 11:18:40 +02:00
|
|
|
func(t *testing.T, expected string, actual string, prefix string) {
|
2022-03-19 00:38:49 +02:00
|
|
|
t.Helper()
|
2021-10-22 11:18:40 +02:00
|
|
|
assert.Equal(t, expected, actual, fmt.Sprintf("Unexpected %s. Expected:\n%s\nActual:\n%s\n", prefix, expected, actual))
|
2021-04-06 01:02:01 +02:00
|
|
|
},
|
2021-04-06 10:20:34 +02:00
|
|
|
includeSkipped,
|
2021-04-06 01:02:01 +02:00
|
|
|
)
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2020-10-06 00:23:09 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
func runCmdHeadless(cmd *exec.Cmd) error {
|
|
|
|
cmd.Env = append(
|
|
|
|
cmd.Env,
|
|
|
|
"HEADLESS=true",
|
|
|
|
"TERM=xterm",
|
|
|
|
)
|
2020-10-06 00:23:09 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 100, Cols: 100})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
_, _ = io.Copy(ioutil.Discard, f)
|
2020-10-04 09:41:33 +02:00
|
|
|
|
2021-04-06 01:02:01 +02:00
|
|
|
return f.Close()
|
2020-10-04 09:41:33 +02:00
|
|
|
}
|
2022-06-11 04:42:16 +02:00
|
|
|
|
|
|
|
func tryConvert(numStr string, defaultVal int) int {
|
|
|
|
num, err := strconv.Atoi(numStr)
|
|
|
|
if err != nil {
|
|
|
|
return defaultVal
|
|
|
|
}
|
|
|
|
|
|
|
|
return num
|
|
|
|
}
|