Skip to content
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

Deprecated advice for expect_equivalent() is not equivalent #1946

Closed
jarad opened this issue Mar 27, 2024 · 2 comments
Closed

Deprecated advice for expect_equivalent() is not equivalent #1946

jarad opened this issue Mar 27, 2024 · 2 comments

Comments

@jarad
Copy link

jarad commented Mar 27, 2024

In testthat 3.1.10 and waldo 0.5.1, the helpfile for expect_equivalent() says that this function is deprecated and suggests you to use expect_equal(ignore_attr = TRUE) instead. Unfortunately, these two are apparently not equivalent.

a <- 1
names(a) <- "a"
expect_equivalent(a, unname(a))                     # passes
expect_equal(a, unname(a), ignore_attr = TRUE) # fails

In addition, in the helpfile for waldo::compare() under ignore_attr, it says "For backward compatibility with all.equal(), you can also use TRUE, to all ignore differences in all attributes. This is not generally recommended as it is a blunt tool that will ignore many important functional differences."

The expect_equivalent() function was useful and the suggested alternative does not work in the use-case I am interested in.

@hadley
Copy link
Member

hadley commented Apr 17, 2024

Minimal reprex:

library(testthat)
a <- 1
names(a) <- "a"
expect_equivalent(a, unname(a))
expect_equal(a, unname(a), ignore_attr = TRUE)
#> Error: `a` not equal to unname(a).
#> names for target but not for current

Created on 2024-04-17 with reprex v2.1.0

Hmmm, this is because waldo doesn't consider names to an attribute to be ignored. This needs to be documented better.

@hadley
Copy link
Member

hadley commented Nov 5, 2024

Looks like this has been fixed in waldo:

library(testthat)
expect_equal(1, c(a = 1), ignore_attr = TRUE)
#> Error: 1 not equal to c(a = 1).
#> names for current but not for target

Created on 2024-11-05 with reprex v2.1.0

@hadley hadley closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants