Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for update collate #304

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: In-source documentation for R
Description: A Doxygen-like in-source documentation system
for Rd, collation, and NAMESPACE.
URL: https://github.com/klutometis/roxygen
Version: 4.0.2.9000
Version: 4.0.2.9001
License: GPL (>= 2)
Authors@R: c(
person("Hadley", "Wickham",, "[email protected]", c("aut", "cre", "cph")),
Expand Down
7 changes: 5 additions & 2 deletions R/roclet-collate.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ register.preref.parsers(parse.value, 'include')
#' (space separated) that should be loaded before the current file - these are
#' typically necessary if you're using S4 or RC classes (because super classes
#' must be defined before subclasses). If there are no \code{@@include} tags
#' Collate will be left blank, indicating that the order of loading does not
#' matter.
#' Collate will be left as is. Blank (ie Collate field absent) indicates that the
#' order of loading does not matter. Any manually entered filenames in the
#' Collate field will be left untouched, unless there are \code{@@include} tags
#' in the R files in which case they will be overwritten.
#'
#' This is not a roclet because roclets need the values of objects in a package,
#' and those values can not be generated unless you've sourced the files,
Expand All @@ -35,6 +37,7 @@ update_collate <- function(base_path) {
if (!is.null(collate)) {
collate <- paste0("'", collate, "'", collapse = " ")
}
else return()

desc_path <- file.path(base_path, "DESCRIPTION")
old <- read.description(desc_path)
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-collate-no-includes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
context("Collation with no @includes")

temp_copy_pkg <- function(pkg) {
file.copy(normalizePath(pkg), tempdir(), recursive = TRUE)
normalizePath(file.path(tempdir(), pkg))
}

test_that("Collate field unchanged when no @includes", {

# Make a temporary copy of the package template for this test,
# since if this test fails update_collate might have permanent side effects,
# namely changing the collate field in the DESCRIPTION file
# which would invalidate any future test runs
test_pkg <- temp_copy_pkg('testCollateNoIncludes')
on.exit(unlink(test_pkg, recursive = TRUE))

old_desc <- read.description(file.path(test_pkg, "DESCRIPTION"))
update_collate(test_pkg)
new_desc <- read.description(file.path(test_pkg, "DESCRIPTION"))

expect_named(old_desc,c("Package","Title","License","Description",
"Author","Maintainer","Version","Collate"))
expect_named(new_desc,c("Package","Title","License","Description",
"Author","Maintainer","Version","Collate"))
expect_identical(old_desc$Collate,new_desc$Collate)

})
8 changes: 8 additions & 0 deletions tests/testthat/testCollateNoIncludes/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: testCollateNoIncludes
Title: Test no change to Collate when there are no @includes
License: GPL-2
Description:
Author: Geoff <[email protected]>
Maintainer: Geoff <[email protected]>
Version: 0.1
Collate: b.r a.r
1 change: 1 addition & 0 deletions tests/testthat/testCollateNoIncludes/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[^\\.]")
4 changes: 4 additions & 0 deletions tests/testthat/testCollateNoIncludes/R/a.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Manually edited the Collate field in the DESCRIPTION file so this *should*
# run after b.r

a <- 1
1 change: 1 addition & 0 deletions tests/testthat/testCollateNoIncludes/R/b.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a <- 2