Skip to content

cryptic error when expect_equal(x, y, tolerance = -Inf) #2344

Description

@she3o

Hi,

This is not really a critical bug...

I was writing tests and hoped expect_equal(actual, expected, tolerance = -Inf) would use the "lowest possible tolerance". I did not even expect it to work. I am reporting because of the cryptic error message.

MRE:

# Success
test_that("1 = 1 with minimum tolerance", {
  expect_equal(1,1,tolerance = -Inf)
})

# Cryptic Error message
test_that("1 = 1.1 with minimum tolerance", {
  expect_equal(1,1.1,tolerance = -Inf) # does not work
})

# Success
test_that("1 = 1.1 with maximum tolerance", {
  expect_equal(1,1.1,tolerance = Inf)
})

error message

── Warning: 1 = 1.1 with minimum tolerance ───────────────────────────────────
NaNs produced
Backtrace:
    ▆
 1. └─testthat::expect_equal(1, 1.1, tolerance = -Inf)
 2.   └─testthat:::expect_waldo_equal_(msg, act, exp, info, ..., tolerance = tolerance)
 3.     └─testthat:::waldo_compare(...)
 4.       └─waldo::compare(x, y, ..., x_arg = x_arg, y_arg = y_arg)
 5.         └─waldo:::compare_structure(x, y, paths = c(x_arg, y_arg), opts = opts)
 6.           └─waldo:::compare_vector(x, y, paths = paths, opts = opts)
 7.             └─waldo:::compare_numeric(...)
 8.               └─waldo:::min_digits(x, y, tolerance)
 9.                 └─waldo:::digits(tolerance)

> packageVersion("testthat")
[1] ‘3.3.2> packageVersion("waldo")
[1] ‘0.6.2> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          6.1                         
year           2026                        
month          06                          
day            24                          
svn rev        90187                       
language       R                           
version.string R version 4.6.1 (2026-06-24)
nickname       Happy Hop                   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions