diff --git a/cmd/micro/micro_test.go b/cmd/micro/micro_test.go index ba5c9a24b8..7866d52763 100644 --- a/cmd/micro/micro_test.go +++ b/cmd/micro/micro_test.go @@ -107,7 +107,10 @@ func handleEvent() { if e != nil { screen.Events <- e } - DoEvent() + + for len(screen.DrawChan()) > 0 || len(screen.Events) > 0 { + DoEvent() + } } func injectKey(key tcell.Key, r rune, mod tcell.ModMask) { @@ -149,6 +152,16 @@ func openFile(file string) { injectKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone) } +func findBuffer(file string) *buffer.Buffer { + var buf *buffer.Buffer + for _, b := range buffer.OpenBuffers { + if b.Path == file { + buf = b + } + } + return buf +} + func createTestFile(name string, content string) (string, error) { testf, err := ioutil.TempFile("", name) if err != nil { @@ -188,14 +201,7 @@ func TestSimpleEdit(t *testing.T) { openFile(file) - var buf *buffer.Buffer - for _, b := range buffer.OpenBuffers { - if b.Path == file { - buf = b - } - } - - if buf == nil { + if findBuffer(file) == nil { t.Errorf("Could not find buffer %s", file) return } @@ -234,6 +240,11 @@ func TestMouse(t *testing.T) { openFile(file) + if findBuffer(file) == nil { + t.Errorf("Could not find buffer %s", file) + return + } + // buffer: // base content // the selections need to happen at different locations to avoid a double click @@ -297,6 +308,11 @@ func TestSearchAndReplace(t *testing.T) { openFile(file) + if findBuffer(file) == nil { + t.Errorf("Could not find buffer %s", file) + return + } + injectKey(tcell.KeyCtrlE, rune(tcell.KeyCtrlE), tcell.ModCtrl) injectString(fmt.Sprintf("replaceall %s %s", "foo", "test_string")) injectKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone)