-
Notifications
You must be signed in to change notification settings - Fork 301
Clean up code and tests around nested projects #1085
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,17 +16,13 @@ if (!is.null(session_temp_proj)) { | |
| )) | ||
| } | ||
|
|
||
| ## putting `pattern` in the package or project name is part of our strategy for | ||
| ## suspending the nested project check during testing | ||
| pattern <- "aaa" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I'm not sure why I ever made the magic string part of the default project name. Probably because I was very frustrated with problems around nested projects and testing? If this ever happens to you @hadley (catastrophic test failure related to nested projects), remember we have some code elsewhere in this |
||
|
|
||
| scoped_temporary_package <- function(dir = file_temp(pattern = pattern), | ||
| scoped_temporary_package <- function(dir = file_temp(pattern = "testpkg"), | ||
| env = parent.frame(), | ||
| rstudio = FALSE) { | ||
| scoped_temporary_thing(dir, env, rstudio, "package") | ||
| } | ||
|
|
||
| scoped_temporary_project <- function(dir = file_temp(pattern = pattern), | ||
| scoped_temporary_project <- function(dir = file_temp(pattern = "testproj"), | ||
| env = parent.frame(), | ||
| rstudio = FALSE) { | ||
| scoped_temporary_thing(dir, env, rstudio, "project") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| context("create") | ||
|
|
||
| test_that("create_package() creates a package", { | ||
| dir <- scoped_temporary_package() | ||
| expect_true(possibly_in_proj(dir)) | ||
|
|
@@ -29,31 +27,59 @@ test_that("create functions return path to new proj, but restore active proj", { | |
|
|
||
| test_that("nested package is disallowed, by default", { | ||
| dir <- scoped_temporary_package() | ||
| expect_usethis_error(scoped_temporary_package(path(dir, "abcde")), "anyway") | ||
| expect_usethis_error(create_package(path(dir, "abcde")), "anyway") | ||
| }) | ||
|
|
||
| test_that("nested project is disallowed, by default", { | ||
| dir <- scoped_temporary_project() | ||
| expect_usethis_error(scoped_temporary_project(path(dir, "abcde")), "anyway") | ||
| expect_usethis_error(create_project(path(dir, "abcde")), "anyway") | ||
| }) | ||
|
|
||
| test_that("nested package can be created if user really, really wants to", { | ||
| parent <- scoped_temporary_package() | ||
| with_mock( | ||
| # since user can't approve interactively, use the backdoor | ||
| `usethis:::allow_nested_project` = function() TRUE, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this just be |
||
| child <- create_package(path(parent, "fghijk")) | ||
| ) | ||
| expect_true(possibly_in_proj(child)) | ||
| expect_true(is_package(child)) | ||
| }) | ||
|
|
||
| test_that("nested project can be created if user really, really wants to", { | ||
| parent <- scoped_temporary_project() | ||
| with_mock( | ||
| # since user can't approve interactively, use the backdoor | ||
| `usethis:::allow_nested_project` = function() TRUE, | ||
| child <- create_project(path(parent, "fghijk")) | ||
| ) | ||
| expect_true(possibly_in_proj(child)) | ||
| expect_false(is_package(child)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Until now, we had never actually intentionally created a nested package or project in the tests 🤷♀️ |
||
| }) | ||
|
|
||
| test_that("can create package in current directory", { | ||
| dir <- dir_create(path(file_temp(), "mypackage")) | ||
| withr::local_dir(dir) | ||
| # doing this "by hand" vs. via withr because Windows appears to be unwilling | ||
| # to delete current working directory | ||
| newdir <- dir_create(path(file_temp(), "mypackage")) | ||
| oldwd <- setwd(newdir) | ||
| on.exit({ | ||
| setwd(oldwd) | ||
| dir_delete(newdir) | ||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated cleanup. |
||
| expect_error_free(create_package(".")) | ||
| }) | ||
|
|
||
| ## https://github.com/r-lib/usethis/issues/227 | ||
| test_that("create_* works w/ non-existing rel path and absolutizes it", { | ||
| ## take care to provide a **non-absolute** path | ||
| path_package <- path_file(file_temp(pattern = "aaa")) | ||
| path_package <- path_file(file_temp(pattern = "abc")) | ||
| withr::with_dir( | ||
| path_temp(), | ||
| create_package(path_package, rstudio = FALSE, open = FALSE) | ||
| ) | ||
| expect_true(dir_exists(path_temp(path_package))) | ||
|
|
||
| path_project <- path_file(file_temp(pattern = "aaa")) | ||
| path_project <- path_file(file_temp(pattern = "abc")) | ||
| withr::with_dir( | ||
| path_temp(), | ||
| create_project(path_project, rstudio = FALSE, open = FALSE) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new way we give ourselves of method of creating a nested project in tests. More self-explaining than previous reliance on
is_testing()plus a magic string in the project name.