2021-04-06 01:02:01 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2021-04-06 07:20:36 +02:00
|
|
|
"testing"
|
2021-04-06 01:02:01 +02:00
|
|
|
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/integration"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-15 11:24:19 +02:00
|
|
|
// see https://github.com/jesseduffield/lazygit/blob/master/docs/Integration_Tests.md
|
2021-04-06 01:02:01 +02:00
|
|
|
// This file can be invoked directly, but you might find it easier to go through
|
2022-01-15 11:24:19 +02:00
|
|
|
// test/lazyintegration/main.go, which provides a convenient gui wrapper to integration tests.
|
2021-04-06 01:02:01 +02:00
|
|
|
//
|
|
|
|
// If invoked directly, you can specify a test by passing it as the first argument.
|
2022-01-15 11:24:19 +02:00
|
|
|
// You can also specify that you want to record a test by passing MODE=record
|
2021-04-06 01:02:01 +02:00
|
|
|
// as an env var.
|
|
|
|
|
|
|
|
func main() {
|
2022-01-15 11:24:19 +02:00
|
|
|
mode := integration.GetModeFromEnv()
|
2021-04-06 01:02:01 +02:00
|
|
|
speedEnv := os.Getenv("SPEED")
|
2022-01-15 11:24:19 +02:00
|
|
|
includeSkipped := os.Getenv("INCLUDE_SKIPPED") == "true"
|
2021-04-06 01:02:01 +02:00
|
|
|
selectedTestName := os.Args[1]
|
|
|
|
|
|
|
|
err := integration.RunTests(
|
|
|
|
log.Printf,
|
|
|
|
runCmdInTerminal,
|
2021-04-06 07:20:36 +02:00
|
|
|
func(test *integration.Test, f func(*testing.T) error) {
|
2021-04-06 01:02:01 +02:00
|
|
|
if selectedTestName != "" && test.Name != selectedTestName {
|
|
|
|
return
|
|
|
|
}
|
2021-04-06 07:20:36 +02:00
|
|
|
if err := f(nil); err != nil {
|
2021-04-06 01:02:01 +02:00
|
|
|
log.Print(err.Error())
|
|
|
|
}
|
|
|
|
},
|
2022-01-15 11:24:19 +02:00
|
|
|
mode,
|
2021-04-06 01:02:01 +02:00
|
|
|
speedEnv,
|
2021-10-22 11:18:40 +02:00
|
|
|
func(_t *testing.T, expected string, actual string, prefix string) {
|
|
|
|
assert.Equal(MockTestingT{}, 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
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MockTestingT struct{}
|
|
|
|
|
|
|
|
func (t MockTestingT) Errorf(format string, args ...interface{}) {
|
|
|
|
fmt.Printf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runCmdInTerminal(cmd *exec.Cmd) error {
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
|
|
|
return cmd.Run()
|
|
|
|
}
|