Skip to content

Add a context= or info= parameter to test() for looped/functional tests #7119

@MichaelChirico

Description

@MichaelChirico

Whenever we need to loop test(), the error becomes hard to determine from the failure itself:

for (ii in 0:4 / 5) test(1 + ii, ii < 0.5)
# Test 1.6 ran without errors but failed check that x equals y:
# > x = ii < 0.5 
# First 1 of 1 (type 'logical'): 
# [1] FALSE
# > y = TRUE 
# First 1 of 1 (type 'logical'): 
# [1] TRUE
# 1 element mismatch
# Test 1.8 ran without errors but failed check that x equals y:
# > x = ii < 0.5 
# First 1 of 1 (type 'logical'): 
# [1] FALSE
# > y = TRUE 
# First 1 of 1 (type 'logical'): 
# [1] TRUE
# 1 element mismatch

It would be a lot better to be able to insert some string into the test() call to capture the context of the loop, e.g.

for (ii in 0:4 / 5) test(1 + ii, ii < 0.5, context=sprintf("ii=%.1f", ii))

Which could then be read directly off of the error.

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