Skip to content

Commit

Permalink
progress: Render never started trackers properly
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBaulch committed Aug 26, 2023
1 parent 5a25275 commit 94f2cb5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 6 additions & 4 deletions progress/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,12 @@ func (p *Progress) renderTrackerStatsSpeedInternal(out *strings.Builder, speed s

func (p *Progress) renderTrackerStatsTime(outStats *strings.Builder, t *Tracker, hint renderHint) {
var td, tp time.Duration
if t.IsDone() {
td = t.timeStop.Sub(t.timeStart)
} else if !t.timeStart.IsZero() {
td = time.Since(t.timeStart)
if !t.timeStart.IsZero() {
if t.IsDone() {
td = t.timeStop.Sub(t.timeStart)
} else {
td = time.Since(t.timeStart)
}
}
if hint.isOverallTracker {
tp = p.style.Options.TimeOverallPrecision
Expand Down
28 changes: 28 additions & 0 deletions progress/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,34 @@ func TestProgress_generateTrackerStr_Indeterminate(t *testing.T) {
}
}

func TestProgress_RenderNeverStarted(t *testing.T) {
renderOutput := strings.Builder{}

pw := generateWriter()
pw.SetOutputWriter(&renderOutput)

tr := &Tracker{DeferStart: true}
pw.AppendTracker(tr)

go pw.Render()
time.Sleep(renderWaitTime)
tr.MarkAsDone()
pw.Stop()
time.Sleep(time.Second)

expectedOutPatterns := []*regexp.Regexp{
regexp.MustCompile(`\s*\.\.\. {2}\?\?\? {2}\[\.{23}] \[0 in 0s]`),
regexp.MustCompile(`\s*\.\.\. done! \[0 in 0s]`),
}
out := renderOutput.String()
for _, expectedOutPattern := range expectedOutPatterns {
if !expectedOutPattern.MatchString(out) {
assert.Fail(t, "Failed to find a pattern in the Output.", expectedOutPattern.String())
}
}
showOutputOnFailure(t, out)
}

func TestProgress_RenderNothing(t *testing.T) {
renderOutput := outputWriter{}

Expand Down

0 comments on commit 94f2cb5

Please sign in to comment.