reader_test.go
This file
Path
src/reader_test.go
64 lines · 1.3 KiB · Go
Last changed by
Update FZF_DEFAULT_COMMANDJunegunn Choibefore adoptionee40212
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 := Reader{14 pusher: func(s []byte) bool { strs = append(strs, string(s)); return true },15 eventBox: eb,16 event: int32(EvtReady)}1718 reader.startEventPoller()1920 // Check EventBox21 if eb.Peek(EvtReadNew) {22 t.Error("EvtReadNew should not be set yet")23 }2425 // Normal command26 reader.fin(reader.readFromCommand("sh", `echo abc && echo def`))27 if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {28 t.Errorf("%s", strs)29 }3031 // Check EventBox again32 eb.WaitFor(EvtReadFin)3334 // Wait should return immediately35 eb.Wait(func(events *util.Events) {36 events.Clear()37 })3839 // EventBox is cleared40 if eb.Peek(EvtReadNew) {41 t.Error("EvtReadNew should not be set yet")42 }4344 // Make sure that event poller is finished45 time.Sleep(readerPollIntervalMax)4647 // Restart event poller48 reader.startEventPoller()4950 // Failing command51 reader.fin(reader.readFromCommand("sh", `no-such-command`))52 strs = []string{}53 if len(strs) > 0 {54 t.Errorf("%s", strs)55 }5657 // Check EventBox again58 if eb.Peek(EvtReadNew) {59 t.Error("Command failed. EvtReadNew should not be set")60 }61 if !eb.Peek(EvtReadFin) {62 t.Error("EvtReadFin should be set")63 }64}