(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func TestNewCmdTaskInstantStop(t *testing.T) { |
| 23 | writer := bytes.NewBuffer(nil) |
| 24 | beforeStart, getBeforeStartCallCount := getCounter() |
| 25 | refreshView, getRefreshViewCallCount := getCounter() |
| 26 | onEndOfInput, getOnEndOfInputCallCount := getCounter() |
| 27 | onNewKey, getOnNewKeyCallCount := getCounter() |
| 28 | onDone, getOnDoneCallCount := getCounter() |
| 29 | task := gocui.NewFakeTask() |
| 30 | newTask := func() gocui.Task { |
| 31 | return task |
| 32 | } |
| 33 | |
| 34 | manager := NewViewBufferManager( |
| 35 | utils.NewDummyLog(), |
| 36 | writer, |
| 37 | beforeStart, |
| 38 | refreshView, |
| 39 | onEndOfInput, |
| 40 | onNewKey, |
| 41 | newTask, |
| 42 | ) |
| 43 | |
| 44 | stop := make(chan struct{}) |
| 45 | reader := bytes.NewBufferString("test") |
| 46 | start := func() (*exec.Cmd, io.Reader) { |
| 47 | // not actually starting this because it's not necessary |
| 48 | cmd := exec.Command("blah") |
| 49 | |
| 50 | close(stop) |
| 51 | |
| 52 | return cmd, reader |
| 53 | } |
| 54 | |
| 55 | fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone) |
| 56 | |
| 57 | _ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }}) |
| 58 | |
| 59 | callCountExpectations := []struct { |
| 60 | expected int |
| 61 | actual int |
| 62 | name string |
| 63 | }{ |
| 64 | {0, getBeforeStartCallCount(), "beforeStart"}, |
| 65 | {1, getRefreshViewCallCount(), "refreshView"}, |
| 66 | {0, getOnEndOfInputCallCount(), "onEndOfInput"}, |
| 67 | {0, getOnNewKeyCallCount(), "onNewKey"}, |
| 68 | {1, getOnDoneCallCount(), "onDone"}, |
| 69 | } |
| 70 | for _, expectation := range callCountExpectations { |
| 71 | if expectation.actual != expectation.expected { |
| 72 | t.Errorf("expected %s to be called %d times, got %d", expectation.name, expectation.expected, expectation.actual) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if task.Status() != gocui.TaskStatusDone { |
| 77 | t.Errorf("expected task status to be 'done', got '%s'", task.FormatStatus()) |
| 78 | } |
| 79 |
nothing calls this directly
no test coverage detected