Skip to content

Failing test on non x86 architectures #103

Description

@nileshpatra

Hi @schollz

Thanks for your work on progressbar :)
However, while running tests on !x86 architectures, one of the test fails -- in particular this one:

=== RUN   ExampleOptionSetRenderBlankState
--- FAIL: ExampleOptionSetRenderBlankState (0.00s)
got:
0% |          |  [0s:-1s]
want:
0% |          |  [0s:0s]

On investigating further, it seems that the value of rightBrac is turning out to be negative. On further investigation, it is found that the value of the averageRate variable is "0" for this particular test, and hence a division by 0 is happening there, which results in a +Inf, now the rest of the operations convert this into 0s on x86 and -1 on rest arches.

Here's a sample code for instance:

package main

import
	(
		"time"
		"fmt"
	);

func main() {
	var rate float64 = 0
	max := 10
	min := 0
	res:= (time.Duration((1 / rate)*(float64(max) - float64(min))) * time.Second).String()
	fmt.Println(res)
}

Output on x86: 0s
Output on arm64/other arches: -1s

For now, I've applied this patch to force a 0s value if rightBrac is 0s:

--- a/progressbar.go
+++ b/progressbar.go
@@ -730,6 +730,11 @@
 	if c.predictTime {
 		leftBrac = (time.Duration(time.Since(s.startTime).Seconds()) * time.Second).String()
 		rightBrac = (time.Duration((1/averageRate)*(float64(c.max)-float64(s.currentNum))) * time.Second).String()
+		zerosec, _ := time.ParseDuration("0s")
+		rightsec, _ := time.ParseDuration(rightBrac)
+		if rightsec.Seconds() < zerosec.Seconds() {
+			rightBrac = "0s"
+		}
 	}
 
 	if c.fullWidth && !c.ignoreLength {

But I admit this might not be the best way to get around it. Please consider fixing this

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions