reader_test.go
This file
Path
src/reader_test.go
63 lines · 1.3 KiB · Go
Last changed by
Merge branch 'devel'Junegunn Choibefore adoptionb471042
History of this fileTake it
1package fzf23import (4 "testing"5 "time"67 "github.com/junegunn/fzf/src/util"8)910func TestReadFromCommand(t *testing.T) {11 strs := []string{}12 eb := util.NewEventBox()13 reader := NewReader(14 func(s []byte) bool { strs = append(strs, string(s)); return true },15 eb, false, true)1617 reader.startEventPoller()1819 // Check EventBox20 if eb.Peek(EvtReadNew) {21 t.Error("EvtReadNew should not be set yet")22 }2324 // Normal command25 reader.fin(reader.readFromCommand(nil, `echo abc && echo def`))26 if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {27 t.Errorf("%s", strs)28 }2930 // Check EventBox again31 eb.WaitFor(EvtReadFin)3233 // Wait should return immediately34 eb.Wait(func(events *util.Events) {35 events.Clear()36 })3738 // EventBox is cleared39 if eb.Peek(EvtReadNew) {40 t.Error("EvtReadNew should not be set yet")41 }4243 // Make sure that event poller is finished44 time.Sleep(readerPollIntervalMax)4546 // Restart event poller47 reader.startEventPoller()4849 // Failing command50 reader.fin(reader.readFromCommand(nil, `no-such-command`))51 strs = []string{}52 if len(strs) > 0 {53 t.Errorf("%s", strs)54 }5556 // Check EventBox again57 if eb.Peek(EvtReadNew) {58 t.Error("Command failed. EvtReadNew should not be set")59 }60 if !eb.Peek(EvtReadFin) {61 t.Error("EvtReadFin should be set")62 }63}