Skip to content
Myr

reader_test.go

This file

Path

src/reader_test.go

68 lines · 1.4 KiB · Go

Last changed by

Remove possible races (#4070)Junegunn Choibefore adoption19495eb

History of this file

Take it

The walk stopped after 200 commits: lines older than 368294e point at it.

Reduce flickering of the list when the list is truncated by --tailJunegunn Choibefore adoption368294e

lines 1–25why, one step back
1package fzf
23import (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 command

Remove possible races (#4070)Junegunn Choibefore adoption19495eb

lines 26–31why, one step back
26 counter := 0
27 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 {

Reduce flickering of the list when the list is truncated by --tailJunegunn Choibefore adoption368294e

lines 32–54why, one step back
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 command

Remove possible races (#4070)Junegunn Choibefore adoption19495eb

line 55why, one step back
55 reader.fin(reader.readFromCommand(`no-such-command`, nil, ready))

Reduce flickering of the list when the list is truncated by --tailJunegunn Choibefore adoption368294e

line 56why, one step back
56 strs = []string{}

Remove possible races (#4070)Junegunn Choibefore adoption19495eb

line 57why, one step back
57 if len(strs) > 0 || counter != 2 {

Reduce flickering of the list when the list is truncated by --tailJunegunn Choibefore adoption368294e

lines 58–68why, one step back
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}