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

Truncate the printed output when expect_equal_to_reference() fails #538

Closed
jennybc opened this issue Nov 2, 2016 · 2 comments
Closed

Truncate the printed output when expect_equal_to_reference() fails #538

jennybc opened this issue Nov 2, 2016 · 2 comments

Comments

@jennybc
Copy link
Member

@jennybc jennybc commented Nov 2, 2016

I used expect_equal_to_reference() for a deeply nested list. When this test fails, it prints >1K lines of this form:

Component X: Component Y: target is blah, current is yo
@hadley
Copy link
Member

@hadley hadley commented Dec 15, 2016

Could you please provide a small reprex?

@hadley hadley added the reprex label Dec 15, 2016
@jennybc
Copy link
Member Author

@jennybc jennybc commented Dec 15, 2016

library(testthat)
library(purrr)

x <- list(
  list(fruit = "apple", color = "red"),
  list(fruit = "grape", color = "green")
)

expect_equal_to_reference(x, "x.rds")

x <- x %>%
  map(function(x) {
    x$color <- sample(colors(), 1)
    x
  })
x
#> [[1]]
#> [[1]]$fruit
#> [1] "apple"
#> 
#> [[1]]$color
#> [1] "dodgerblue"
#> 
#> 
#> [[2]]
#> [[2]]$fruit
#> [1] "grape"
#> 
#> [[2]]$color
#> [1] "plum"

expect_equal_to_reference(x, "x.rds")
#> Error: `x` not equal to reference from `x.rds`.
#> Component 1: Component 2: 1 string mismatch
#> Component 2: Component 2: 1 string mismatch

I think you get one line of Component 2: Component 2: 1 string mismatch for every mismatch, no matter how many thousands there are.

My original context was roundtripping JSON: does the R object I get from httr::content() on a request match what I get after writing that list out to JSON and reading it back in. Apparently the answer is no and this is how I learned that. At very great length.

@hadley hadley closed this in bd683c8 Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants