Skip to content

Improve failure message for comparison expectations #2170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 5, 2025
Merged

Conversation

hadley
Copy link
Member

@hadley hadley commented Aug 4, 2025

Using the digits calculation from waldo, displaying the actual calculation, comparison, and renaming "more" to "greater"

Fixes #2006

@MichaelChirico could you please take a look? This doesn't need to be perfect, but is hopefully better than the current display.

hadley added 2 commits August 4, 2025 16:31
Using the digits calculation from waldo, displaying the actual calculation, comparison, and renaming "more" to "greater"

Fixes #2006
)[[operator]]

negated_op <- switch(operator, "<" = ">", "<=" = ">=", ">" = "<", ">=" = "<=")
Copy link
Contributor

@MichaelChirico MichaelChirico Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these wrong? e.g. I think we'll get

expect_snapshot_failure(expect_gt(x, 1.0 * x))
    `x` is not strictly greater than 1.0 * x.
    0.0000100 - 0.0000110 = 0 < 0

The negated open interval is a closed interval, and vice versa.

https://github.com/r-lib/lintr/blob/84d3f8c5f4b3576defe880872ec413df8986ef9c/R/comparison_negation_linter.R#L40

(even if I'm reading it wrong we'll still want a test of the edge case)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also that revealed a bug when the number of digits in the difference is much smaller than the values.

Copy link
Contributor

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, output LGTM! It might be helpful to add another example where the values are totally different just to get a glimpse of what that will look like.

@hadley hadley merged commit a7983dd into main Aug 5, 2025
10 of 11 checks passed
@hadley hadley deleted the comparison-display branch August 5, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expect_comparison could use waldo to determine digits in the failure case?
2 participants