Skip to content

Commit 4664b5d

Browse files
committed
Fixed tests
1 parent 82a0525 commit 4664b5d

3 files changed

Lines changed: 56 additions & 14 deletions

File tree

R/build-readme.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ build_md <- function(
5555
}
5656

5757
local_install(pkg, quiet = TRUE)
58+
env <- r_env_vars()
5859

5960
for (path in paths) {
6061
cli::cli_inform(c(i = "Building {.path {path}}"))
@@ -68,7 +69,8 @@ build_md <- function(
6869
),
6970
show = TRUE,
7071
spinner = FALSE,
71-
stderr = "2>&1"
72+
stderr = "2>&1",
73+
env = env
7274
)
7375
} else {
7476
callr::r_safe(
@@ -81,7 +83,8 @@ build_md <- function(
8183
),
8284
show = TRUE,
8385
spinner = FALSE,
84-
stderr = "2>&1"
86+
stderr = "2>&1",
87+
env = env
8588
)
8689
}
8790
}
@@ -108,7 +111,7 @@ build_rmd <- function(...) {
108111
build_readme <- function(path = ".", quiet = TRUE, ...) {
109112
pkg <- as.package(path)
110113

111-
regexp <- paste0(path_file(pkg$path), "/(inst/)?readme[.](r|q)md")
114+
regexp <- paste0(path_file(pkg$path), "/(inst/)?readme[.](r|q)md$")
112115
readme_path <- path_abs(
113116
dir_ls(
114117
pkg$path,

tests/testthat/_snaps/build-readme.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# useful errors if too few or too many
1+
# useful errors if too few or too many (Rmd)
22

33
Code
44
build_readme(pkg)
@@ -14,3 +14,27 @@
1414
Error in `build_readme()`:
1515
! Can't have multiple README sources: 'README.Rmd', 'inst/README.Rmd', 'README.qmd', or 'inst/README.qmd'.
1616

17+
# useful errors if too few or too many (qmd)
18+
19+
Code
20+
build_readme(pkg)
21+
Condition
22+
Error in `build_readme()`:
23+
! Can't find 'README.Rmd', 'inst/README.Rmd', 'README.qmd', or 'inst/README.qmd'.
24+
25+
---
26+
27+
Code
28+
build_readme(pkg)
29+
Condition
30+
Error in `build_readme()`:
31+
! Can't have multiple README sources: 'README.Rmd', 'inst/README.Rmd', 'README.qmd', or 'inst/README.qmd'.
32+
33+
# useful errors if too many--mixed Quarto and Rmd
34+
35+
Code
36+
build_readme(pkg)
37+
Condition
38+
Error in `build_readme()`:
39+
! Can't have multiple README sources: 'README.Rmd', 'inst/README.Rmd', 'README.qmd', or 'inst/README.qmd'.
40+

tests/testthat/test-build-readme.R

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("can build README in root directory", {
1+
test_that("can build README in root directory (Rmd)", {
22
skip_on_cran()
33

44
pkg <- local_package_create()
@@ -9,7 +9,7 @@ test_that("can build README in root directory", {
99
expect_false(file_exists(path(pkg, "README.html")))
1010
})
1111

12-
test_that("can build README in inst/", {
12+
test_that("can build README in inst/ (Rmd)", {
1313
skip_on_cran()
1414

1515
pkg <- local_package_create()
@@ -27,7 +27,7 @@ test_that("can build README in inst/", {
2727
expect_false(file_exists(path(pkg, "inst", "README.html")))
2828
})
2929

30-
test_that("can build Quarto README in root directory", {
30+
test_that("can build README in root directory (qmd)", {
3131
skip_on_cran()
3232

3333
pkg <- local_package_create()
@@ -38,7 +38,7 @@ test_that("can build Quarto README in root directory", {
3838
expect_false(file_exists(path(pkg, "README.html")))
3939
})
4040

41-
test_that("can build Quarto README in inst/", {
41+
test_that("can build README in inst/ (qmd)", {
4242
skip_on_cran()
4343

4444
pkg <- local_package_create()
@@ -51,19 +51,28 @@ test_that("can build Quarto README in inst/", {
5151

5252
suppressMessages(build_readme(pkg))
5353
expect_true(file_exists(path(pkg, "inst", "README.md")))
54-
expect_false(file_exists(path(pkg, "README.Rmd")))
54+
expect_false(file_exists(path(pkg, "README.qmd")))
5555
expect_false(file_exists(path(pkg, "README.md")))
5656
expect_false(file_exists(path(pkg, "inst", "README.html")))
5757
})
5858

59-
test_that("useful errors if too few or too many", {
59+
test_that("useful errors if too few or too many (Rmd)", {
60+
skip_on_cran()
61+
6062
pkg <- local_package_create()
6163
expect_snapshot(build_readme(pkg), error = TRUE)
6264

6365
suppressMessages(usethis::with_project(pkg, use_readme_rmd()))
6466
dir_create(pkg, "inst")
6567
file_copy(path(pkg, "README.Rmd"), path(pkg, "inst", "README.Rmd"))
6668
expect_snapshot(build_readme(pkg), error = TRUE)
69+
})
70+
71+
test_that("useful errors if too few or too many (qmd)", {
72+
skip_on_cran()
73+
74+
pkg <- local_package_create()
75+
expect_snapshot(build_readme(pkg), error = TRUE)
6776

6877
suppressMessages(usethis::with_project(pkg, use_readme_qmd()))
6978
dir_create(pkg, "inst")
@@ -72,12 +81,18 @@ test_that("useful errors if too few or too many", {
7281
})
7382

7483
test_that("useful errors if too many--mixed Quarto and Rmd", {
75-
suppressMessages(usethis::with_project(pkg, use_readme_rmd()))
76-
suppressMessages(usethis::with_project(pkg, use_readme_qmd()))
84+
skip_on_cran()
85+
86+
pkg <- local_package_create()
87+
88+
suppressMessages(usethis::with_project(pkg, use_readme_rmd(open = FALSE)))
89+
90+
file_copy(path(pkg, "README.Rmd"), path(pkg, "README.qmd"))
91+
7792
expect_snapshot(build_readme(pkg), error = TRUE)
7893
})
7994

80-
test_that("don't error for README in another directory", {
95+
test_that("don't error for README in another directory (Rmd)", {
8196
skip_on_cran()
8297

8398
pkg <- local_package_create()
@@ -88,7 +103,7 @@ test_that("don't error for README in another directory", {
88103
expect_no_error(suppressMessages(build_readme(pkg)))
89104
})
90105

91-
test_that("don't error for Quarto README in another directory", {
106+
test_that("don't error for README in another directory (qmd)", {
92107
skip_on_cran()
93108

94109
pkg <- local_package_create()

0 commit comments

Comments
 (0)