reader_test.go
This file
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–68why, one step back1package 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 exec := util.NewExecutor("")14 reader := NewReader(15 func(s []byte) bool { strs = append(strs, string(s)); return true },16 eb, exec, false, true)1718 reader.startEventPoller()1920 // Check EventBox21 if eb.Peek(EvtReadNew) {22 t.Error("EvtReadNew should not be set yet")23 }2425 // Normal command26 counter := 027 ready := func() {28 counter++29 }30 reader.fin(reader.readFromCommand(`echo abc&&echo def`, nil, ready))31 if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" || counter != 1 {32 t.Errorf("%s", strs)33 }3435 // Check EventBox again36 eb.WaitFor(EvtReadFin)3738 // Wait should return immediately39 eb.Wait(func(events *util.Events) {40 events.Clear()41 })4243 // EventBox is cleared44 if eb.Peek(EvtReadNew) {45 t.Error("EvtReadNew should not be set yet")46 }4748 // Make sure that event poller is finished49 time.Sleep(readerPollIntervalMax)5051 // Restart event poller52 reader.startEventPoller()5354 // Failing command55 reader.fin(reader.readFromCommand(`no-such-command`, nil, ready))56 strs = []string{}57 if len(strs) > 0 || counter != 2 {58 t.Errorf("%s", strs)59 }6061 // Check EventBox again62 if eb.Peek(EvtReadNew) {63 t.Error("Command failed. EvtReadNew should not be set")64 }65 if !eb.Peek(EvtReadFin) {66 t.Error("EvtReadFin should be set")67 }68}