Skip to content

Commit

Permalink
Update dev tests (#352)
Browse files Browse the repository at this point in the history
* Enable either test

* Lint file

* Rename helper and permit optional either tests

* Skip dev tests

* I just can't type

* Also in test-coverage

* Upgrade Rtools version
  • Loading branch information
Ilia-Kosenkov authored May 11, 2024
1 parent e5072fc commit 6156085
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_pkg_gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down
3 changes: 0 additions & 3 deletions R/create_extendr_package.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Create package that uses Rust
#'
#' @description
Expand All @@ -14,7 +13,6 @@
#'
#' @noRd
create_extendr_package <- function(path, ...) {

# error if usethis is not installed
rlang::check_installed("usethis")

Expand Down Expand Up @@ -51,5 +49,4 @@ create_extendr_package <- function(path, ...) {
)

invisible(path)

}
2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-document.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-eval.R
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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(
Expand All @@ -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)

Expand Down Expand Up @@ -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")

Expand All @@ -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")
Expand All @@ -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"

Expand Down
19 changes: 8 additions & 11 deletions tests/testthat/test-extendr_function_options.R
Original file line number Diff line number Diff line change
@@ -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<Integers, Doubles>) -> Either<Rint, Rfloat> {
Expand All @@ -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)
Expand All @@ -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\"}",
Expand All @@ -42,29 +39,29 @@ 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.
expect_error(rust_function("fn func() {}", extendr_fn_options = list("use_try_from" = 42L)))
})

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))
)
})

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
Expand All @@ -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
Expand All @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-knitr-engine.R
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-license_note.R
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-make-module-macro.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("Module macro generation", {
skip_if_cargo_bin()
skip_if_cargo_unavailable()

rust_src <- r"(
#[extendr]
Expand Down Expand Up @@ -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 = ();"),
Expand All @@ -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("/*/*/**/"),
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-name-override.R
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-optional-features.R
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand All @@ -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()))
})
Loading

0 comments on commit 6156085

Please sign in to comment.