diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 4537f668..5bcca714 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -18,7 +18,7 @@ jobs: config: - {os: windows-latest, r: 'release', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu' } - {os: windows-latest, r: 'devel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu' } - - {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '42' } + - {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '43' } - {os: macOS-latest, r: 'release', rust-version: 'stable' } @@ -29,6 +29,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes + REXTENDR_SKIP_DEV_TESTS: TRUE # TODO: Remove this when extendr/libR-sys issue is resolved steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb502..44c75e97 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -13,6 +13,7 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + REXTENDR_SKIP_DEV_TESTS: TRUE # TODO: Remove this when extendr/libR-sys issue is resolved steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/test_pkg_gen.yaml b/.github/workflows/test_pkg_gen.yaml index f2d7e9fd..c55af1df 100644 --- a/.github/workflows/test_pkg_gen.yaml +++ b/.github/workflows/test_pkg_gen.yaml @@ -22,7 +22,7 @@ jobs: config: - {os: windows-latest, r: 'release', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu'} - {os: windows-latest, r: 'devel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu'} - - {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '42'} + - {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '43'} - {os: macOS-latest, r: 'release', rust-version: 'stable'} diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index abee654a..e970b9ce 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -1,4 +1,3 @@ - #' Create package that uses Rust #' #' @description @@ -14,7 +13,6 @@ #' #' @noRd create_extendr_package <- function(path, ...) { - # error if usethis is not installed rlang::check_installed("usethis") @@ -51,5 +49,4 @@ create_extendr_package <- function(path, ...) { ) invisible(path) - } diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 4b70ee72..d5f58ee6 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -83,7 +83,7 @@ cat_file <- function(...) { #' Helper function for skipping tests when cargo subcommand is unavailable #' @param args Character vector, arguments to the `cargo` command. Pass to [processx::run()]'s args param. -skip_if_cargo_bin <- function(args = "--help") { +skip_if_cargo_unavailable <- function(args = "--help") { tryCatch( { processx::run("cargo", args, error_on_status = TRUE) diff --git a/tests/testthat/test-clean.R b/tests/testthat/test-clean.R index 7aa1d687..3ee022ee 100644 --- a/tests/testthat/test-clean.R +++ b/tests/testthat/test-clean.R @@ -2,7 +2,7 @@ test_that("rextendr::clean() removes cargo target directory & binaries", { skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_on_R42_win() path <- local_package("testpkg") diff --git a/tests/testthat/test-document.R b/tests/testthat/test-document.R index 34c33439..6aaa24df 100644 --- a/tests/testthat/test-document.R +++ b/tests/testthat/test-document.R @@ -2,7 +2,7 @@ test_that("Running `document` after adding multiple files", { skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() path <- local_package("testPackage") use_extendr() @@ -18,7 +18,7 @@ test_that("Warn if using older rextendr", { skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() path <- local_package("futurepkg") use_extendr() @@ -31,7 +31,7 @@ test_that("Update the Config/rextendr/version field in DESCRIPTION file", { skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() path <- local_package("oldpkg") use_extendr() @@ -47,7 +47,7 @@ test_that("document() warns if NAMESPACE file is malformed", { skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() path <- local_package("testPackage") r"(exportPattern("^[[:alpha:]]+"))" |> brio::write_lines("NAMESPACE") diff --git a/tests/testthat/test-eval.R b/tests/testthat/test-eval.R index 5fd41927..bb9dcb20 100644 --- a/tests/testthat/test-eval.R +++ b/tests/testthat/test-eval.R @@ -1,5 +1,5 @@ test_that("`rust_eval()` works", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_equal(rust_eval("2 + 2"), 4) expect_visible(rust_eval("2 + 2")) @@ -17,7 +17,7 @@ test_that("`rust_eval()` works", { # the order of compilation. # Returned integer values should be identical to the input sequence. test_that("multiple `rust_eval_deferred()` work correctly", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() provided_values <- seq_len(5) deferred_handles <- purrr::map( @@ -44,7 +44,7 @@ test_that("multiple `rust_eval_deferred()` work correctly", { # the reverse order. # Returned integer values should be identical to the reversed input sequence. test_that("multiple `rust_eval_deferred()` work correctly in reverse order", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() provided_values <- seq_len(5) @@ -72,7 +72,7 @@ test_that("multiple `rust_eval_deferred()` work correctly in reverse order", { # Third, attempt to execute the same compiled piece of code and # observe an error. test_that("`rust_eval_deferred()` disallows multiple executions of the same chunk", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() handle <- rust_eval_deferred("5i32 + 6i32") @@ -92,7 +92,7 @@ test_that("`rust_eval_deferred()` disallows multiple executions of the same chun # Execute code chunk and verify result. # Test if the wrapper has been removed and dll unloaded. test_that("`rust_eval_deferred()` environment cleanup", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() handle <- rust_eval_deferred("42i32") fn_name <- attr(handle, "function_name") @@ -116,7 +116,7 @@ test_that("`rust_eval_deferred()` environment cleanup", { # Compare wrapper function names and dll paths (should be unequal). # Execute both chunks and test results (should be equal). test_that("`rust_eval_deferred()` generates unique function names", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() rust_code <- "42f64" diff --git a/tests/testthat/test-extendr_function_options.R b/tests/testthat/test-extendr_function_options.R index e1cc1ae1..09161830 100644 --- a/tests/testthat/test-extendr_function_options.R +++ b/tests/testthat/test-extendr_function_options.R @@ -1,6 +1,5 @@ test_that("`extendr` code is compiled with `either` feature and `use_try_from` enabled", { - skip_if_cargo_bin() - skip_if_opted_out_of_dev_tests() + skip_if_cargo_unavailable() rust_function( "fn type_aware_sum(input : Either) -> Either { @@ -11,8 +10,6 @@ test_that("`extendr` code is compiled with `either` feature and `use_try_from` e }", extendr_fn_options = list("use_try_from" = TRUE), features = "either", - use_dev_extendr = TRUE, - quiet = TRUE # Suppresses warnings while the feature is still experimental ) int_sum <- type_aware_sum(1:5) @@ -27,7 +24,7 @@ test_that("`extendr` code is compiled with `either` feature and `use_try_from` e }) test_that("`r_name` option renames R function", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() rust_function( "fn func() -> &'static str {\"Modified Name\"}", @@ -42,7 +39,7 @@ test_that("`rust_source()` errors if `extendr_fn_options` contains `NULL` value" }) test_that("`rust_source()` errors if `extendr_fn_options` contains value of the wrong type", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() # due to the use of purrr here, the error that is emitted is on of class `mutate_error` # we cannot expect `rextendr_error` from this function. @@ -50,13 +47,13 @@ test_that("`rust_source()` errors if `extendr_fn_options` contains value of the }) test_that("`rust_source()` errors if `extendr_fn_options` contains option with an invalid name", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_rextendr_error(rust_function("fn func() {}", extendr_fn_options = list("use try from" = TRUE))) }) test_that("`rust_source()` errors if `extendr_fn_options` contains two invalid options", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_rextendr_error( rust_function("fn func() {}", extendr_fn_options = list("use try from" = TRUE, "r_name" = NULL)) @@ -64,7 +61,7 @@ test_that("`rust_source()` errors if `extendr_fn_options` contains two invalid o }) test_that("`rust_source()` warns if `extendr_fn_options` contains an unknown option", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_warning( # Unknown option expect_rextendr_error( # Failed compilation because of the unknonw option @@ -76,7 +73,7 @@ test_that("`rust_source()` warns if `extendr_fn_options` contains an unknown opt test_that( "`rust_source()` does not warn if `extendr_fn_options` contains an unknown option and `use_dev_extendr` is `TRUE`", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_if_opted_out_of_dev_tests() expect_rextendr_error( # Failed compilation because of the unknonw option @@ -93,7 +90,7 @@ test_that( test_that( "`rust_function()` does not emit any messages when `quiet = TRUE`", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_no_message(rust_function(code = "fn func() {}", quiet = TRUE)) } diff --git a/tests/testthat/test-knitr-engine.R b/tests/testthat/test-knitr-engine.R index fcffb4d8..2df4ee56 100644 --- a/tests/testthat/test-knitr-engine.R +++ b/tests/testthat/test-knitr-engine.R @@ -1,5 +1,5 @@ test_that("knitr-engine works", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_if_not_installed("knitr") options <- knitr::opts_chunk$merge(list( @@ -23,7 +23,7 @@ test_that("knitr-engine works", { test_that("Snapshot test of knitr-engine", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_if_not_installed("knitr") input <- file.path("../data/test-knitr-engine-source-01.Rmd") diff --git a/tests/testthat/test-license_note.R b/tests/testthat/test-license_note.R index 9e4a6465..280cb870 100644 --- a/tests/testthat/test-license_note.R +++ b/tests/testthat/test-license_note.R @@ -1,6 +1,6 @@ test_that("LICENSE.note is generated properly", { skip_if_not_installed("usethis") - skip_if_cargo_bin(c("license", "--help")) + skip_if_cargo_unavailable(c("license", "--help")) local_package("testPackage") use_extendr() diff --git a/tests/testthat/test-make-module-macro.R b/tests/testthat/test-make-module-macro.R index ad7280ee..240b16ae 100644 --- a/tests/testthat/test-make-module-macro.R +++ b/tests/testthat/test-make-module-macro.R @@ -1,5 +1,5 @@ test_that("Module macro generation", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() rust_src <- r"( #[extendr] @@ -62,7 +62,7 @@ impl Counter { }) test_that("Macro generation fails on invalid rust code", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_rextendr_error( make_module_macro("#[extendr]\nlet invalid_var = ();"), @@ -72,7 +72,7 @@ test_that("Macro generation fails on invalid rust code", { test_that("Macro generation fails on invalid comments in code", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_rextendr_error( make_module_macro("/*/*/**/"), @@ -99,7 +99,7 @@ test_that("Macro generation fails on invalid comments in code", { test_that("Rust code cleaning", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_equal( fill_block_comments(c( @@ -129,7 +129,7 @@ test_that("Rust code cleaning", { }) test_that("Rust metadata capturing", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_equal( find_extendr_attrs_ids(c( diff --git a/tests/testthat/test-name-override.R b/tests/testthat/test-name-override.R index a12ce53e..502e2ec9 100644 --- a/tests/testthat/test-name-override.R +++ b/tests/testthat/test-name-override.R @@ -1,5 +1,5 @@ test_that("Multiple rust functions with the same name", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() rust_src_1 <- " #[extendr] diff --git a/tests/testthat/test-optional-features.R b/tests/testthat/test-optional-features.R index 318ead3e..797ff324 100644 --- a/tests/testthat/test-optional-features.R +++ b/tests/testthat/test-optional-features.R @@ -1,5 +1,5 @@ test_that("Feature 'ndarray' is enabled when no extra dependencies are specified", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_on_R42_win() input <- file.path("../data/ndarray_example.rs") @@ -16,7 +16,7 @@ test_that("Feature 'ndarray' is enabled when no extra dependencies are specified }) test_that("Feature 'ndarray' is enabled when 'extendr-api' has features enabled", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_on_R42_win() input <- file.path("../data/ndarray_example.rs") @@ -34,20 +34,20 @@ test_that("Feature 'ndarray' is enabled when 'extendr-api' has features enabled" }) test_that("Enable multiple features simultaneously", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() rust_function("fn test_multiple_features() {}", features = c("ndarray", "serde", "graphics")) expect_no_error(test_multiple_features()) }) test_that("Passing integers to `features` results in error", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_rextendr_error(rust_function("fn test() {}", features = 1:10)) }) test_that("Passing list to `features` results in error", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_rextendr_error(rust_function("fn test() {}", features = list())) }) diff --git a/tests/testthat/test-source.R b/tests/testthat/test-source.R index 311aa9f6..1eaaa975 100644 --- a/tests/testthat/test-source.R +++ b/tests/testthat/test-source.R @@ -1,5 +1,5 @@ test_that("`rust_source()` works", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() rust_src <- " #[extendr] @@ -44,14 +44,14 @@ test_that("`rust_source()` works", { test_that("`options` override `toolchain` value in `rust_source`", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() withr::local_options(rextendr.toolchain = "Non-existent-toolchain") expect_rextendr_error(rust_function("fn rust_test() {}"), "Rust code could not be compiled successfully. Aborting.") }) test_that("`options` override `patch.crates_io` value in `rust_source`", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() withr::local_options(rextendr.patch.crates_io = list(`extendr-api` = "-1")) expect_rextendr_error(rust_function("fn rust_test() {}"), "Rust code could not be compiled successfully. Aborting.") @@ -59,7 +59,7 @@ test_that("`options` override `patch.crates_io` value in `rust_source`", { test_that("`options` override `rextendr.extendr_deps` value in `rust_source`", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() withr::local_options(rextendr.extendr_deps = list(`extendr-api` = "-1")) expect_rextendr_error(rust_function("fn rust_test() {}"), "Rust code could not be compiled successfully. Aborting.") @@ -69,7 +69,7 @@ test_that("`rust_source` works even when the PATH is not set correctly, which ma skip_on_os("windows") # On Windows, we have no concern as the only installation method is the official installer skip_on_os("linux") # On Linux, `cargo` might be on somewhere like `/usr/bin`, which is hard to eliminate skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() # Construct PATH without ~/.cargo/bin local_path <- Sys.getenv("PATH") @@ -92,7 +92,7 @@ test_that("`rust_source` works even when the PATH is not set correctly, which ma # https://github.com/extendr/rextendr/issues/234 test_that("`rust_code()` can compile code from rust file", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() input <- file.path("../data/rust_source.rs") expect_no_error(rust_source(input, module_name = "test_module")) @@ -101,7 +101,7 @@ test_that("`rust_code()` can compile code from rust file", { # https://github.com/extendr/rextendr/issues/234 test_that("`rust_code()` can compile code from rust file multiple times", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() input <- file.path("../data/rust_source.rs") expect_no_error(rust_source(input, module_name = "test_module")) @@ -112,7 +112,7 @@ test_that("`rust_code()` can compile code from rust file multiple times", { # https://github.com/extendr/rextendr/issues/234 test_that("`rust_code()` can compile code from rust files with identical names", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() input_1 <- file.path("../data/inner_1/rust_source.rs") input_2 <- file.path("../data/inner_2/rust_source.rs") @@ -126,7 +126,7 @@ test_that("`rust_code()` can compile code from rust files with identical names", # https://github.com/extendr/rextendr/issues/264 test_that("`rust_source()` should not raise internal error for code without extendr attrs", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() expect_no_error(rust_source(code = "fn test() {}")) }) diff --git a/tests/testthat/test-use_dev_extendr.R b/tests/testthat/test-use_dev_extendr.R index 8a096daf..5823f5df 100644 --- a/tests/testthat/test-use_dev_extendr.R +++ b/tests/testthat/test-use_dev_extendr.R @@ -1,5 +1,5 @@ test_that("`use_dev_extendr = TRUE` works together with `features`", { - skip_if_cargo_bin() + skip_if_cargo_unavailable() skip_if_opted_out_of_dev_tests() rust_function( diff --git a/tests/testthat/test-use_extendr.R b/tests/testthat/test-use_extendr.R index f64c5221..124cea6a 100644 --- a/tests/testthat/test-use_extendr.R +++ b/tests/testthat/test-use_extendr.R @@ -113,7 +113,7 @@ test_that("use_extendr() handles R packages with dots in the name", { skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() path <- local_package("a.b.c") use_extendr() @@ -127,7 +127,7 @@ test_that("use_extendr() handles R package name, crate name and library name sep skip_if_not_installed("usethis") skip_if_not_installed("devtools") skip_on_cran() - skip_if_cargo_bin() + skip_if_cargo_unavailable() path <- local_package("testPackage") use_extendr(crate_name = "crate_name", lib_name = "lib_name")