-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support readme's in inst/readme again
This used to work, but I think was accidentally broken along the way. Fixes #2333
- Loading branch information
Showing
8 changed files
with
84 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This is a trimmed down version of create_local_thing from usethis | ||
# https://github.com/jimhester/usethis/blob/de8aa116820a8e54f2f952b341039985d78d0352/tests/testthat/helper.R#L28-L68 | ||
create_local_package <- function() { | ||
old_project <- asNamespace("usethis")$proj_get_() # this could be `NULL`, i.e. no active project | ||
old_wd <- getwd() | ||
dir <- file_temp() | ||
|
||
withr::defer(envir = parent.frame(), { | ||
proj_set(old_project, force = TRUE) | ||
dir_delete(dir) | ||
setwd(old_wd) | ||
}) | ||
|
||
usethis::ui_silence({ | ||
create_package(dir, rstudio = FALSE, open = FALSE, check_name = FALSE) | ||
proj_set(dir) | ||
}) | ||
|
||
proj_dir <- proj_get() | ||
setwd(proj_dir) | ||
|
||
invisible(proj_dir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
test_that("Package readme can be built ", { | ||
test_that("Package readme in root directory can be built ", { | ||
skip_on_cran() | ||
|
||
on.exit({ | ||
file_delete("testReadme/README.md") | ||
dir_delete("testReadme/man/figures") | ||
}) | ||
pkg_path <- create_local_package() | ||
|
||
suppressMessages(build_readme("testReadme")) | ||
# errors if no readme found | ||
expect_error( | ||
build_readme(pkg_path), | ||
"Can't find a 'README.Rmd'" | ||
) | ||
|
||
expect_true(file_exists(path("testReadme", "README.md"))) | ||
expect_false(file_exists(path("testReadme", "README.html"))) | ||
suppressMessages(use_readme_rmd()) | ||
|
||
suppressMessages(build_readme(pkg_path)) | ||
|
||
expect_true(file_exists(path(pkg_path, "README.md"))) | ||
expect_false(file_exists(path(pkg_path, "README.html"))) | ||
}) | ||
|
||
test_that("Package readme in inst/ can be built ", { | ||
skip_on_cran() | ||
|
||
pkg_path <- create_local_package() | ||
suppressMessages(use_readme_rmd()) | ||
dir_create(pkg_path, "inst") | ||
file_copy( | ||
path(pkg_path, "README.Rmd"), | ||
path(pkg_path, "inst", "README.Rmd") | ||
) | ||
|
||
# errors if both a root readme and inst readme found | ||
expect_error( | ||
build_readme(pkg_path), | ||
"Can't have both" | ||
) | ||
|
||
file_delete(path(pkg_path, "README.Rmd")) | ||
|
||
suppressMessages(build_readme(pkg_path)) | ||
|
||
expect_true(file_exists(path(pkg_path, "inst", "README.md"))) | ||
expect_false(file_exists(path(pkg_path, "README.Rmd"))) | ||
expect_false(file_exists(path(pkg_path, "README.md"))) | ||
expect_false(file_exists(path(pkg_path, "inst", "README.html"))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.