Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uptestthat::expect_equal() returns spurious pass result when comparing Message objects #53
Comments
|
Interesting. I will note that our use of To be precise, you are suggesting a one-liner addition to |
|
Odd. R> library(RUnit)
R> checkEquals(p, p2)
[1] TRUE
R>but that uses a direct comparison. If we are explicit this works R> checkTrue( FALSE == all.equal(p, p2) )
[1] TRUE
R> |
|
I've created #54 to fix this. Here's the result from the same reprex after the fix. library(RProtoBuf)
library(testthat)
# Create two obviously different messages from the same descriptor
p <- new(tutorial.Person, name = "John", id = 1)
p2 <- new(tutorial.Person, name = "Doe", id = 2)
# Directly calling all.equal() returns the correct result
all.equal(p, p2)
#> [1] FALSE
# Calling all.equal.default() returns the wrong result
all.equal.default(p, p2)
#> [1] TRUE
# testthat::expect_equal() now correctly fails the test
expect_equal(p, p2)
#> Error: `p` not equal to `p2`.
#> FALSECreated on 2018-11-26 by the reprex package (v0.2.1) |
|
Added an RUnit test in the reprex. library(RProtoBuf)
library(testthat)
library(RUnit)
# Create two obviously different messages from the same descriptor
p <- new(tutorial.Person, name = "John", id = 1)
p2 <- new(tutorial.Person, name = "Doe", id = 2)
# Directly calling all.equal() returns the correct result
all.equal(p, p2)
#> [1] FALSE
# Calling all.equal.default() returns the wrong result
all.equal.default(p, p2)
#> [1] TRUE
# testthat::expect_equal() now correctly fails the test
expect_equal(p, p2)
#> Error: `p` not equal to `p2`.
#> FALSE
# RUnit::checkEquals now returns the correct result too
checkEquals(p, p2)
#> Error in checkEquals(p, p2): FALSECreated on 2018-11-26 by the reprex package (v0.2.1) |
|
I think the root cause of this lies in
|
|
Very helpful follow-ups, thanks. In all those of using Thanks for all that, will follow-up. |
|
Added ChangeLog and NEWS in 6298c7c -- thanks again for the PR. |
testthat::expect_equalpasses even when two Message objects have totally different content (see reprex below).expect_equal()calls the genericall.equal()to compare two objects. Instead of dispatching on the S4 method defined in RProtoBuf,all.equal()(when called fromtestthat) actually dispatch to the defaultall.equal.default()which in turn usesattr.all.equal()to only compare the attributes of the two objects.This is likely because RProtoBuf doesn't define an S3method for
all.equalas the manual suggests. A simple addition to theNAMESPACEfile should fix the issue. Happy to send in a PR on this if necessary.Created on 2018-11-26 by the reprex package (v0.2.1)