Skip to content

Commit

Permalink
handling cases where .Rprofile was already generated by rix_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Rodrigues committed Jul 1, 2024
1 parent 2b62be4 commit 2f1cfb0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rix/one_git_default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/12a9c0004bc987afb1ff511ebb97b67497a68e22.tar.gz") {};
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {};

git_archive_pkgs = [
(pkgs.rPackages.buildRPackage {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-nix_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ testthat::test_that("Testing that `nix_build()` builds derivation", {
path_subshell <- tempdir()

rix(
r_ver = "latest",
r_ver = "4.3.1",
overwrite = TRUE,
project_path = path_subshell,
shell_hook = NULL
Expand Down
52 changes: 50 additions & 2 deletions tests/testthat/test-rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ testthat::test_that("rix(), only one Github package", {

save_default_nix_test <- function(path_default_nix) {

rix(r_ver = "latest",
rix(r_ver = "4.3.1",
r_pkgs = NULL,
system_pkgs = NULL,
git_pkgs = list(package_name = "lookup",
Expand Down Expand Up @@ -466,7 +466,7 @@ testthat::test_that("rix(), conclusion message", {

save_default_nix_test <- function(path_default_nix) {

rix(r_ver = "latest",
rix(r_ver = "4.3.1",
ide = "other",
project_path = path_default_nix,
message_type = "simple",
Expand All @@ -485,3 +485,51 @@ testthat::test_that("rix(), conclusion message", {
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
})


testthat::test_that("rix(), warning message if rix_init() already called", {

testthat::skip_on_os

path_default_nix <- paste0(
tempdir(), paste0(sample(letters, 5), collapse = "")
)
dir.create(path_default_nix)
path_default_nix <- normalizePath(path_default_nix)

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

# Remove lines starting with # so rix() thinks the
# .Rprofile file was not generated by rix_init()
system(
paste0("sed -i '/^#/d' ",
file.path(path_default_nix, ".Rprofile"))
)


save_default_nix_test <- function(path_default_nix) {

rix(r_ver = "4.3.1",
ide = "other",
project_path = path_default_nix,
message_type = "simple",
overwrite = TRUE
)

file.path(path_default_nix, "default.nix")
}

testthat::expect_warning(
save_default_nix_test(path_default_nix),
regexp = "You may"
)

on.exit({
unlink(path_default_nix, recursive = TRUE, force = TRUE)
})
})

0 comments on commit 2f1cfb0

Please sign in to comment.