Skip to content
Open
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
21 changes: 21 additions & 0 deletions R/pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,24 @@ pkg_version <- function(pkgdir) {
pkg_bug_reports <- function(pkgdir) {
read.dcf(file.path(pkgdir, "DESCRIPTION"))[, "BugReports"][[1]]
}

# Helper for testing ------------------------------------------------------

local_package <- function(fields = list(), env = parent.frame()) {
dir <- tempfile()
dir.create(dir)
dir.create(file.path(dir, "revdep"))
withr::defer(unlink(dir, recursive = TRUE), envir = env)

defaults <- list(
Package = "Test",
Version = "1.0.0"
)

fields <- utils::modifyList(defaults, fields)
write.dcf(fields, file.path(dir, "DESCRIPTION"))

db_setup(dir)

dir
}
17 changes: 17 additions & 0 deletions tests/testthat/test-pkg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("can retrieve basic package metadata", {
pkg <- local_package(list(
Package = "test",
Version = "0.0.1",
BugReports = "BUGS"
))

expect_equal(pkg_name(pkg), "test")
expect_equal(pkg_version(pkg), "0.0.1")
expect_equal(pkg_bug_reports(pkg), "BUGS")
})

test_that("pkg_check validates its inputs", {
expect_error(pkg_check(1), "string")
expect_error(pkg_check("NOT-FOUND"), "existing directory")
expect_error(pkg_check("."), "DESCRIPTION")
})
13 changes: 13 additions & 0 deletions tests/testthat/test-todo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_that("can add and remove from db", {
pkg <- local_package()

todo <- revdep_todo(pkg)
expect_equal(nrow(todo), 0)

todo <- revdep_add(pkg, c("x", "y"))
expect_equal(todo$package, c("x", "y"))

todo <- revdep_rm(pkg, "x")
expect_equal(todo$package, c("x", "y"))
expect_equal(todo$status, c("ignore", "todo"))
})