Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix test CI: testthat and covr tests for with_nix() #116

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
911f338
add sys
philipp-baumann Jan 28, 2024
da510e0
fix typo
philipp-baumann Jan 28, 2024
aad9583
quick tempdir diagnostics
philipp-baumann Jan 28, 2024
cc8b68a
typo :-)
philipp-baumann Jan 28, 2024
c9bd1e6
add nix to subshell
philipp-baumann Jan 28, 2024
0bb62bc
--pure shell
philipp-baumann Jan 28, 2024
9a4d46c
manual tempdir
philipp-baumann Jan 28, 2024
ec86f13
cacert needed
philipp-baumann Jan 28, 2024
23ee260
test with no session info output
philipp-baumann Jan 28, 2024
8075c93
quick devtools test
philipp-baumann Jan 28, 2024
4990fdd
try-error pkg location
philipp-baumann Jan 28, 2024
c982f34
less deps for Nix-R devtools::test
philipp-baumann Jan 28, 2024
71a18e3
add back covr
philipp-baumann Jan 28, 2024
91be77c
no custom install path (try-error)
philipp-baumann Jan 28, 2024
3e3c034
install_path makes no difference
philipp-baumann Jan 28, 2024
3b029e3
keep up with master
philipp-baumann Jan 29, 2024
9d9dfd8
Merge branch 'master' into covr-with-nix
philipp-baumann Jan 29, 2024
b1e9bdd
add git
philipp-baumann Jan 29, 2024
58439c0
add missing xml2
philipp-baumann Jan 29, 2024
0353208
add httr
philipp-baumann Jan 29, 2024
86996e6
this is needed for local RStudio on MacOS
philipp-baumann Jan 29, 2024
7663de8
add another test with different R version
philipp-baumann Jan 29, 2024
a65862b
add nix store to PATH if not there; nix_build test
philipp-baumann Jan 30, 2024
a13decf
fix `sessionInfo()` erroring on R 3.5.3
philipp-baumann Jan 30, 2024
58b95e3
remove `_out.Rds` to make with_nix() error if Nix evall not successful
philipp-baumann Jan 30, 2024
fa55027
test nix_build in local runner dir
philipp-baumann Jan 30, 2024
5604af1
block the R nix session in tests
philipp-baumann Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ jobs:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Test coverage
run: nix-shell -p R rPackages.covr rPackages.codetools rPackages.testthat --run "Rscript -e 'covr::codecov(quiet = FALSE, clean = FALSE, install_path = file.path(Sys.getenv(\"RUNNER_TEMP\"), \"package\"))' "
- name: Test
run: nix-shell --pure -p cacert nix R rPackages.covr rPackages.codetools rPackages.xml2 rPackages.sys rPackages.devtools --run "Rscript -e 'devtools::test()'"

- name: Test coverage
run: nix-shell --pure -p git cacert nix R rPackages.covr rPackages.codetools rPackages.xml2 rPackages.httr rPackages.sys rPackages.testthat --run "Rscript -e 'covr::codecov(quiet = FALSE, clean = FALSE, install_path = file.path(\"/home/runner/work/_temp\", \"package\"))' "

- name: Show testthat output
if: always()
run: |
Expand Down
1 change: 1 addition & 0 deletions R/nix_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' }
nix_build <- function(project_path = ".",
exec_mode = c("blocking", "non-blocking")) {
PATH <- set_nix_path()
has_nix_build <- nix_build_installed() # TRUE if yes, FALSE if no
nix_file <- file.path(project_path, "default.nix")

Expand Down
11 changes: 10 additions & 1 deletion R/with_nix.R
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ with_nix <- function(expr,
print(out$stdout)
}

unlink(file.path(temp_dir, "_out.Rds"), force = TRUE)

cat("")
return(out)
}
Expand Down Expand Up @@ -754,7 +756,7 @@ quote_rnix <- function(expr,
cat(ls())
cat("\n")
cat("\n* `sessionInfo()` output:\n")
cat(capture.output(sessionInfo()), sep = "\n")
try(cat(capture.output(sessionInfo()), sep = "\n"))
} ) # end of `bquote()`

return(expr_quoted)
Expand Down Expand Up @@ -799,6 +801,13 @@ with_expr_deparse <- function(expr) {

#' @noRd
nix_shell_available <- function() {
# for local tests via `devtools::test()` in RStudio
old_path <- Sys.getenv("PATH")
nix_path <- "/nix/var/nix/profiles/default/bin"
has_nix_path <- any(grepl(nix_path, old_path))
if (isFALSE(has_nix_path)) {
Sys.setenv(PATH = paste(old_path, nix_path, sep = ":"))
}
which_nix_shell <- Sys.which("nix-shell")
if (nzchar(which_nix_shell)) {
return(TRUE)
Expand Down
34 changes: 34 additions & 0 deletions dev/flat_nix_build.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ session.
#' }
nix_build <- function(project_path = ".",
exec_mode = c("blocking", "non-blocking")) {
PATH <- set_nix_path()
has_nix_build <- nix_build_installed() # TRUE if yes, FALSE if no
nix_file <- file.path(project_path, "default.nix")

Expand Down Expand Up @@ -142,3 +143,36 @@ nix_build_exit_msg <- function(x) {
return(err_msg)
}
```

```{r, tests-nix_build}
testthat::test_that("Testing that `nix_build()` builds derivation", {

skip_if_not(nix_shell_available())

path_subshell <- "."

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

rix(
r_ver = "latest",
overwrite = TRUE,
project_path = path_subshell
)

out <- nix_build(
project_path = path_subshell,
exec_mode = "blocking"
)

# exit status 0L is success
testthat::expect_true(
out$status == 0L
)


})
```
53 changes: 48 additions & 5 deletions dev/flat_with_nix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ with_nix <- function(expr,
print(out$stdout)
}

unlink(file.path(temp_dir, "_out.Rds"), force = TRUE)

cat("")
return(out)
}
Expand Down Expand Up @@ -763,7 +765,7 @@ quote_rnix <- function(expr,
cat(ls())
cat("\n")
cat("\n* `sessionInfo()` output:\n")
cat(capture.output(sessionInfo()), sep = "\n")
try(cat(capture.output(sessionInfo()), sep = "\n"))
} ) # end of `bquote()`

return(expr_quoted)
Expand Down Expand Up @@ -808,6 +810,13 @@ with_expr_deparse <- function(expr) {

#' @noRd
nix_shell_available <- function() {
# for local tests via `devtools::test()` in RStudio
old_path <- Sys.getenv("PATH")
nix_path <- "/nix/var/nix/profiles/default/bin"
has_nix_path <- any(grepl(nix_path, old_path))
if (isFALSE(has_nix_path)) {
Sys.setenv(PATH = paste(old_path, nix_path, sep = ":"))
}
which_nix_shell <- Sys.which("nix-shell")
if (nzchar(which_nix_shell)) {
return(TRUE)
Expand Down Expand Up @@ -837,13 +846,47 @@ create_shell_nix <- function(path = file.path("inst", "extdata",
```

```{r, tests-with_nix}
testthat::test_that("Test 2 for with_nix() if Nix is installed", {

skip_if_not(nix_shell_available())

path_subshell <- "."

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

rix(
r_ver = "4.2.0",
overwrite = TRUE,
project_path = path_subshell
)

df <- data.frame(a = 1:3, b = 4:6)

out_subshell <- with_nix(
expr = function() {
as.vector(x = data.frame(a = 1:3, b = 4:6), mode = "list")
},
program = "R",
exec_mode = "blocking",
project_path = path_subshell,
message_type = "verbose"
)

testthat::expect_false(
inherits(out_subshell, "data.frame")
)
})


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

skip_if_not(nix_shell_available())

skip_on_covr()

path_subshell <- tempdir()
path_subshell <- "."

rix_init(
project_path = path_subshell,
Expand All @@ -865,7 +908,7 @@ testthat::test_that("Testing with_nix() if Nix is installed", {
return(a)
},
program = "R",
exec_mode = "non-blocking",
exec_mode = "blocking",
project_path = path_subshell,
message_type = "simple"
)
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/test-nix_build.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# WARNING - Generated by {fusen} from dev/flat_nix_build.Rmd: do not edit by hand

testthat::test_that("Testing that `nix_build()` builds derivation", {

skip_if_not(nix_shell_available())

path_subshell <- "."

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

rix(
r_ver = "latest",
overwrite = TRUE,
project_path = path_subshell
)

out <- nix_build(
project_path = path_subshell,
exec_mode = "blocking"
)

# exit status 0L is success
testthat::expect_true(
out$status == 0L
)


})
42 changes: 38 additions & 4 deletions tests/testthat/test-with_nix.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
# WARNING - Generated by {fusen} from dev/flat_with_nix.Rmd: do not edit by hand

testthat::test_that("Test 2 for with_nix() if Nix is installed", {

skip_if_not(nix_shell_available())

path_subshell <- "."

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

rix(
r_ver = "4.2.0",
overwrite = TRUE,
project_path = path_subshell
)

df <- data.frame(a = 1:3, b = 4:6)

out_subshell <- with_nix(
expr = function() {
as.vector(x = data.frame(a = 1:3, b = 4:6), mode = "list")
},
program = "R",
exec_mode = "blocking",
project_path = path_subshell,
message_type = "verbose"
)

testthat::expect_false(
inherits(out_subshell, "data.frame")
)
})


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

skip_if_not(nix_shell_available())

skip_on_covr()

path_subshell <- tempdir()
path_subshell <- "."

rix_init(
project_path = path_subshell,
Expand All @@ -28,7 +62,7 @@ testthat::test_that("Testing with_nix() if Nix is installed", {
return(a)
},
program = "R",
exec_mode = "non-blocking",
exec_mode = "blocking",
project_path = path_subshell,
message_type = "simple"
)
Expand Down
Loading