Michael
Michael

Reputation: 1381

testthat package 'label' parameter

I included a simple example of a test using the R package testthat,

testthat::expect_equal(1,0, label = 'First')

Error: First not equal to 0.
1/1 mismatches
[1] 1 - 0 == 1

The label parameter replaces '1' by a word to give a more helpful error message. Now I'm interested in replacing the '0' as well. Such that we get something like

Error: First not equal to Second.

I've tried this

testthat::expect_equal(1,0, label = c('First', 'Second'))

Error in stop(exp) : bad error message

However this does not work as you may see. I read the vignette on the package, but there's not a lot of info on this parameter.

Upvotes: 1

Views: 329

Answers (2)

akrun
akrun

Reputation: 887213

We can use

testthat::expect_equal(1,0, label = 'First', expected.label = 'Second')

Error: First not equal to Second. 1/1 mismatches [1] 1 - 0 == 1

Upvotes: 4

Michael
Michael

Reputation: 1381

It turned out to be quite simple. The 'expected label' parameter is used for this.

Upvotes: 0

Related Questions