Skip to content

Commit 850faa3

Browse files
committed
Improve message; add test
1 parent d42608b commit 850faa3

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

R/parallel.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ test_files_parallel <- function(
4646
# TODO: support timeouts. 20-30s for each file by default?
4747

4848
num_workers <- min(default_num_cpus(), length(test_paths))
49-
cli::cli_inform(
50-
"Starting {num_workers} test process{?es}."
51-
)
49+
cli::cli_inform("Starting {num_workers} test process{?es}.")
5250

5351
# Set up work queue ------------------------------------------
5452
queue <- NULL
@@ -107,7 +105,10 @@ default_num_cpus <- function() {
107105
if (!is.null(ncpus)) {
108106
ncpus <- suppressWarnings(as.integer(ncpus))
109107
if (is.na(ncpus)) {
110-
cli::cli_abort("{.fn getOption}({.arg Ncpus}) must be an integer.")
108+
cli::cli_abort(
109+
"{.code getOption('Ncpus')} must be an integer.",
110+
call = NULL
111+
)
111112
}
112113
return(ncpus)
113114
}

tests/testthat/_snaps/parallel.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# good error if bad option
2+
3+
Code
4+
default_num_cpus()
5+
Condition
6+
Error:
7+
! `getOption('Ncpus')` must be an integer.
8+

tests/testthat/test-parallel.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ test_that("detect number of cpus to use", {
2020
expect_equal(default_num_cpus(), 13L)
2121
})
2222

23+
test_that("good error if bad option", {
24+
withr::local_options(Ncpus = "bad")
25+
expect_snapshot(default_num_cpus(), error = TRUE)
26+
})
27+
2328
test_that("ok", {
2429
withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE"))
2530
# we cannot run these with the silent reporter, because it is not

0 commit comments

Comments
 (0)