Skip to content

Truncate the printed output when expect_equal_to_reference() fails #538

Closed

Description

@jennybc

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

Activity

  1. hadley commented on Dec 15, 2016

    @hadley
    Member

    Could you please provide a small reprex?

  2. added
    reprexneeds a minimal reproducible example
    on Dec 15, 2016
  3. jennybc commented on Dec 15, 2016

    @jennybc
    MemberAuthor
    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.

  4. added
    featurea feature request or enhancement
    and removed
    reprexneeds a minimal reproducible example
    on Dec 15, 2016
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions