|
1 | | -context("create") |
2 | | - |
3 | 1 | test_that("create_package() creates a package", { |
4 | 2 | dir <- scoped_temporary_package() |
5 | 3 | expect_true(possibly_in_proj(dir)) |
@@ -29,31 +27,59 @@ test_that("create functions return path to new proj, but restore active proj", { |
29 | 27 |
|
30 | 28 | test_that("nested package is disallowed, by default", { |
31 | 29 | dir <- scoped_temporary_package() |
32 | | - expect_usethis_error(scoped_temporary_package(path(dir, "abcde")), "anyway") |
| 30 | + expect_usethis_error(create_package(path(dir, "abcde")), "anyway") |
33 | 31 | }) |
34 | 32 |
|
35 | 33 | test_that("nested project is disallowed, by default", { |
36 | 34 | dir <- scoped_temporary_project() |
37 | | - expect_usethis_error(scoped_temporary_project(path(dir, "abcde")), "anyway") |
| 35 | + expect_usethis_error(create_project(path(dir, "abcde")), "anyway") |
| 36 | +}) |
| 37 | + |
| 38 | +test_that("nested package can be created if user really, really wants to", { |
| 39 | + parent <- scoped_temporary_package() |
| 40 | + with_mock( |
| 41 | + # since user can't approve interactively, use the backdoor |
| 42 | + `usethis:::allow_nested_project` = function() TRUE, |
| 43 | + child <- create_package(path(parent, "fghijk")) |
| 44 | + ) |
| 45 | + expect_true(possibly_in_proj(child)) |
| 46 | + expect_true(is_package(child)) |
| 47 | +}) |
| 48 | + |
| 49 | +test_that("nested project can be created if user really, really wants to", { |
| 50 | + parent <- scoped_temporary_project() |
| 51 | + with_mock( |
| 52 | + # since user can't approve interactively, use the backdoor |
| 53 | + `usethis:::allow_nested_project` = function() TRUE, |
| 54 | + child <- create_project(path(parent, "fghijk")) |
| 55 | + ) |
| 56 | + expect_true(possibly_in_proj(child)) |
| 57 | + expect_false(is_package(child)) |
38 | 58 | }) |
39 | 59 |
|
40 | 60 | test_that("can create package in current directory", { |
41 | | - dir <- dir_create(path(file_temp(), "mypackage")) |
42 | | - withr::local_dir(dir) |
| 61 | + # doing this "by hand" vs. via withr because Windows appears to be unwilling |
| 62 | + # to delete current working directory |
| 63 | + newdir <- dir_create(path(file_temp(), "mypackage")) |
| 64 | + oldwd <- setwd(newdir) |
| 65 | + on.exit({ |
| 66 | + setwd(oldwd) |
| 67 | + dir_delete(newdir) |
| 68 | + }) |
43 | 69 | expect_error_free(create_package(".")) |
44 | 70 | }) |
45 | 71 |
|
46 | 72 | ## https://github.com/r-lib/usethis/issues/227 |
47 | 73 | test_that("create_* works w/ non-existing rel path and absolutizes it", { |
48 | 74 | ## take care to provide a **non-absolute** path |
49 | | - path_package <- path_file(file_temp(pattern = "aaa")) |
| 75 | + path_package <- path_file(file_temp(pattern = "abc")) |
50 | 76 | withr::with_dir( |
51 | 77 | path_temp(), |
52 | 78 | create_package(path_package, rstudio = FALSE, open = FALSE) |
53 | 79 | ) |
54 | 80 | expect_true(dir_exists(path_temp(path_package))) |
55 | 81 |
|
56 | | - path_project <- path_file(file_temp(pattern = "aaa")) |
| 82 | + path_project <- path_file(file_temp(pattern = "abc")) |
57 | 83 | withr::with_dir( |
58 | 84 | path_temp(), |
59 | 85 | create_project(path_project, rstudio = FALSE, open = FALSE) |
|
0 commit comments