From 568141e2c12a1f291ae4fe7216f4abad2121924b Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 30 Apr 2025 14:43:56 -0700 Subject: [PATCH 1/4] Make skip reason clearer --- tests/testthat/test-standalone-errors.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test-standalone-errors.R b/tests/testthat/test-standalone-errors.R index b460bc41..12e4e2dc 100644 --- a/tests/testthat/test-standalone-errors.R +++ b/tests/testthat/test-standalone-errors.R @@ -134,8 +134,7 @@ test_that("chain_call", { }) test_that("errors from subprocess", { - skip_if_not_installed("callr", minimum_version = "3.7.0") - if (packageVersion("callr") != "3.7.0") skip("only with callr 3.7.0") + if (!requireNamespace("callr", quietly = TRUE) || packageVersion("callr") != "3.7.0") skip("only with callr exactly 3.7.0") err <- tryCatch( callr::r(function() 1 + "a"), error = function(e) e From dcf0abf3fa25dc21540af21d017816cb13a7107a Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 30 Apr 2025 14:47:57 -0700 Subject: [PATCH 2/4] Use skip_if() --- tests/testthat/test-standalone-errors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-standalone-errors.R b/tests/testthat/test-standalone-errors.R index 12e4e2dc..05d56ee2 100644 --- a/tests/testthat/test-standalone-errors.R +++ b/tests/testthat/test-standalone-errors.R @@ -134,7 +134,7 @@ test_that("chain_call", { }) test_that("errors from subprocess", { - if (!requireNamespace("callr", quietly = TRUE) || packageVersion("callr") != "3.7.0") skip("only with callr exactly 3.7.0") + skip_if(!requireNamespace("callr", quietly = TRUE) || packageVersion("callr") != "3.7.0", "only with callr exactly 3.7.0") err <- tryCatch( callr::r(function() 1 + "a"), error = function(e) e From 7cb46865c0403e32813721844b7b55b6f8cfdd5e Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 30 Apr 2025 14:50:40 -0700 Subject: [PATCH 3/4] tryCatch approach with specific error handler --- tests/testthat/test-standalone-errors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-standalone-errors.R b/tests/testthat/test-standalone-errors.R index 05d56ee2..3d3e8e32 100644 --- a/tests/testthat/test-standalone-errors.R +++ b/tests/testthat/test-standalone-errors.R @@ -134,7 +134,7 @@ test_that("chain_call", { }) test_that("errors from subprocess", { - skip_if(!requireNamespace("callr", quietly = TRUE) || packageVersion("callr") != "3.7.0", "only with callr exactly 3.7.0") + skip_if_not(isTRUE(tryCatch(packageVersion("callr") == "3.7.0", packageNotFoundError = function(c) FALSE)), "only with callr exactly 3.7.0") err <- tryCatch( callr::r(function() 1 + "a"), error = function(e) e From 5517de29eaf6f5a5e66ff716728dd026cc2b6847 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 30 Apr 2025 14:51:57 -0700 Subject: [PATCH 4/4] elide: use try() for concision --- tests/testthat/test-standalone-errors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-standalone-errors.R b/tests/testthat/test-standalone-errors.R index 3d3e8e32..d4128ff9 100644 --- a/tests/testthat/test-standalone-errors.R +++ b/tests/testthat/test-standalone-errors.R @@ -134,7 +134,7 @@ test_that("chain_call", { }) test_that("errors from subprocess", { - skip_if_not(isTRUE(tryCatch(packageVersion("callr") == "3.7.0", packageNotFoundError = function(c) FALSE)), "only with callr exactly 3.7.0") + skip_if_not(isTRUE(try(packageVersion("callr") == "3.7.0", silent = TRUE)), "only with callr exactly 3.7.0") err <- tryCatch( callr::r(function() 1 + "a"), error = function(e) e