Documentation for expect_error argument 'regexp' says it accepts a character vector but it does not

Open Beginner friendly
#2,351 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Active
Tech stack
r
Domain
testing

Research direction

Start with the documentation for testthat::expect_error() and reproduce the reported character-vector example in R. Check whether the documented vector behavior is intended; done means either the documentation accurately describes the accepted regexp input or the behavior and its tests support the documented vector form.

Written by the indexing model from the issue text.

Description

The documentation reads:

regexp
Regular expression to test against.

  • A character vector giving a regular expression that must match the error message.

Yetexpect_error(object = x, regexp = c('foo', 'bar')) does not work.

Repex:

f <- function(x){
  foo <- 'foo is not '
  stop(foo, x)
}

testthat::test_that('expect_error() can use a character vector for regexp',{
  expect_error(
    object = f('bar'),
    regexp = c('foo', 'bar')
  )
})

# test fails because of an error in expect_error():
# Error in `expect_error(object = f("bar"), regexp = c("foo", "bar"))`: `regexp` must be a single string, `NA`, or `NULL`, not a character vector.

Is it intended for expect_error() to work with a regexp vector of patterns or should one always use a single pattern?

Dominant language
R
Stars
939
Forks
346
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/testthat

All issues in r-lib/testthat

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.