Skip to content

Commit

Permalink
split testthat fns into R/testthat-fns.R
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 8, 2022
1 parent 52a2678 commit dd0a02f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: typetracer
Title: Trace Function Parameter Types
Version: 0.1.1.001
Version: 0.1.1.002
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
42 changes: 42 additions & 0 deletions R/testthat-fns.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

testthat_is_parallel <- function (pkg_dir) {

flist <- list.files (pkg_dir, recursive = TRUE, full.names = TRUE)
desc <- grep ("DESCRIPTION$", flist, value = TRUE)
if (length (desc) != 1L) {
return (FALSE)
}
desc <- read.dcf (desc)
field <- "Config/testthat/parallel"
if (!field %in% colnames (desc)) {
return (FALSE)
}
ret <- as.logical (desc [1L, field])
ret <- ifelse (is.na (ret), FALSE, ret)

return (ret)
}

#' Remove testthat "parallel = true" config entry from DESCRIPTION
#'
#' Tests can not be traced in parallel (issue#10), so this line needs to be
#' removed in order to enable tracing.
#' @noRd
rm_testthat_parallel <- function (pkg_dir) {

message (
"Tests can not be traced with testthat tests run in parallel; ",
"parallel testing has been temporarily deactivated."
)

flist <- list.files (pkg_dir, recursive = TRUE, full.names = TRUE)
desc_file <- grep ("DESCRIPTION$", flist, value = TRUE)
if (length (desc_file) != 1L) {
return (NULL)
}
desc <- brio::read_lines (desc_file)
field <- "Config/testthat/parallel"
desc <- desc [-grep (field, desc, fixed = TRUE)]

brio::write_lines (desc, desc_file)
}
43 changes: 1 addition & 42 deletions R/trace-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ trace_package <- function (package = NULL,

if ("examples" %in% types) {
trace_names <- trace_package_exs (package, functions)
traces <- list_traces ()
}
if ("tests" %in% types) {
if (testthat_is_parallel (pkg_dir) && !pre_installed) {
Expand Down Expand Up @@ -258,48 +259,6 @@ trace_package_tests <- function (package, pkg_dir = NULL,
return (test_trace_numbers)
}

testthat_is_parallel <- function (pkg_dir) {

flist <- list.files (pkg_dir, recursive = TRUE, full.names = TRUE)
desc <- grep ("DESCRIPTION$", flist, value = TRUE)
if (length (desc) != 1L) {
return (FALSE)
}
desc <- read.dcf (desc)
field <- "Config/testthat/parallel"
if (!field %in% colnames (desc)) {
return (FALSE)
}
ret <- as.logical (desc [1L, field])
ret <- ifelse (is.na (ret), FALSE, ret)

return (ret)
}

#' Remove testthat "parallel = true" config entry from DESCRIPTION
#'
#' Tests can not be traced in parallel (issue#10), so this line needs to be
#' removed in order to enable tracing.
#' @noRd
rm_testthat_parallel <- function (pkg_dir) {

message (
"Tests can not be traced with testthat tests run in parallel; ",
"parallel testing has been temporarily deactivated."
)

flist <- list.files (pkg_dir, recursive = TRUE, full.names = TRUE)
desc_file <- grep ("DESCRIPTION$", flist, value = TRUE)
if (length (desc_file) != 1L) {
return (NULL)
}
desc <- brio::read_lines (desc_file)
field <- "Config/testthat/parallel"
desc <- desc [-grep (field, desc, fixed = TRUE)]

brio::write_lines (desc, desc_file)
}

get_pkg_examples <- function (package) {

rd <- tools::Rd_db (package)
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/mpadge/typetracer",
"issueTracker": "https://github.com/mpadge/typetracer/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.1.1.001",
"version": "0.1.1.002",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit dd0a02f

Please sign in to comment.