@@ -48,14 +48,6 @@ func TestTaskExecTUI_Integration(t *testing.T) {
4848 advanceClock := func (d time.Duration ) { now = now .Add (d ) }
4949
5050 buf := & ttyBuf {}
51- expectOutput := func (t * testing.T , buf * ttyBuf , want []string ) {
52- t .Helper ()
53-
54- have := buf .Lines ()
55- if ! cmp .Equal (want , have ) {
56- t .Fatalf ("wrong output:\n %s" , cmp .Diff (want , have ))
57- }
58- }
5951
6052 out := output .NewOutput (buf , output.OutputOpts {
6153 ForceTTY : true ,
@@ -205,6 +197,70 @@ func TestTaskExecTUI_Integration(t *testing.T) {
205197 })
206198}
207199
200+ func TestProgressUpdateAfterComplete (t * testing.T ) {
201+ if runtime .GOOS == "windows" {
202+ t .Skip ("Something emits different escape codes on windows." )
203+ }
204+
205+ buf := & ttyBuf {}
206+
207+ now := time .Now ()
208+ clock := func () time.Time { return now .UTC ().Truncate (time .Millisecond ) }
209+
210+ out := output .NewOutput (buf , output.OutputOpts {
211+ ForceTTY : true ,
212+ ForceColor : true ,
213+ ForceHeight : 25 ,
214+ ForceWidth : 80 ,
215+ Verbose : true ,
216+ })
217+
218+ tasks := []* executor.Task {
219+ {Repository : & graphql.Repository {Name : "github.com/sourcegraph/sourcegraph" }},
220+ {Repository : & graphql.Repository {Name : "github.com/sourcegraph/src-cli" }},
221+ }
222+
223+ printer := newTaskExecTUI (out , true , 2 )
224+ printer .forceNoSpinner = true
225+ printer .clock = clock
226+
227+ // Setup internal state.
228+ printer .Start (tasks )
229+
230+ // Start the tasks.
231+ printer .TaskStarted (tasks [0 ])
232+ printer .TaskStarted (tasks [1 ])
233+
234+ // Update the tasks into a useful state.
235+ printer .TaskCurrentlyExecuting (tasks [0 ], "echo Hello World > README.md" )
236+ printer .TaskCurrentlyExecuting (tasks [1 ], "Downloading archive" )
237+
238+ expectOutput (t , buf , []string {
239+ "⠋ Executing... (0/2, 0 errored) " ,
240+ "│ " ,
241+ "├── github.com/sourcegraph/sourcegraph echo Hello World > README.md 0s" ,
242+ "└── github.com/sourcegraph/src-cli Downloading archive 0s" ,
243+ "" ,
244+ })
245+
246+ // Now mark the progress as complete.
247+ printer .progress .Complete ()
248+
249+ // Now send another update. This would panic before the relevant fix was
250+ // merged in #666.
251+ printer .TaskCurrentlyExecuting (tasks [0 ], "exit 42" )
252+
253+ // The actual output is slightly less important at this point, but let's
254+ // check it anyway.
255+ expectOutput (t , buf , []string {
256+ "✅ Executing... (0/2, 0 errored) ██████████████████████████████████████████████" ,
257+ "│ " ,
258+ "├── github.com/sourcegraph/sourcegraph exit 42 0s" ,
259+ "└── github.com/sourcegraph/src-cli Downloading archive 0s" ,
260+ "" ,
261+ })
262+ }
263+
208264type ttyBuf struct {
209265 lines [][]byte
210266
@@ -322,3 +378,12 @@ func (t *ttyBuf) Lines() []string {
322378func isDigit (ch byte ) bool {
323379 return '0' <= ch && ch <= '9'
324380}
381+
382+ func expectOutput (t * testing.T , buf * ttyBuf , want []string ) {
383+ t .Helper ()
384+
385+ have := buf .Lines ()
386+ if ! cmp .Equal (want , have ) {
387+ t .Fatalf ("wrong output:\n %s" , cmp .Diff (want , have ))
388+ }
389+ }
0 commit comments