Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Write tests and fix bugs
  • Loading branch information
hadley committed Aug 18, 2017
commit e364e45d715cea453194e62a90751d6625b8aae9
10 changes: 8 additions & 2 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ block_evaluate <- function(block, env, registry) {
env = env,
tag_name = "@eval"
)
results <- lapply(results, function(x) paste0("#' ", x))
results <- lapply(results, function(x) {
if (is.null(x)) {
character()
} else {
paste0("#' ", x)
}
})

# Tokenise and parse
tokens <- lapply(results, tokenise_block,
Expand All @@ -162,7 +168,7 @@ block_evaluate <- function(block, env, registry) {
out[is_eval] <- tags
names(out)[is_eval] <- ""

unlist(out, recursive = FALSE)
compact(unlist(out, recursive = FALSE))
}

parse_description <- function(tags) {
Expand Down
54 changes: 54 additions & 0 deletions tests/testthat/test-eval.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
context("eval")

test_that("evaluation occurs during parsing", {
out <- roc_proc_text(rd_roclet(), "
foo <- function() c('@name a', '@title a')
#' @eval foo()
NULL")[[1]]

expect_equal(out$get_field("title")$values, "a")
expect_equal(out$filename, "a.Rd")
})

test_that("errors are propagated", {
expect_warning(
roc_proc_text(rd_roclet(), "
foo <- function() stop('Uhoh')
#' @eval foo()
NULL"
),
"@eval failed with error"
)
})

test_that("must return non-NA string", {
expect_warning(
roc_proc_text(rd_roclet(), "
foo <- function() NA
#' @eval foo()
NULL"
),
"@eval did not evaluate to a string"
)

expect_warning(
roc_proc_text(rd_roclet(), "
foo <- function() NA_character_
#' @eval foo()
NULL"
),
"@eval result contained NA"
)
})


test_that("also works with namespace roclet", {
out <- roc_proc_text(namespace_roclet(), "
foo <- function() '@export a'
#' @eval foo()
#' @name a
#' @title a
NULL")

expect_equal(out, "export(a)")
})