Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Nov 15, 2024
1 parent 4404db8 commit 426400c
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 134 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rextendr (development version)

* `use_cran_default()` has been removed as the default package template is CRAN compatible <https://github.com/extendr/rextendr/pull/394>
* `use_extendr()` now creates `tools/msrv.R`, `configure` and `configure.win`. These have been moved out of `use_cran_defaults()` <https://github.com/extendr/rextendr/pull/393>
* `Makevars` now prints linked static libraries at compile time by adding `--print=native-static-libs` to `RUSTFLAGS` <https://github.com/extendr/rextendr/pull/393>
* `use_extendr()` sets the `DESCRIPTION`'s `SystemRequirements` field according to CRAN policy to `Cargo (Rust's package manager), rustc` (#329)
Expand Down
32 changes: 31 additions & 1 deletion R/cran-compliance.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' \dontrun{
#' vendor_pkgs()
#' }
#' @name cran
#' @export
vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
stderr_line_callback <- function(x, proc) {
Expand Down Expand Up @@ -123,3 +122,34 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
# return packages and versions invisibly
invisible(res)
}


#' CRAN compliant extendr packages
#'

Check warning on line 128 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=128,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' R packages developed using extendr are not immediately ready to

Check warning on line 129 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=129,col=67,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' be published to CRAN. The extendr package template ensures that

Check warning on line 130 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=130,col=67,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' CRAN publication is (farily) painless.
#'

Check warning on line 132 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=132,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @section CRAN requirements:

Check warning on line 133 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=133,col=31,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#'

Check warning on line 134 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=134,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' In order to publish a Rust based package on CRAN it must meet certain

Check warning on line 135 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=135,col=73,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' requirements. These are:

Check warning on line 136 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=136,col=28,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#'
#' - Rust dependencies are vendored
#' - The package is compiled offline
#' - the `DESCRIPTION` file's `SystemRequirements` field contains `Cargo (Rust's package manager), rustc`
#'

Check warning on line 141 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=141,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' The extendr templates handle all of this _except_ vendoring dependencies.

Check warning on line 142 in R/cran-compliance.R

View workflow job for this annotation

GitHub Actions / lint

file=R/cran-compliance.R,line=142,col=77,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' This must be done prior to publication using [`vendor_pkgs()`].
#'
#' In addition, it is important to make sure that CRAN maintainers
#' are aware that the package they are checking contains Rust code.
#' Depending on which and how many crates are used as a dependencies
#' the `vendor.tar.xz` will be larger than a few megabytes. If a
#' built package is larger than 5mbs CRAN may reject the submission.
#'
#' To prevent rejection make a note in your `cran-comments.md` file
#' (create one using [`usethis::use_cran_comments()`]) along the lines of
#' "The package tarball is 6mb because Rust dependencies are vendored within src/rust/vendor.tar.xz which is 5.9mb."
#' @name cran
NULL
2 changes: 1 addition & 1 deletion inst/templates/configure
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"${R_HOME}/bin/Rscript" tools/msrv.R

# Set CRAN_FLAGS based on the NOT_CRAN value
if [ "${NOT_CRAN}" = "false" ]; then
if [ "${NOT_CRAN}" != "true" ]; then
export CRAN_FLAGS="-j 2 --offline"
else
export CRAN_FLAGS=""
Expand Down
2 changes: 1 addition & 1 deletion inst/templates/configure.win
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/msrv.R

# Set CRAN_FLAGS based on the NOT_CRAN value
if [ "${NOT_CRAN}" = "false" ]; then
if [ "${NOT_CRAN}" != "true" ]; then
export CRAN_FLAGS="-j 2 --offline"
else
export CRAN_FLAGS=""
Expand Down
51 changes: 24 additions & 27 deletions man/cran.Rd

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

37 changes: 37 additions & 0 deletions man/vendor_pkgs.Rd

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

33 changes: 11 additions & 22 deletions tests/testthat/_snaps/use_extendr.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
i Setting `Config/rextendr/version` to "*.*.*" in the 'DESCRIPTION' file.
i Setting `SystemRequirements` to "Cargo (Rust's package manager), rustc" in the 'DESCRIPTION' file.
v Creating 'src/rust/src'.
v Writing 'src/entrypoint.c'
v Writing 'src/Makevars.in'
v Writing 'src/Makevars.win.in'
v Writing 'src/Makevars.ucrt'
v Writing 'src/.gitignore'
v Writing 'src/rust/Cargo.toml'
v Writing 'src/rust/src/lib.rs'
v Writing 'src/testpkg-win.def'
v Writing 'src/entrypoint.c'.
v Writing 'src/Makevars.in'.
v Writing 'src/Makevars.win.in'.
v Writing 'src/Makevars.ucrt'.
v Writing 'src/.gitignore'.
v Writing 'src/rust/Cargo.toml'.
v Writing 'src/rust/src/lib.rs'.
v Writing 'src/testpkg-win.def'.
v Writing 'R/extendr-wrappers.R'
v Writing 'tools/msrv.R'
v Writing 'configure'
v Writing 'configure.win'
v Writing 'tools/msrv.R'.
v Writing 'configure'.
v Writing 'configure.win'.
v Adding "^src/\\.cargo$" to '.Rbuildignore'.
v Adding "^src/rust/vendor$" to '.Rbuildignore'.
v Adding "src/rust/vendor" to '.gitignore'.
Expand Down Expand Up @@ -234,18 +234,7 @@
Code
use_extendr()
Message
> File 'src/entrypoint.c' already exists. Skip writing the file.
> File 'src/Makevars.in' already exists. Skip writing the file.
> File 'src/Makevars.win.in' already exists. Skip writing the file.
> File 'src/Makevars.ucrt' already exists. Skip writing the file.
> File 'src/.gitignore' already exists. Skip writing the file.
> File 'src/rust/Cargo.toml' already exists. Skip writing the file.
> File 'src/rust/src/lib.rs' already exists. Skip writing the file.
> File 'src/testpkg.wrap-win.def' already exists. Skip writing the file.
> File 'R/extendr-wrappers.R' already exists. Skip writing the file.
> File 'tools/msrv.R' already exists. Skip writing the file.
> File 'configure' already exists. Skip writing the file.
> File 'configure.win' already exists. Skip writing the file.
v Finished configuring extendr for package testpkg.wrap.
* Please run `rextendr::document()` for changes to take effect.

Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-cran-compliance.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_that("vendor_pkgs() vendors dependencies", {
})


test_that("rextendr passes NOT_CRAN=false checks", {
test_that("rextendr passes CRAN checks", {
skip_if_not_installed("usethis")
skip_if_not_installed("rcmdcheck")

Expand All @@ -23,7 +23,17 @@ test_that("rextendr passes NOT_CRAN=false checks", {
use_extendr()
document()
vendor_pkgs()
res <- rcmdcheck::rcmdcheck(env = c("NOT_CRAN" = "false"))
res <- rcmdcheck::rcmdcheck(env = c("NOT_CRAN" = ""))

# --offline flag should be set
expect_true(grepl("--offline", res$install_out))
# -j 2 flag should be set
expect_true(grepl("-j 2", res$install_out))

# "Downloading" should not be present
expect_false(grepl("Downloading", res$install_out))


expect_true(
rlang::is_empty(res$errors) && rlang::is_empty(res$warnings)
)
Expand Down
13 changes: 7 additions & 6 deletions tests/testthat/test-use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ test_that("use_extendr() sets up extendr files correctly", {
# DESCRITION file
version_in_desc <- stringi::stri_trim_both(desc::desc_get("Config/rextendr/version", path)[[1]])
sysreq_in_desc <- stringi::stri_trim_both(desc::desc_get("SystemRequirements", path)[[1]])
expect_equal(version_in_desc, as.character(packageVersion("rextendr")))
expect_equal(sysreq_in_desc, "Cargo (Rust's package manager), rustc")
expect_identical(version_in_desc, as.character(packageVersion("rextendr")))
expect_identical(sysreq_in_desc, "Cargo (Rust's package manager), rustc")

# directory structure
expect_true(dir.exists("src"))
Expand Down Expand Up @@ -119,7 +119,7 @@ test_that("use_extendr() handles R packages with dots in the name", {
use_extendr()
document()
devtools::load_all()
expect_equal(hello_world(), "Hello world!")
expect_identical(hello_world(), "Hello world!")
})

# Specify crate name and library names explicitly
Expand All @@ -133,7 +133,7 @@ test_that("use_extendr() handles R package name, crate name and library name sep
use_extendr(crate_name = "crate_name", lib_name = "lib_name")
document()
devtools::load_all()
expect_equal(hello_world(), "Hello world!")
expect_identical(hello_world(), "Hello world!")
})

# Pass unsupported values to `crate_name` and `lib_name` and expect errors.
Expand Down Expand Up @@ -173,7 +173,7 @@ test_that("Message if the SystemRequirements field is already set.", {
)

expect_true(created)
expect_equal(desc::desc_get("SystemRequirements")[[1]], sys_req)
expect_identical(desc::desc_get("SystemRequirements")[[1]], sys_req)
})

test_that("`use_extendr()` works correctly when path is specified explicitly", {
Expand All @@ -195,8 +195,9 @@ test_that("`use_extendr()` passes R CMD check", {
usethis::use_mit_license()
use_extendr()
document()

# store results
res <- rcmdcheck::rcmdcheck()
res <- rcmdcheck::rcmdcheck(env = c("NOT_CRAN"="true"))

# check the output
expect_true(
Expand Down
74 changes: 0 additions & 74 deletions vignettes/articles/cran-compliance.Rmd

This file was deleted.

0 comments on commit 426400c

Please sign in to comment.