Skip to content

Commit c976aac

Browse files
committed
Skip tests if installed backtrace format routine is stale
1 parent d243c82 commit c976aac

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

R/cnd-abort.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ find_capture_context <- function(n = 3L) {
268268
#' # stop("foo")
269269
NULL
270270

271+
# Whenever the backtrace-on-error format is changed, the version in
272+
# `inst/backtrace-ver` and in `tests/testthat/helper-rlang.R` must be
273+
# bumped. This way `devtools::test()` will skip the tests that require
274+
# the dev version to be installed locally.
271275
format_onerror_backtrace <- function(cnd) {
272276
trace <- cnd$trace
273277
if (is_null(trace) || !trace_length(trace)) {

inst/backtrace-ver

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

tests/testthat/helper-rlang.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ with_methods <- function(.expr, ...) {
3030
local_methods(...)
3131
.expr
3232
}
33+
34+
# Some backtrace tests use Rscript, which requires the last version of
35+
# the backtrace code to be installed locally
36+
skip_if_stale_backtrace <- local({
37+
current_backtrace_ver <- "1.0.0"
38+
39+
ver <- system.file("backtrace-ver", package = "rlang")
40+
has_stale_backtrace <- ver == "" || !identical(readLines(ver), current_backtrace_ver)
41+
42+
function() {
43+
skip_if(has_stale_backtrace)
44+
}
45+
})

tests/testthat/test-cnd-abort.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ test_that("format_onerror_backtrace handles empty and size 1 traces", {
6565

6666
test_that("error is printed with backtrace", {
6767
skip_unless_utf8()
68+
skip_if_stale_backtrace()
6869

6970
run_error_script <- function(envvars = chr()) {
7071
run_script(test_path("fixtures", "error-backtrace.R"), envvars = envvars)
@@ -114,6 +115,7 @@ test_that("error is printed with backtrace", {
114115

115116
test_that("empty backtraces are not printed", {
116117
skip_unless_utf8()
118+
skip_if_stale_backtrace()
117119

118120
run_error_script <- function(envvars = chr()) {
119121
run_script(test_path("fixtures", "error-backtrace-empty.R"), envvars = envvars)
@@ -141,6 +143,7 @@ test_that("empty backtraces are not printed", {
141143

142144
test_that("parent errors are not displayed in error message and backtrace", {
143145
skip_unless_utf8()
146+
skip_if_stale_backtrace()
144147

145148
run_error_script <- function(envvars = chr()) {
146149
run_script(

tests/testthat/test-cnd-error.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_that("error_cnd() checks its fields", {
99

1010
test_that("can use conditionMessage() method in subclasses of rlang errors", {
1111
skip_unless_utf8()
12+
skip_if_stale_backtrace()
1213

1314
run_error_script <- function(envvars = chr()) {
1415
run_script(

0 commit comments

Comments
 (0)