Skip to content

Commit 39e12bd

Browse files
authored
Only warn once when parsing namespace tags (#1870)
1 parent 342713a commit 39e12bd

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

R/namespace.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ namespace_imports <- function(base_path = ".") {
9393
paths <- package_files(base_path)
9494
parsed <- lapply(paths, parse, keep.source = TRUE)
9595
srcrefs <- lapply(parsed, utils::getSrcref)
96-
blocks <- unlist(lapply(srcrefs, namespace_imports_blocks), recursive = FALSE)
96+
# Ensure parse warnings only fire once during the main parse_package() pass
97+
suppressMessages(
98+
blocks <- unlist(
99+
lapply(srcrefs, namespace_imports_blocks),
100+
recursive = FALSE
101+
)
102+
)
97103

98104
blocks_to_ns(blocks, emptyenv())
99105
}

tests/testthat/_snaps/namespace.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# parsing warnings only fire once
2+
3+
Code
4+
roxygenise(path)
5+
Message
6+
Writing 'NAMESPACE'
7+
i Loading testNamespace
8+
x multiline.R:1: @importFrom must be only 1 line long, not 2.
9+
i The first line is "stats median"
10+
111
# @exportS3Method generates fully automatically
212

313
Code

tests/testthat/test-namespace.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ test_that("end-to-end NAMESPACE generation works", {
1616
)
1717
})
1818

19+
test_that("parsing warnings only fire once", {
20+
path <- local_package_copy(test_path("testNamespace"))
21+
write_lines(
22+
c("#' @importFrom stats median", "#' ave", "NULL"),
23+
file.path(path, "R", "multiline.R")
24+
)
25+
withr::defer(pkgload::unload("testNamespace"))
26+
27+
# Warning fires once (during the main parse_package() pass),
28+
# not also during update_namespace_imports()'s early pass.
29+
expect_snapshot(roxygenise(path))
30+
})
31+
32+
1933
# @export -----------------------------------------------------------------
2034

2135
test_that("export quote object name appropriate", {

0 commit comments

Comments
 (0)