summaryrefslogtreecommitdiff
path: root/src/reader_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/reader_test.go')
-rw-r--r--src/reader_test.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/reader_test.go b/src/reader_test.go
index d5c218cb..82ca6b7b 100644
--- a/src/reader_test.go
+++ b/src/reader_test.go
@@ -2,6 +2,7 @@ package fzf
import (
"testing"
+ "time"
"github.com/junegunn/fzf/src/util"
)
@@ -11,7 +12,10 @@ func TestReadFromCommand(t *testing.T) {
eb := util.NewEventBox()
reader := Reader{
pusher: func(s []byte) bool { strs = append(strs, string(s)); return true },
- eventBox: eb}
+ eventBox: eb,
+ event: int32(EvtReady)}
+
+ reader.startEventPoller()
// Check EventBox
if eb.Peek(EvtReadNew) {
@@ -19,21 +23,16 @@ func TestReadFromCommand(t *testing.T) {
}
// Normal command
- reader.readFromCommand(`echo abc && echo def`)
+ reader.fin(reader.readFromCommand(`echo abc && echo def`))
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
t.Errorf("%s", strs)
}
// Check EventBox again
- if !eb.Peek(EvtReadNew) {
- t.Error("EvtReadNew should be set yet")
- }
+ eb.WaitFor(EvtReadFin)
// Wait should return immediately
eb.Wait(func(events *util.Events) {
- if _, found := (*events)[EvtReadNew]; !found {
- t.Errorf("%s", events)
- }
events.Clear()
})
@@ -42,8 +41,14 @@ func TestReadFromCommand(t *testing.T) {
t.Error("EvtReadNew should not be set yet")
}
+ // Make sure that event poller is finished
+ time.Sleep(readerPollIntervalMax)
+
+ // Restart event poller
+ reader.startEventPoller()
+
// Failing command
- reader.readFromCommand(`no-such-command`)
+ reader.fin(reader.readFromCommand(`no-such-command`))
strs = []string{}
if len(strs) > 0 {
t.Errorf("%s", strs)
@@ -51,6 +56,9 @@ func TestReadFromCommand(t *testing.T) {
// Check EventBox again
if eb.Peek(EvtReadNew) {
- t.Error("Command failed. EvtReadNew should be set")
+ t.Error("Command failed. EvtReadNew should not be set")
+ }
+ if !eb.Peek(EvtReadFin) {
+ t.Error("EvtReadFin should be set")
}
}