Skip to content

Commit

Permalink
Allow deprecation warnings to bubble up (#1699)
Browse files Browse the repository at this point in the history
Fixes #1680
  • Loading branch information
hadley authored Sep 28, 2022
1 parent f3bf982 commit 63dce2d
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 64 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# testthat (development version)

* Deprecation warnings are no longer captured by `expect_warning(code, NA)`,
`expect_no_warning(code)`, or `expect_silent(code)`. This ensures that they
bubble up to the top level so that you can address them (#1680). If you want
to assert that code does not throw a deprecation warning, use
`expect_no_condition(code(), class = "lifecycle_warning_deprecation")`.

* New experimental `expect_no_error()`, `expect_no_warning()`,
`expect_no_message()`, and `expect_no_condition()` for asserting
the code runs without an error, warning, message, or condition (#1679).
Expand Down
6 changes: 5 additions & 1 deletion R/deprec-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ capture_messages <- function(code) {

#' @export
#' @rdname capture_condition
capture_warnings <- function(code) {
capture_warnings <- function(code, ignore_deprecation = FALSE) {
out <- Stack$new()

withCallingHandlers(
code,
warning = function(condition) {
if (ignore_deprecation && is_deprecation(condition)) {
return()
}

out$push(condition)
maybe_restart("muffleWarning")
}
Expand Down
6 changes: 4 additions & 2 deletions R/evaluate-promise.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
evaluate_promise <- function(code, print = FALSE) {
warnings <- Stack$new()
handle_warning <- function(condition) {
warnings$push(condition)
maybe_restart("muffleWarning")
if (!is_deprecation(condition)) {
warnings$push(condition)
maybe_restart("muffleWarning")
}
}

messages <- Stack$new()
Expand Down
16 changes: 13 additions & 3 deletions R/expect-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ expect_warning <- function(object,
trace_env = caller_env()
)
} else {
act <- quasi_capture(enquo(object), label, capture_warnings)
act <- quasi_capture(enquo(object), label, capture_warnings, ignore_deprecation = identical(regexp, NA))
msg <- compare_messages(
act$cap, act$lab, regexp = regexp, all = all, ...,
cond_type = "warnings"
Expand Down Expand Up @@ -229,6 +229,7 @@ expect_condition <- function(object,
trace_env = caller_env()
)
} else {

act <- quasi_capture(enquo(object), label, capture_condition, entrace = TRUE)
msg <- compare_condition_2e(
act$cap,
Expand Down Expand Up @@ -260,7 +261,8 @@ expect_condition_matching <- function(base_class,
class %||% base_class,
regexp,
...,
inherit = inherit
inherit = inherit,
ignore_deprecation = base_class == "warning" && identical(regexp, NA)
)

act <- quasi_capture(
Expand All @@ -284,7 +286,7 @@ expect_condition_matching <- function(base_class,

# -------------------------------------------------------------------------

cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE) {
cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE, ignore_deprecation = FALSE) {
if (!is_string(class)) {
abort("`class` must be a single string")
}
Expand All @@ -297,6 +299,10 @@ cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE) {
cnd$parent <- NULL
}

if (ignore_deprecation && is_deprecation(cnd)) {
return(FALSE)
}

if (is.null(pattern) || isNA(pattern)) {
cnd_inherits(cnd, class)
} else {
Expand All @@ -305,6 +311,10 @@ cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE) {
}
}

is_deprecation <- function(x) {
inherits(x, "lifecycle_warning_deprecated")
}

cnd_inherits <- function(cnd, class) {
cnd_some(cnd, ~ inherits(.x, class))
}
Expand Down
6 changes: 5 additions & 1 deletion R/expect-no-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ expect_no_ <- function(base_class,
class = NULL,
error_call = caller_env()) {

matcher <- cnd_matcher(class %||% base_class, regexp)
matcher <- cnd_matcher(
class %||% base_class,
pattern = regexp,
ignore_deprecation = base_class == "warning" && is.null(regexp) && is.null(class)
)

capture <- function(code) {
try_fetch(
Expand Down
2 changes: 1 addition & 1 deletion man/capture_condition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions revdep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
|package |version |error |warning |note |
|:------------|:-------|:-----|:-------|:----|
|Boom |0.9.10 |1 | | |
|bsts |? | | | |
|CausalImpact |? | | | |
|NA |? | | | |
|ctsem |3.7.1 |1 | | |
|NA |? | | | |
Expand Down Expand Up @@ -34,12 +34,15 @@
|vivid |? | | | |
|NA |? | | | |

## New problems (4)
## New problems (7)

|package |version |error |warning |note |
|:--------|:-------|:------|:-------|:----|
|package |version |error |warning |note |
|:----------|:-------|:------|:-------|:----|
|[batata](problems.md#batata)|0.2.1 |__+1__ | |1 |
|[brew](problems.md#brew)|1.0-7 |__+1__ | | |
|[freshr](problems.md#freshr)|1.0.1 |__+1__ | | |
|[lightgbm](problems.md#lightgbm)|3.3.2 |__+1__ | |1 |
|[log4r](problems.md#log4r)|0.4.2 |__+1__ | | |
|[r2dii.plot](problems.md#r2diiplot)|0.3.0 |__+1__ | | |
|[reprex](problems.md#reprex)|2.0.2 |__+1__ | | |
|[WeMix](problems.md#wemix)|3.2.2 |__+1__ |1 | |

17 changes: 13 additions & 4 deletions revdep/cran.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
## revdepcheck results

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

* We saw 4 new problems
* We saw 7 new problems
* We failed to check 16 packages

Issues with CRAN packages are summarised below.

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

* batata
checking tests ... ERROR

* brew
checking tests ... ERROR

* freshr
checking tests ... ERROR

* lightgbm
* log4r
checking tests ... ERROR

* r2dii.plot
checking tests ... ERROR

* reprex
checking tests ... ERROR

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

* Boom (NA)
* bsts (NA)
* CausalImpact (NA)
* ctsem (NA)
* elbird (NA)
* ggPMX (NA)
Expand Down
30 changes: 14 additions & 16 deletions revdep/failures.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ ERROR: compilation failed for package ‘Boom’


```
# bsts
# CausalImpact
<details>
* Version: 0.9.8
* Version: 1.2.7
* GitHub: NA
* Source code: https://github.com/cran/bsts
* Date/Publication: 2022-05-30 07:00:12 UTC
* Number of recursive dependencies: 37
* Source code: https://github.com/cran/CausalImpact
* Date/Publication: 2021-06-07 06:40:02 UTC
* Number of recursive dependencies: 73
Run `cloud_details(, "bsts")` for more info
Run `cloud_details(, "CausalImpact")` for more info
</details>
Expand All @@ -95,17 +95,16 @@ Run `cloud_details(, "bsts")` for more info
### Devel
```
* using log directory ‘/tmp/workdir/bsts/new/bsts.Rcheck’
* using log directory ‘/tmp/workdir/CausalImpact/new/CausalImpact.Rcheck’
* using R version 4.1.1 (2021-08-10)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* using option ‘--no-manual’
* checking for file ‘bsts/DESCRIPTION’ ... OK
* this is package ‘bsts’ version ‘0.9.8’
* package encoding: UTF-8
* checking for file ‘CausalImpact/DESCRIPTION’ ... OK
* this is package ‘CausalImpact’ version ‘1.2.7’
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Packages required but not available: 'BoomSpikeSlab', 'Boom'
Packages required but not available: 'bsts', 'Boom'

See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
manual.
Expand All @@ -120,17 +119,16 @@ Status: 1 ERROR
### CRAN
```
* using log directory ‘/tmp/workdir/bsts/old/bsts.Rcheck’
* using log directory ‘/tmp/workdir/CausalImpact/old/CausalImpact.Rcheck’
* using R version 4.1.1 (2021-08-10)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* using option ‘--no-manual’
* checking for file ‘bsts/DESCRIPTION’ ... OK
* this is package ‘bsts’ version ‘0.9.8’
* package encoding: UTF-8
* checking for file ‘CausalImpact/DESCRIPTION’ ... OK
* this is package ‘CausalImpact’ version ‘1.2.7’
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Packages required but not available: 'BoomSpikeSlab', 'Boom'
Packages required but not available: 'bsts', 'Boom'

See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
manual.
Expand Down
Loading

0 comments on commit 63dce2d

Please sign in to comment.