Skip to content

Diff is reported as 0% #503

@sonatard

Description

@sonatard

Coverage is decreasing, but the difference is 0%, so the test passes.

coverage:
  if: true
  acceptable: diff >= 0%
codeToTestRatio:
  if: false
testExecutionTime:
  if: false
diff:
  datastores:
    - artifact://${GITHUB_REPOSITORY}
comment:
  if: is_pull_request
summary:
  if: true
report:
  if: is_default_branch
  datastores:
    - artifact://${GITHUB_REPOSITORY}
Image

I think using big.Rat instead of float64 for current and prev will likely resolve the issue.

func coverageAcceptable(current, prev float64, cond string) error {

I haven't been able to conduct detailed tests, but I think it would be something like this.

-func coverageAcceptable(current, prev float64, cond string) error {
+func coverageAcceptable(current, prev *big.Rat, cond string) error {
        if cond == "" {
                return nil
        }
@@ -258,10 +259,11 @@ func CoverageAcceptable(current, prev float64, cond string) error {
                cond = fmt.Sprintf("current %s", cond)
        }

+       diff, _ := current.Sub(current, prev).Float64()
        variables := map[string]any{
                "current": current,
                "prev":    prev,
-               "diff":    current - prev,
+               "diff":    diff,
        }
        fmt.Printf("%v\n", variables["diff"])
        ok, err := expr.Eval(fmt.Sprintf("(%s) == true", cond), variables)
@@ -274,7 +276,8 @@ func CoverageAcceptable(current, prev float64, cond string) error {
                return fmt.Errorf("invalid condition `%s`", cond)
        }
        if !tf {
-               return fmt.Errorf("code coverage is %.1f%%. the condition in the `coverage.acceptable:` section is not met (`%s`)", floor1(current), org)
+               cf, _ := current.Float64()
+               return fmt.Errorf("code coverage is %.1f%%. the condition in the `coverage.acceptable:` section is not met (`%s`)", cf, org)
        }
        return nil
 }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions