Skip to content

Commit 63dce2d

Browse files
authored
Allow deprecation warnings to bubble up (#1699)
Fixes #1680
1 parent f3bf982 commit 63dce2d

16 files changed

+291
-64
lines changed

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# testthat (development version)
22

3+
* Deprecation warnings are no longer captured by `expect_warning(code, NA)`,
4+
`expect_no_warning(code)`, or `expect_silent(code)`. This ensures that they
5+
bubble up to the top level so that you can address them (#1680). If you want
6+
to assert that code does not throw a deprecation warning, use
7+
`expect_no_condition(code(), class = "lifecycle_warning_deprecation")`.
8+
39
* New experimental `expect_no_error()`, `expect_no_warning()`,
410
`expect_no_message()`, and `expect_no_condition()` for asserting
511
the code runs without an error, warning, message, or condition (#1679).

R/deprec-condition.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,16 @@ capture_messages <- function(code) {
9696

9797
#' @export
9898
#' @rdname capture_condition
99-
capture_warnings <- function(code) {
99+
capture_warnings <- function(code, ignore_deprecation = FALSE) {
100100
out <- Stack$new()
101101

102102
withCallingHandlers(
103103
code,
104104
warning = function(condition) {
105+
if (ignore_deprecation && is_deprecation(condition)) {
106+
return()
107+
}
108+
105109
out$push(condition)
106110
maybe_restart("muffleWarning")
107111
}

R/evaluate-promise.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
evaluate_promise <- function(code, print = FALSE) {
1919
warnings <- Stack$new()
2020
handle_warning <- function(condition) {
21-
warnings$push(condition)
22-
maybe_restart("muffleWarning")
21+
if (!is_deprecation(condition)) {
22+
warnings$push(condition)
23+
maybe_restart("muffleWarning")
24+
}
2325
}
2426

2527
messages <- Stack$new()

R/expect-condition.R

+13-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ expect_warning <- function(object,
167167
trace_env = caller_env()
168168
)
169169
} else {
170-
act <- quasi_capture(enquo(object), label, capture_warnings)
170+
act <- quasi_capture(enquo(object), label, capture_warnings, ignore_deprecation = identical(regexp, NA))
171171
msg <- compare_messages(
172172
act$cap, act$lab, regexp = regexp, all = all, ...,
173173
cond_type = "warnings"
@@ -229,6 +229,7 @@ expect_condition <- function(object,
229229
trace_env = caller_env()
230230
)
231231
} else {
232+
232233
act <- quasi_capture(enquo(object), label, capture_condition, entrace = TRUE)
233234
msg <- compare_condition_2e(
234235
act$cap,
@@ -260,7 +261,8 @@ expect_condition_matching <- function(base_class,
260261
class %||% base_class,
261262
regexp,
262263
...,
263-
inherit = inherit
264+
inherit = inherit,
265+
ignore_deprecation = base_class == "warning" && identical(regexp, NA)
264266
)
265267

266268
act <- quasi_capture(
@@ -284,7 +286,7 @@ expect_condition_matching <- function(base_class,
284286

285287
# -------------------------------------------------------------------------
286288

287-
cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE) {
289+
cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE, ignore_deprecation = FALSE) {
288290
if (!is_string(class)) {
289291
abort("`class` must be a single string")
290292
}
@@ -297,6 +299,10 @@ cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE) {
297299
cnd$parent <- NULL
298300
}
299301

302+
if (ignore_deprecation && is_deprecation(cnd)) {
303+
return(FALSE)
304+
}
305+
300306
if (is.null(pattern) || isNA(pattern)) {
301307
cnd_inherits(cnd, class)
302308
} else {
@@ -305,6 +311,10 @@ cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE) {
305311
}
306312
}
307313

314+
is_deprecation <- function(x) {
315+
inherits(x, "lifecycle_warning_deprecated")
316+
}
317+
308318
cnd_inherits <- function(cnd, class) {
309319
cnd_some(cnd, ~ inherits(.x, class))
310320
}

R/expect-no-condition.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ expect_no_ <- function(base_class,
8989
class = NULL,
9090
error_call = caller_env()) {
9191

92-
matcher <- cnd_matcher(class %||% base_class, regexp)
92+
matcher <- cnd_matcher(
93+
class %||% base_class,
94+
pattern = regexp,
95+
ignore_deprecation = base_class == "warning" && is.null(regexp) && is.null(class)
96+
)
9397

9498
capture <- function(code) {
9599
try_fetch(

man/capture_condition.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

revdep/README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
|package |version |error |warning |note |
66
|:------------|:-------|:-----|:-------|:----|
77
|Boom |0.9.10 |1 | | |
8-
|bsts |? | | | |
8+
|CausalImpact |? | | | |
99
|NA |? | | | |
1010
|ctsem |3.7.1 |1 | | |
1111
|NA |? | | | |
@@ -34,12 +34,15 @@
3434
|vivid |? | | | |
3535
|NA |? | | | |
3636

37-
## New problems (4)
37+
## New problems (7)
3838

39-
|package |version |error |warning |note |
40-
|:--------|:-------|:------|:-------|:----|
39+
|package |version |error |warning |note |
40+
|:----------|:-------|:------|:-------|:----|
41+
|[batata](problems.md#batata)|0.2.1 |__+1__ | |1 |
4142
|[brew](problems.md#brew)|1.0-7 |__+1__ | | |
4243
|[freshr](problems.md#freshr)|1.0.1 |__+1__ | | |
43-
|[lightgbm](problems.md#lightgbm)|3.3.2 |__+1__ | |1 |
44+
|[log4r](problems.md#log4r)|0.4.2 |__+1__ | | |
45+
|[r2dii.plot](problems.md#r2diiplot)|0.3.0 |__+1__ | | |
46+
|[reprex](problems.md#reprex)|2.0.2 |__+1__ | | |
4447
|[WeMix](problems.md#wemix)|3.2.2 |__+1__ |1 | |
4548

revdep/cran.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
## revdepcheck results
22

3-
We checked 7102 reverse dependencies (7089 from CRAN + 13 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
3+
We checked 7109 reverse dependencies (7096 from CRAN + 13 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
44

5-
* We saw 4 new problems
5+
* We saw 7 new problems
66
* We failed to check 16 packages
77

88
Issues with CRAN packages are summarised below.
99

1010
### New problems
1111
(This reports the first line of each new failure)
1212

13+
* batata
14+
checking tests ... ERROR
15+
1316
* brew
1417
checking tests ... ERROR
1518

1619
* freshr
1720
checking tests ... ERROR
1821

19-
* lightgbm
22+
* log4r
23+
checking tests ... ERROR
24+
25+
* r2dii.plot
26+
checking tests ... ERROR
27+
28+
* reprex
2029
checking tests ... ERROR
2130

2231
* WeMix
@@ -25,7 +34,7 @@ Issues with CRAN packages are summarised below.
2534
### Failed to check
2635

2736
* Boom (NA)
28-
* bsts (NA)
37+
* CausalImpact (NA)
2938
* ctsem (NA)
3039
* elbird (NA)
3140
* ggPMX (NA)

revdep/failures.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ ERROR: compilation failed for package ‘Boom’
7676

7777

7878
```
79-
# bsts
79+
# CausalImpact
8080
8181
<details>
8282
83-
* Version: 0.9.8
83+
* Version: 1.2.7
8484
* GitHub: NA
85-
* Source code: https://github.com/cran/bsts
86-
* Date/Publication: 2022-05-30 07:00:12 UTC
87-
* Number of recursive dependencies: 37
85+
* Source code: https://github.com/cran/CausalImpact
86+
* Date/Publication: 2021-06-07 06:40:02 UTC
87+
* Number of recursive dependencies: 73
8888
89-
Run `cloud_details(, "bsts")` for more info
89+
Run `cloud_details(, "CausalImpact")` for more info
9090
9191
</details>
9292
@@ -95,17 +95,16 @@ Run `cloud_details(, "bsts")` for more info
9595
### Devel
9696
9797
```
98-
* using log directory ‘/tmp/workdir/bsts/new/bsts.Rcheck’
98+
* using log directory ‘/tmp/workdir/CausalImpact/new/CausalImpact.Rcheck’
9999
* using R version 4.1.1 (2021-08-10)
100100
* using platform: x86_64-pc-linux-gnu (64-bit)
101101
* using session charset: UTF-8
102102
* using option ‘--no-manual’
103-
* checking for file ‘bsts/DESCRIPTION’ ... OK
104-
* this is package ‘bsts’ version ‘0.9.8’
105-
* package encoding: UTF-8
103+
* checking for file ‘CausalImpact/DESCRIPTION’ ... OK
104+
* this is package ‘CausalImpact’ version ‘1.2.7’
106105
* checking package namespace information ... OK
107106
* checking package dependencies ... ERROR
108-
Packages required but not available: 'BoomSpikeSlab', 'Boom'
107+
Packages required but not available: 'bsts', 'Boom'
109108

110109
See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
111110
manual.
@@ -120,17 +119,16 @@ Status: 1 ERROR
120119
### CRAN
121120
122121
```
123-
* using log directory ‘/tmp/workdir/bsts/old/bsts.Rcheck’
122+
* using log directory ‘/tmp/workdir/CausalImpact/old/CausalImpact.Rcheck’
124123
* using R version 4.1.1 (2021-08-10)
125124
* using platform: x86_64-pc-linux-gnu (64-bit)
126125
* using session charset: UTF-8
127126
* using option ‘--no-manual’
128-
* checking for file ‘bsts/DESCRIPTION’ ... OK
129-
* this is package ‘bsts’ version ‘0.9.8’
130-
* package encoding: UTF-8
127+
* checking for file ‘CausalImpact/DESCRIPTION’ ... OK
128+
* this is package ‘CausalImpact’ version ‘1.2.7’
131129
* checking package namespace information ... OK
132130
* checking package dependencies ... ERROR
133-
Packages required but not available: 'BoomSpikeSlab', 'Boom'
131+
Packages required but not available: 'bsts', 'Boom'
134132

135133
See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
136134
manual.

0 commit comments

Comments
 (0)