diff --git a/_tasks.hcl b/_tasks.hcl index aaa47687..0eefcb54 100644 --- a/_tasks.hcl +++ b/_tasks.hcl @@ -1,13 +1,13 @@ task "install-deps" { description = "Install all of package dependencies" pipeline = [ - "go get {{.files}}", + "go get -v {{.files}}", ] } task "tests" { description = "Run the test suite" - command = "go test {{.files}}" + command = "go test -v {{.files}}" environment = { GOFLAGS = "-mod=vendor" } diff --git a/editor_test.go b/editor_test.go index 97f1144a..5ad9d627 100644 --- a/editor_test.go +++ b/editor_test.go @@ -102,10 +102,6 @@ func TestEditorRender(t *testing.T) { } func TestEditorPrompt(t *testing.T) { - if os.Getenv("SKIP_EDITOR_PROMPT_TESTS") != "" { - t.Skip("editor prompt tests skipped by dev") - } - if _, err := exec.LookPath("vi"); err != nil { t.Skip("vi not found in PATH") } @@ -122,7 +118,7 @@ func TestEditorPrompt(t *testing.T) { c.SendLine("") go c.ExpectEOF() time.Sleep(time.Millisecond) - c.Send("iAdd editor prompt tests\x1b") + c.Send("ccAdd editor prompt tests\x1b") c.SendLine(":wq!") }, "Add editor prompt tests\n", @@ -155,7 +151,7 @@ func TestEditorPrompt(t *testing.T) { c.SendLine("") go c.ExpectEOF() time.Sleep(time.Millisecond) - c.Send("iAdd editor prompt tests\x1b") + c.Send("ccAdd editor prompt tests\x1b") c.SendLine(":wq!") }, "Add editor prompt tests\n", @@ -196,7 +192,7 @@ func TestEditorPrompt(t *testing.T) { c.SendLine("") go c.ExpectEOF() time.Sleep(time.Millisecond) - c.Send("iAdd editor prompt tests\x1b") + c.Send("ccAdd editor prompt tests\x1b") c.SendLine(":wq!") }, "Add editor prompt tests\n", @@ -230,7 +226,7 @@ func TestEditorPrompt(t *testing.T) { c.SendLine("") go c.ExpectEOF() time.Sleep(time.Millisecond) - c.Send("iAdd editor prompt tests\x1b") + c.Send("ccAdd editor prompt tests\x1b") c.SendLine(":wq!") }, "Add editor prompt tests\n", diff --git a/survey_test.go b/survey_test.go index 5ca77055..d32dc3c2 100644 --- a/survey_test.go +++ b/survey_test.go @@ -2,8 +2,6 @@ package survey import ( "fmt" - "os" - "os/exec" "strings" "testing" "time" @@ -134,23 +132,6 @@ func TestPagination_lastHalf(t *testing.T) { } func TestAsk(t *testing.T) { - - _, err := exec.LookPath("vi") - noEditor := err != nil || os.Getenv("SKIP_EDITOR_PROMPT_TESTS") != "" - - filter := func(qs []*Question) []*Question { return qs } - if noEditor { - filter = func(qs []*Question) []*Question { - r := make([]*Question, 0) - for _, q := range qs { - if _, ok := q.Prompt.(*Editor); !ok { - r = append(r, q) - } - } - return r - } - } - tests := []struct { name string questions []*Question @@ -159,7 +140,7 @@ func TestAsk(t *testing.T) { }{ { "Test Ask for all prompts", - filter([]*Question{ + []*Question{ { Name: "pizza", Prompt: &Confirm{ @@ -215,35 +196,35 @@ func TestAsk(t *testing.T) { Options: []string{"red", "blue", "green", "yellow"}, }, }, - }), + }, func(c *expect.Console) { // Confirm c.ExpectString("Is pizza your favorite food? (y/N)") c.SendLine("Y") - if !noEditor { - // Editor - c.ExpectString("Edit git commit message [Enter to launch editor]") - c.SendLine("") - time.Sleep(time.Millisecond) - c.Send("iAdd editor prompt tests\x1b") - c.SendLine(":wq!") - - // Editor validated - c.ExpectString("Edit git commit message [Enter to launch editor]") - c.SendLine("") - time.Sleep(time.Millisecond) - c.Send("i invalid input first try\x1b") - c.SendLine(":wq!") - time.Sleep(time.Millisecond) - c.ExpectString("invalid error message") - c.ExpectString("Edit git commit message [Enter to launch editor]") - c.SendLine("") - time.Sleep(time.Millisecond) - c.ExpectString("first try") - c.Send("iAdd editor prompt tests\x1b") - c.SendLine(":wq!") - } + // Editor + c.ExpectString("Edit git commit message [Enter to launch editor]") + c.SendLine("") + time.Sleep(time.Millisecond) + c.SendLine(":d") + c.Send(string(terminal.SpecialKeyEnd)) + c.Send("iAdd editor prompt tests\x1b") + c.SendLine(":wq!") + + // Editor validated + c.ExpectString("Edit git commit message [Enter to launch editor]") + c.SendLine("") + time.Sleep(time.Millisecond) + c.Send("i invalid input first try\x1b") + c.SendLine(":wq!") + time.Sleep(time.Millisecond) + c.ExpectString("invalid error message") + c.ExpectString("Edit git commit message [Enter to launch editor]") + c.SendLine("") + time.Sleep(time.Millisecond) + c.ExpectString("first try") + c.Send("ccAdd editor prompt tests, but validated\x1b") + c.SendLine(":wq!") // Input c.ExpectString("What is your name?") @@ -274,7 +255,7 @@ func TestAsk(t *testing.T) { map[string]interface{}{ "pizza": true, "commit-message": "Add editor prompt tests\n", - "commit-message-validated": "Add editor prompt tests\n", + "commit-message-validated": "Add editor prompt tests, but validated\n", "name": "Johnny Appleseed", /* TODO "day": []string{"Monday", "Wednesday"}, @@ -332,16 +313,11 @@ func TestAsk(t *testing.T) { // Capture range variable. test := test t.Run(test.name, func(t *testing.T) { - expectedAnswers := make(map[string]interface{}, 0) - for _, q := range test.questions { - expectedAnswers[q.Name] = test.expected[q.Name] - } - answers := make(map[string]interface{}) RunTest(t, test.procedure, func(stdio terminal.Stdio) error { return Ask(test.questions, &answers, WithStdio(stdio.In, stdio.Out, stdio.Err)) }) - require.Equal(t, expectedAnswers, answers) + require.Equal(t, test.expected, answers) }) } }