Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion R/parseFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
msg <- paste0(msg, " (line numbers refer to the extracted examples)")
else if (!identical(infile, outfile))
msg <- paste0(msg, " (line numbers refer to the tangled R code)")
pd <- getParseData(parse(text = "", keep.source = TRUE))
pd <- .emptyParseData()
attr(pd, "parse_error") <- msg
pd
}

## zero-row data frame with the columns of utils::getParseData()
.emptyParseData <- function() {
data.frame(
line1 = integer(0L), col1 = integer(0L),
line2 = integer(0L), col2 = integer(0L),
id = integer(0L), parent = integer(0L),
token = character(0L), terminal = logical(0L),
text = character(0L)
)
}

parseFile <- function(.BiocPackage, infile) {
dir.create(parse_dir <- tempfile())
outfile <- file.path(parse_dir, "parseFile.tmp")
Expand Down
59 changes: 59 additions & 0 deletions inst/tinytest/test_BiocCheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -739,13 +739,72 @@ temp_dir <- tempfile()
.BiocCheck$zero()
df <- BiocCheck:::parseFile(.bioctest, .bioctest$manSources)
expect_identical(nrow(df), 0L)
expect_identical(
names(df),
names(getParseData(parse(text = "1", keep.source = TRUE)))
)
expect_true(grepl("unexpected end of input", attr(df, "parse_error")))
expect_false(grepl("parseFile.tmp", attr(df, "parse_error"), fixed = TRUE))
expect_true(grepl("extracted examples", attr(df, "parse_error"), fixed = TRUE))
parsedCode <- BiocCheck:::parseFiles(.bioctest)
expect_false(any(grepl("broken.Rd", names(parsedCode), fixed = TRUE)))
errs <- unlist(.BiocCheck$get("error"), use.names = FALSE)
expect_true(any(grepl("man/broken.Rd: broken.Rd:", errs, fixed = TRUE)))
checkCounter("Unparseable Rd example didn't cause error!")
unlink(temp_dir, recursive = TRUE)

## unparseable R files are reported by their own name
temp_dir <- tempfile()
.bioctest <- create_test_package(
test_dir = temp_dir,
extraActions = function(path) {
writeLines("f <- function(x,", file.path(path, "R", "broken.R"))
writeLines("g <- function() 1", file.path(path, "R", "good.R"))
}
)
.BiocCheck$zero()
rfile <- grep("broken.R$", .bioctest$RSources, value = TRUE)
df <- BiocCheck:::parseFile(.bioctest, rfile)
expect_identical(nrow(df), 0L)
expect_true(grepl("^broken.R:", attr(df, "parse_error")))
expect_false(grepl("line numbers refer", attr(df, "parse_error"), fixed = TRUE))
parsedCode <- BiocCheck:::parseFiles(.bioctest)
expect_false(any(grepl("broken.R", names(parsedCode), fixed = TRUE)))
expect_true(any(grepl("good.R", names(parsedCode), fixed = TRUE)))
errs <- unlist(.BiocCheck$get("error"), use.names = FALSE)
expect_true(any(grepl("R/broken.R: broken.R:", errs, fixed = TRUE)))
checkCounter("Unparseable R file didn't cause error!")
unlink(temp_dir, recursive = TRUE)

## unparseable vignette code is reported, and vignette checks skip the file
temp_dir <- tempfile()
.bioctest <- create_test_package(
test_dir = temp_dir,
description = list(VignetteBuilder = "knitr", Suggests = "knitr"),
extraActions = function(path) {
dir.create(file.path(path, "vignettes"))
writeLines(c(
"---", "title: broken", "vignette: >",
" %\\VignetteIndexEntry{broken}",
" %\\VignetteEngine{knitr::rmarkdown}", "---", "",
"```{r}", "f <- function(x,", "```"
), file.path(path, "vignettes", "broken.Rmd"))
}
)
.BiocCheck$zero()
df <- BiocCheck:::parseFile(.bioctest, .bioctest$VigSources)
expect_identical(nrow(df), 0L)
expect_true(grepl("tangled R code", attr(df, "parse_error"), fixed = TRUE))
expect_false(grepl("parseFile.tmp", attr(df, "parse_error"), fixed = TRUE))
parsedCode <- BiocCheck:::parseFiles(.bioctest)
expect_false(any(grepl("broken.Rmd", names(parsedCode), fixed = TRUE)))
checkCounter("Unparseable vignette code didn't cause error!")
## checks that parse vignettes on their own skip the broken file
expect_silent(BiocCheck:::checkVigSessionInfo(.bioctest))
expect_silent(BiocCheck:::checkVigEvalAllFalse(.bioctest))
expect_true(stillZero())
unlink(temp_dir, recursive = TRUE)

# checkForBrowser ---------------------------------------------------------
cli::cli_h3("checkForBrowser")

Expand Down