Skip to content

Commit

Permalink
added test to with_nix()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Rodrigues committed Jan 26, 2024
1 parent 40b2e09 commit 1203ad8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Imports:
Suggests:
knitr,
rmarkdown,
stringr,
testthat
VignetteBuilder:
knitr
Expand Down
15 changes: 13 additions & 2 deletions dev/flat_build_envs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ flag_rpkgs

```{r tests-rix}
testthat::test_that("Snapshot test of rix()", {
save_default_nix_test <- function(ide) {
path_default_nix <- tempdir()
Expand Down Expand Up @@ -1236,6 +1237,9 @@ nix_rprofile <- function() {

```{r, tests-rix_init}
testthat::test_that("Snapshot test of rix_init()", {
skip_on_covr()
save_rix_init_test <- function() {
path_env_nix <- tempdir()
Expand Down Expand Up @@ -2093,6 +2097,10 @@ create_shell_nix <- function(path = file.path("inst", "extdata",
```{r, tests-with_nix}
testthat::test_that("Testing with_nix() if Nix is installed", {
skip_if_not(nix_shell_available())
skip_on_covr()
path_env_stringr <- file.path(".", "_env_stringr_1.4.1")
rix_init(
Expand All @@ -2116,9 +2124,12 @@ testthat::test_that("Testing with_nix() if Nix is installed", {
message_type = "simple"
)
# on a recent version of stringr, stringr::str_subset(c("", "a"), "")
# should result in an error, but older versions would return "a"
# to avoid having a dependency on stringr just for this test,
# we see if the old version still returns "a"
testthat::expect_true(
skip_if_not(nix_shell_available())
identical(out_system_stringr, out_nix_stringr)
identical("a", out_nix_stringr)
)
on.exit(unlink(path_env_stringr, recursive = TRUE, force = TRUE))
Expand Down
47 changes: 47 additions & 0 deletions tests/testthat/test-find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ testthat::test_that("get_sri_hash_deps returns correct sri hash and dependencies


testthat::test_that("Snapshot test of rix()", {


save_default_nix_test <- function(ide) {

path_default_nix <- tempdir()
Expand Down Expand Up @@ -91,6 +93,9 @@ testthat::test_that("Snapshot test of rix()", {


testthat::test_that("Snapshot test of rix_init()", {

skip_on_covr()

save_rix_init_test <- function() {

path_env_nix <- tempdir()
Expand All @@ -112,3 +117,45 @@ testthat::test_that("Snapshot test of rix_init()", {
name = "golden_Rprofile.txt",
)
})

testthat::test_that("Testing with_nix() if Nix is installed", {

skip_if_not(nix_shell_available())

skip_on_covr()

path_env_stringr <- file.path(".", "_env_stringr_1.4.1")

rix_init(
project_path = path_env_stringr,
rprofile_action = "overwrite",
message_type = "simple"
)

rix(
r_ver = "latest",
r_pkgs = "stringr@1.4.1",
overwrite = TRUE,
project_path = path_env_stringr
)

out_nix_stringr <- with_nix(
expr = function() stringr::str_subset(c("", "a"), ""),
program = "R",
exec_mode = "non-blocking",
project_path = path_env_stringr,
message_type = "simple"
)

# on a recent version of stringr, stringr::str_subset(c("", "a"), "")
# should result in an error, but older versions would return "a"
# to avoid having a dependency on stringr just for this test,
# we see if the old version still returns "a"
testthat::expect_true(
identical("a", out_nix_stringr)
)

on.exit(unlink(path_env_stringr, recursive = TRUE, force = TRUE))

})

0 comments on commit 1203ad8

Please sign in to comment.