Skip to content

Commit

Permalink
Merge pull request #153 from ssi-dk/repo-sync/AEF-DDF/default
Browse files Browse the repository at this point in the history
chore: synced file(s) with ssi-dk/AEF-DDF
  • Loading branch information
RasmusSkytte authored Oct 4, 2024
2 parents fcccd53 + e8239c9 commit f27cc9c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/testthat/helper-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,30 @@ get_test_conns <- function() {

return(test_conns)
}


#' Parse checkmate assertions for testthat compatibility
#' @description
#' The error messages generated by `checkmate` are formatted to look nicely in the console by the
#' addition of `*` and `\n` characters.
#'
#' This means that checking these errors with `testthat::expect_error()` will often fail or will be harder to read
#' in the test since we need to manually insert `*` and `\n` to the comparison pattern to match the error message.
#'
#' This helper function intercepts the `checkmate` error message and removes the `*` and `\n` characters to allow for
#' human readable error checking.
#' @return
#' The checkmate error without `*` and `\n` characters.
#' @noRd
checkmate_err_msg <- function(expr) {
tryCatch(
expr,
error = \(e) {
e$message |>
stringr::str_remove_all(stringr::fixed("\n *")) |>
stringr::str_remove_all(stringr::fixed("* ")) |>
simpleError(message = _) |>
stop()
}
)
}

0 comments on commit f27cc9c

Please sign in to comment.