Skip to content

Commit f70be76

Browse files
committed
Support NEWS in Rd and md formats and under inst
Mirrors the search path documented in utils::news() for NEWS files. Uses the internal machinery of tools to build news databases.
1 parent bfb4209 commit f70be76

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

R/show-news.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@
77
#' @export
88
show_news <- function(pkg = ".", latest = TRUE, ...) {
99
pkg <- as.package(pkg)
10-
news_path <- path(pkg$path, "NEWS")
1110

12-
if (!file_exists(news_path)) {
11+
news_path <- path_abs(c(
12+
file.path(pkg$path, "inst", "NEWS.Rd"),
13+
file.path(pkg$path, "NEWS.md"),
14+
file.path(pkg$path, "NEWS"),
15+
file.path(pkg$path, "inst", "NEWS")
16+
))
17+
news_path <- news_path[file_exists(news_path)]
18+
19+
if (length(news_path) == 0) {
1320
cli::cli_abort("No NEWS found")
1421
}
1522

23+
news_db <- switch (path_ext(news_path),
24+
Rd = ("tools" %:::% ".build_news_db_from_package_NEWS_Rd")(news_path),
25+
md = ("tools" %:::% ".build_news_db_from_package_NEWS_md")(news_path),
26+
("tools" %:::% ".news_reader_default")(news_path)
27+
)
28+
1629
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
1730

18-
out <- utils::news(..., db = ("tools" %:::% ".news_reader_default")(news_path))
31+
out <- utils::news(..., db = news_db)
1932
if (latest) {
2033
ver <- numeric_version(out$Version)
2134
recent <- ver == max(ver)

tests/testthat/test-show-news.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
test_that("can read NEWS.md in root directory", {
2+
skip_on_cran()
3+
4+
pkg <- local_package_create()
5+
suppressMessages(usethis::with_project(pkg, use_news_md()))
6+
7+
expect_no_error(show_news(pkg))
8+
})
9+
10+
test_that("can read NEWS.Rd in inst directory", {
11+
skip_on_cran()
12+
13+
pkg <- local_package_create()
14+
15+
dir_create(pkg, "inst")
16+
write(r"[\name{NEWS}
17+
\title{News for Package 'test'}
18+
19+
\section{CHANGES IN test VERSION 0.0.1}{
20+
\itemize{
21+
\item First version
22+
}
23+
}]", path(pkg, "inst", "NEWS.Rd"))
24+
25+
expect_no_error(show_news(pkg))
26+
})
27+
28+
test_that("can read NEWS in inst directory", {
29+
skip_on_cran()
30+
31+
pkg <- local_package_create()
32+
33+
dir_create(pkg, "inst")
34+
write("v0.1-1 (2024-01-09)\n\n o first release", path(pkg, "inst", "NEWS"))
35+
36+
expect_no_error(show_news(pkg))
37+
})
38+
39+
test_that("fails when NEWS is missing", {
40+
skip_on_cran()
41+
42+
pkg <- local_package_create()
43+
44+
expect_error(show_news(pkg))
45+
})
46+
47+
test_that("fails when NEWS is improperly formatted", {
48+
skip_on_cran()
49+
50+
pkg <- local_package_create()
51+
suppressMessages(usethis::with_project(pkg, use_news_md()))
52+
53+
dir_create(pkg, "inst")
54+
file_create(pkg, "inst", "NEWS.Rd")
55+
56+
expect_error(show_news(pkg))
57+
})

0 commit comments

Comments
 (0)