Skip to content

Commit cf95bd7

Browse files
authored
✨ Error upkeep ✨ (#2177)
Using chores prompt, followed by a couple of human tweaks
1 parent fa29578 commit cf95bd7

25 files changed

+157
-43
lines changed

R/expect-comparison.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ expect_compare_ <- function(
3939

4040
cmp <- op(act$val, exp$val)
4141
if (length(cmp) != 1 || !is.logical(cmp)) {
42-
abort("Result of comparison must be a single logical value")
42+
abort(
43+
"Result of comparison must be a single logical value",
44+
call = trace_env
45+
)
4346
}
4447
if (!isTRUE(cmp)) {
4548
digits <- max(

R/skip.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ package_version <- function(x) {
138138
#' should only be run on R versions 4.1.0 and later.
139139
#' @rdname skip
140140
skip_unless_r <- function(spec) {
141+
check_string(spec)
142+
141143
parts <- unlist(strsplit(spec, " ", fixed = TRUE))
142144
if (length(parts) != 2L) {
143145
cli::cli_abort(
144-
"{.arg spec} should be a comparison like '>=' and an R version separated by a space."
146+
"{.arg spec} must be an valid version specification, like {.str >= 4.0.0}, not {.str {spec}}."
145147
)
146148
}
147149
comparator <- match.fun(parts[1L])

tests/testthat/_snaps/examples.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# test_examples fails if no examples
2+
3+
Code
4+
test_examples("asdf")
5+
Condition
6+
Error:
7+
! Could not find examples
8+

tests/testthat/_snaps/expect-comparison.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@
1818
`x` is not strictly less than 0.001.
1919
100.000 - 0.001 = 99.999 >= 0
2020

21+
# comparison must yield a single logical
22+
23+
Code
24+
expect_lt(1:10, 5)
25+
Condition
26+
Error in `expect_lt()`:
27+
! Result of comparison must be a single logical value
28+

tests/testthat/_snaps/expect-setequal.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# warns if both inputs are named
2+
3+
Code
4+
expect_setequal(c(a = 1), c(b = 1))
5+
Condition
6+
Warning:
7+
expect_setequal() ignores names
8+
19
# checks inputs
210

311
Code

tests/testthat/_snaps/reporter-stop.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@
4848

4949

5050

51+
# stop if needed errors when needed
52+
53+
Code
54+
r$stop_if_needed()
55+
Condition
56+
Error:
57+
! Test failed
58+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# useful error message if can't find reporter
2+
3+
Code
4+
find_reporter(c("summary", "blah"))
5+
Condition
6+
Error:
7+
! Can not find test reporter blah
8+

tests/testthat/_snaps/skip.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878

7979
Reason: On Windows i386
8080

81+
# skip_unless_r works as expected
82+
83+
Code
84+
skip_unless_r("idfjdij")
85+
Condition
86+
Error in `skip_unless_r()`:
87+
! `spec` must be an valid version specification, like ">= 4.0.0", not "idfjdij".
88+
8189
# skip_unless_r gives the expected output
8290

8391
Reason: Current R version (4.5.0) does not satisfy requirement (>= 999.999.999)

tests/testthat/_snaps/snapshot-file.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# warns on first creation
2+
3+
Code
4+
out <- snapshot_file_equal(tempdir(), "test.txt", NULL, path)
5+
Condition
6+
Warning:
7+
Adding new file snapshot: 'tests/testthat/_snaps/test.txt'
8+
9+
---
10+
11+
Code
12+
expect_true(snapshot_file_equal(tempdir(), "test.txt", NULL, "doesnt-exist.txt"))
13+
Condition
14+
Error in `snapshot_file_equal()`:
15+
! `doesnt-exist.txt` not found
16+
117
# snapshot_hint output differs in R CMD check
218

319
Code

tests/testthat/_snaps/test-compiled-code.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# get_routine() fails when no routine exists
2+
3+
Code
4+
get_routine("utils", "no_such_routine")
5+
Condition
6+
Error:
7+
! failed to locate routine 'no_such_routine' in package 'utils'
8+
19
# validates inputs
210

311
Code

0 commit comments

Comments
 (0)