From 01b1249887e85879faa146e54e86a51d91121757 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 19 Jan 2023 14:25:07 +0800 Subject: [PATCH 01/24] increment version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 76f05aae..f65346f8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9000 +Version: 3.6.0.9100 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), From a19ffd023def08931d54daccff0261ea834e607b Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 19 Jan 2023 14:49:57 +0800 Subject: [PATCH 02/24] an app with box modules example --- tests/testthat/Testbox/app/app.R | 6 ++++++ tests/testthat/Testbox/app/modules/module.R | 10 ++++++++++ tests/testthat/Testbox/tests/testthat.R | 6 ++++++ .../testthat/Testbox/tests/testthat/test-module.R | 15 +++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 tests/testthat/Testbox/app/app.R create mode 100644 tests/testthat/Testbox/app/modules/module.R create mode 100644 tests/testthat/Testbox/tests/testthat.R create mode 100644 tests/testthat/Testbox/tests/testthat/test-module.R diff --git a/tests/testthat/Testbox/app/app.R b/tests/testthat/Testbox/app/app.R new file mode 100644 index 00000000..1bbc51fc --- /dev/null +++ b/tests/testthat/Testbox/app/app.R @@ -0,0 +1,6 @@ +options(box.path = file.path(getwd())) +rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) + +box::use( + app/modules/module +) diff --git a/tests/testthat/Testbox/app/modules/module.R b/tests/testthat/Testbox/app/modules/module.R new file mode 100644 index 00000000..a33a454e --- /dev/null +++ b/tests/testthat/Testbox/app/modules/module.R @@ -0,0 +1,10 @@ +#' an example function +#' +#' @export +a <- function(x) { + if (x <= 1) { + 1 + } else { + 2 + } +} diff --git a/tests/testthat/Testbox/tests/testthat.R b/tests/testthat/Testbox/tests/testthat.R new file mode 100644 index 00000000..39706593 --- /dev/null +++ b/tests/testthat/Testbox/tests/testthat.R @@ -0,0 +1,6 @@ +options(box.path = file.path(getwd())) +rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) + +library(testthat) + +test_dir("tests/testthat") diff --git a/tests/testthat/Testbox/tests/testthat/test-module.R b/tests/testthat/Testbox/tests/testthat/test-module.R new file mode 100644 index 00000000..0ffbd392 --- /dev/null +++ b/tests/testthat/Testbox/tests/testthat/test-module.R @@ -0,0 +1,15 @@ +box::use( + testthat[test_that, expect_equal] +) + +box::use( + app/modules/module +) + +test_that("regular function `a` works as expected", { + expect_equal(module$a(1), 1) + expect_equal(module$a(2), 2) + expect_equal(module$a(3), 2) + expect_equal(module$a(4), 2) + expect_equal(module$a(0), 1) +}) From e9fe6ffa1b7a1354f0f27c9d18b8621abcc8006a Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 19 Jan 2023 14:55:27 +0800 Subject: [PATCH 03/24] boilerplate for box coverage test --- tests/testthat/test-box.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/testthat/test-box.R diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R new file mode 100644 index 00000000..345c1c9e --- /dev/null +++ b/tests/testthat/test-box.R @@ -0,0 +1,12 @@ +context("box") + +test_that("box module coverage is reported", { + withr::with_dir("tests/testthat/Testbox", { + cov <- as.data.frame(file_coverage( + source_files = "app/app.R", + test_files = list.files("tests/testthat", full.name = TRUE))) + + expect_true("a" %in% cov$functions) + }) + +}) From 1a0c5b7edd8a266a533043fdbfc83532c71f458f Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 19 Jan 2023 15:02:54 +0800 Subject: [PATCH 04/24] ready to write box support --- R/box.R | 3 +++ R/covr.R | 1 + tests/testthat/test-box.R | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 R/box.R diff --git a/R/box.R b/R/box.R new file mode 100644 index 00000000..10759e7a --- /dev/null +++ b/R/box.R @@ -0,0 +1,3 @@ +replacements_box <- function(env) { + +} diff --git a/R/covr.R b/R/covr.R index b8106efe..ee7b155f 100644 --- a/R/covr.R +++ b/R/covr.R @@ -93,6 +93,7 @@ trace_environment <- function(env) { replacements_S4(env), replacements_RC(env), replacements_R6(env), + replacements_box(env), lapply(ls(env, all.names = TRUE), replacement, env = env))) lapply(the$replacements, replace) diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R index 345c1c9e..5a45759d 100644 --- a/tests/testthat/test-box.R +++ b/tests/testthat/test-box.R @@ -1,7 +1,7 @@ context("box") test_that("box module coverage is reported", { - withr::with_dir("tests/testthat/Testbox", { + withr::with_dir("./Testbox", { cov <- as.data.frame(file_coverage( source_files = "app/app.R", test_files = list.files("tests/testthat", full.name = TRUE))) From 337d1ccb34bce83aa5423c70a1ba6535a8458db1 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 19 Jan 2023 18:39:38 +0800 Subject: [PATCH 05/24] now works with basic box modules --- R/box.R | 16 +++++++++++++++- tests/testthat/test-box.R | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/R/box.R b/R/box.R index 10759e7a..7bc4c0c9 100644 --- a/R/box.R +++ b/R/box.R @@ -1,3 +1,17 @@ replacements_box <- function(env) { - + unlist(recursive = FALSE, eapply(env, all.names = TRUE, + function(obj) { + if (inherits(obj, "box$mod")) { + lapply(names(obj), + function(f_name) { + f <- get(f_name, obj) + if (inherits(f, "function")) { + replacement(f_name, env = obj, target_value = f) + } + } + ) + } + } + ) + ) } diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R index 5a45759d..fb894fd3 100644 --- a/tests/testthat/test-box.R +++ b/tests/testthat/test-box.R @@ -6,6 +6,9 @@ test_that("box module coverage is reported", { source_files = "app/app.R", test_files = list.files("tests/testthat", full.name = TRUE))) + expect_equal(cov$value, c(5, 2, 3)) + expect_equal(cov$first_line, c(5, 6, 8)) + expect_equal(cov$last_line, c(5, 6, 8)) expect_true("a" %in% cov$functions) }) From 7d4a35a9266d3a9f28e6ab820ec96c9500e2964f Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 20 Jan 2023 12:24:53 +0800 Subject: [PATCH 06/24] Forgot an s Co-authored-by: Jakub Nowicki --- tests/testthat/test-box.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R index fb894fd3..50aad453 100644 --- a/tests/testthat/test-box.R +++ b/tests/testthat/test-box.R @@ -4,7 +4,7 @@ test_that("box module coverage is reported", { withr::with_dir("./Testbox", { cov <- as.data.frame(file_coverage( source_files = "app/app.R", - test_files = list.files("tests/testthat", full.name = TRUE))) + test_files = list.files("tests/testthat", full.names = TRUE))) expect_equal(cov$value, c(5, 2, 3)) expect_equal(cov$first_line, c(5, 6, 8)) From d1f485c7418537578a2781890ef6768301b192da Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 20 Jan 2023 12:25:15 +0800 Subject: [PATCH 07/24] Smaller version increment as suggested Co-authored-by: Jakub Nowicki --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f65346f8..3413f96c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9100 +Version: 3.6.0.9001 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), From 95b51d7614cb21b023eb52382e2ac15cfa100a55 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 20 Jan 2023 13:25:24 +0800 Subject: [PATCH 08/24] got it to work! --- DESCRIPTION | 2 +- R/box.R | 5 +++-- tests/testthat/Testbox/app/modules/module.R | 4 ++++ tests/testthat/Testbox/tests/testthat/test-module.R | 8 ++++++++ tests/testthat/test-box.R | 9 +++++---- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3413f96c..501a01bd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9001 +Version: 3.6.0.9002 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), diff --git a/R/box.R b/R/box.R index 7bc4c0c9..4d07b900 100644 --- a/R/box.R +++ b/R/box.R @@ -2,9 +2,10 @@ replacements_box <- function(env) { unlist(recursive = FALSE, eapply(env, all.names = TRUE, function(obj) { if (inherits(obj, "box$mod")) { - lapply(names(obj), + obj_impl <- attr(obj, "namespace") + lapply(ls(obj_impl), function(f_name) { - f <- get(f_name, obj) + f <- get(f_name, obj_impl) if (inherits(f, "function")) { replacement(f_name, env = obj, target_value = f) } diff --git a/tests/testthat/Testbox/app/modules/module.R b/tests/testthat/Testbox/app/modules/module.R index a33a454e..2fa4982f 100644 --- a/tests/testthat/Testbox/app/modules/module.R +++ b/tests/testthat/Testbox/app/modules/module.R @@ -8,3 +8,7 @@ a <- function(x) { 2 } } + +private_function <- function(x) { + x ^ 2 +} diff --git a/tests/testthat/Testbox/tests/testthat/test-module.R b/tests/testthat/Testbox/tests/testthat/test-module.R index 0ffbd392..1a8b092c 100644 --- a/tests/testthat/Testbox/tests/testthat/test-module.R +++ b/tests/testthat/Testbox/tests/testthat/test-module.R @@ -6,6 +6,8 @@ box::use( app/modules/module ) +impl <- attr(module, "namespace") + test_that("regular function `a` works as expected", { expect_equal(module$a(1), 1) expect_equal(module$a(2), 2) @@ -13,3 +15,9 @@ test_that("regular function `a` works as expected", { expect_equal(module$a(4), 2) expect_equal(module$a(0), 1) }) + +test_that("private function works as expected", { + expect_equal(impl$private_function(2), 4) + expect_equal(impl$private_function(3), 9) + expect_equal(impl$private_function(4), 16) +}) diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R index 50aad453..3e2726fe 100644 --- a/tests/testthat/test-box.R +++ b/tests/testthat/test-box.R @@ -1,15 +1,16 @@ context("box") test_that("box module coverage is reported", { - withr::with_dir("./Testbox", { + withr::with_dir("Testbox", { cov <- as.data.frame(file_coverage( source_files = "app/app.R", test_files = list.files("tests/testthat", full.names = TRUE))) - expect_equal(cov$value, c(5, 2, 3)) - expect_equal(cov$first_line, c(5, 6, 8)) - expect_equal(cov$last_line, c(5, 6, 8)) + expect_equal(cov$value, c(5, 2, 3, 3)) + expect_equal(cov$first_line, c(5, 6, 8, 13)) + expect_equal(cov$last_line, c(5, 6, 8, 13)) expect_true("a" %in% cov$functions) + expect_true("private_function" %in% cov$functions) }) }) From 938b83820a3415a3cbdef39b282483ee0497cca2 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 20 Jan 2023 16:09:48 +0800 Subject: [PATCH 09/24] added support for R6 classes attached as box modules --- R/box.R | 34 +++++++++++++++++++ R/covr.R | 1 + tests/testthat/Testbox/app/app.R | 3 +- tests/testthat/Testbox/app/modules/moduleR6.R | 11 ++++++ .../Testbox/tests/testthat/test-moduleR6.R | 21 ++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/Testbox/app/modules/moduleR6.R create mode 100644 tests/testthat/Testbox/tests/testthat/test-moduleR6.R diff --git a/R/box.R b/R/box.R index 4d07b900..429e25fa 100644 --- a/R/box.R +++ b/R/box.R @@ -16,3 +16,37 @@ replacements_box <- function(env) { ) ) } + +replacements_box_r6 <- function(env) { + unlist(recursive = FALSE, eapply(env, all.names = TRUE, + function(obj) { + if (inherits(obj, "box$mod")) { + obj_impl <- attr(obj, "namespace") + unlist(recursive = FALSE, lapply(ls(obj_impl), + function(f_name) { + f <- get(f_name, obj_impl) + if (inherits(f, "R6ClassGenerator")) { + unlist(recursive = FALSE, eapply(f, all.names = TRUE, + function(o) { + if (inherits(o, "list")) { + lapply(names(o), + function(m_name) { + m <- get(m_name, o) + if (inherits(m, "function")) { + replacement(m_name, env = obj, target_value = m) + } + } + ) + } + } + ) + ) + } + } + ) + ) + } + } + ) + ) +} diff --git a/R/covr.R b/R/covr.R index ee7b155f..93d43e66 100644 --- a/R/covr.R +++ b/R/covr.R @@ -94,6 +94,7 @@ trace_environment <- function(env) { replacements_RC(env), replacements_R6(env), replacements_box(env), + replacements_box_r6(env), lapply(ls(env, all.names = TRUE), replacement, env = env))) lapply(the$replacements, replace) diff --git a/tests/testthat/Testbox/app/app.R b/tests/testthat/Testbox/app/app.R index 1bbc51fc..b5bede5d 100644 --- a/tests/testthat/Testbox/app/app.R +++ b/tests/testthat/Testbox/app/app.R @@ -2,5 +2,6 @@ options(box.path = file.path(getwd())) rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) box::use( - app/modules/module + app/modules/module, + app/modules/moduleR6 ) diff --git a/tests/testthat/Testbox/app/modules/moduleR6.R b/tests/testthat/Testbox/app/modules/moduleR6.R new file mode 100644 index 00000000..9c2876c3 --- /dev/null +++ b/tests/testthat/Testbox/app/modules/moduleR6.R @@ -0,0 +1,11 @@ +#' @export +TestR6 <- R6::R6Class("TestR6", # nolint + public = list( + show = function(x) { + 1 + 3 + }, + print2 = function(x) { + 1 + 2 + } + ) +) diff --git a/tests/testthat/Testbox/tests/testthat/test-moduleR6.R b/tests/testthat/Testbox/tests/testthat/test-moduleR6.R new file mode 100644 index 00000000..9843e46e --- /dev/null +++ b/tests/testthat/Testbox/tests/testthat/test-moduleR6.R @@ -0,0 +1,21 @@ +box::use( + testthat[test_that, expect_equal, expect_s3_class] +) + +box::use( + app/modules/moduleR6 +) + +test_that("TestR6 class can be instantiated", { + t1 <- moduleR6$TestR6$new() # nolint + + expect_s3_class(t1, "R6") + expect_s3_class(t1, "TestR6") + }) + +test_that("TestR6 Methods can be evaluated", { + t1 <- moduleR6$TestR6$new() # nolint + + expect_equal(t1$show(), 4) + expect_equal(print(t1$print2()), 3) +}) From 8805e9dc826e9c966b1689c37a348c8732820733 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 20 Jan 2023 16:10:18 +0800 Subject: [PATCH 10/24] increment dev version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 501a01bd..31f3e7d3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9002 +Version: 3.6.0.9003 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), From 9b9251ac9db06876bfa52e5c72330a446c23ebce Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 20 Jan 2023 18:36:50 +0800 Subject: [PATCH 11/24] forgot to update the unit test with R6 modules attached --- tests/testthat/test-box.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R index 3e2726fe..bcec020e 100644 --- a/tests/testthat/test-box.R +++ b/tests/testthat/test-box.R @@ -6,11 +6,12 @@ test_that("box module coverage is reported", { source_files = "app/app.R", test_files = list.files("tests/testthat", full.names = TRUE))) - expect_equal(cov$value, c(5, 2, 3, 3)) - expect_equal(cov$first_line, c(5, 6, 8, 13)) - expect_equal(cov$last_line, c(5, 6, 8, 13)) + expect_equal(cov$value, c(5, 2, 3, 3, 1, 1)) + expect_equal(cov$first_line, c(5, 6, 8, 13, 5, 8)) + expect_equal(cov$last_line, c(5, 6, 8, 13, 5, 8)) expect_true("a" %in% cov$functions) expect_true("private_function" %in% cov$functions) + expect_true("show" %in% cov$functions) }) }) From 924fd0679e711f05dc50c8212bdc2e27206f13b6 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Tue, 24 Jan 2023 15:02:34 +0800 Subject: [PATCH 12/24] some refactoring to clean up code --- R/R6.R | 26 +++++++++++++++----------- R/box.R | 51 +++++++++++++++++++++++++++++++++------------------ R/covr.R | 1 - 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/R/R6.R b/R/R6.R index 91ce1ace..d2b6e914 100644 --- a/R/R6.R +++ b/R/R6.R @@ -2,18 +2,22 @@ replacements_R6 <- function(env) { unlist(recursive = FALSE, eapply(env, all.names = TRUE, function(obj) { if (inherits(obj, "R6ClassGenerator")) { - unlist(recursive = FALSE, eapply(obj, - function(o) { - if (inherits(o, "list")) { - lapply(names(o), - function(f_name) { - f <- get(f_name, o) - if (inherits(f, "function")) { - replacement(f_name, env = env, target_value = f) - } -}) + traverse_R6(obj, env) } })) } - })) + +traverse_R6 <- function(obj, env) { + unlist(recursive = FALSE, eapply(obj, + function(o) { + if (inherits(o, "list")) { + lapply(names(o), + function(f_name) { + f <- get(f_name, o) + if (inherits(f, "function")) { + replacement(f_name, env = env, target_value = f) + } + }) + } + })) } diff --git a/R/box.R b/R/box.R index 429e25fa..addcb44d 100644 --- a/R/box.R +++ b/R/box.R @@ -1,7 +1,7 @@ -replacements_box <- function(env) { +replacements_box_modules <- function(env) { unlist(recursive = FALSE, eapply(env, all.names = TRUE, function(obj) { - if (inherits(obj, "box$mod")) { + if (inherits(attr(obj, "spec"), "box$mod_spec")) { obj_impl <- attr(obj, "namespace") lapply(ls(obj_impl), function(f_name) { @@ -9,6 +9,10 @@ replacements_box <- function(env) { if (inherits(f, "function")) { replacement(f_name, env = obj, target_value = f) } + # This else if looks like it should work, but it doesn't + # else if (inherits(f, "R6ClassGenerator")) { + # traverse_R6(f, obj) + # } } ) } @@ -20,28 +24,32 @@ replacements_box <- function(env) { replacements_box_r6 <- function(env) { unlist(recursive = FALSE, eapply(env, all.names = TRUE, function(obj) { - if (inherits(obj, "box$mod")) { + if (inherits(attr(obj, "spec"), "box$mod_spec")) { obj_impl <- attr(obj, "namespace") unlist(recursive = FALSE, lapply(ls(obj_impl), function(f_name) { f <- get(f_name, obj_impl) if (inherits(f, "R6ClassGenerator")) { - unlist(recursive = FALSE, eapply(f, all.names = TRUE, - function(o) { - if (inherits(o, "list")) { - lapply(names(o), - function(m_name) { - m <- get(m_name, o) - if (inherits(m, "function")) { - replacement(m_name, env = obj, target_value = m) - } - } - ) - } - } - ) - ) + traverse_R6(f, obj) } + # keeping this here for notes + # if (inherits(f, "R6ClassGenerator")) { + # unlist(recursive = FALSE, eapply(f, all.names = TRUE, + # function(o) { + # if (inherits(o, "list")) { + # lapply(names(o), + # function(m_name) { + # m <- get(m_name, o) + # if (inherits(m, "function")) { + # replacement(m_name, env = obj, target_value = m) + # } + # } + # ) + # } + # } + # ) + # ) + # } } ) ) @@ -50,3 +58,10 @@ replacements_box_r6 <- function(env) { ) ) } + +replacements_box <- function(env) { + c( + replacements_box_modules(env), + replacements_box_r6(env) + ) +} diff --git a/R/covr.R b/R/covr.R index 93d43e66..ee7b155f 100644 --- a/R/covr.R +++ b/R/covr.R @@ -94,7 +94,6 @@ trace_environment <- function(env) { replacements_RC(env), replacements_R6(env), replacements_box(env), - replacements_box_r6(env), lapply(ls(env, all.names = TRUE), replacement, env = env))) lapply(the$replacements, replace) From 102009280cbc27044b93d47f8988c9893cb4fce1 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 12:23:34 +0800 Subject: [PATCH 13/24] tests for klmr/box attached modules, functions, three dots, and aliases --- DESCRIPTION | 2 +- .../app/app.R | 7 +++++++ .../app/modules/module.R | 19 +++++++++++++++++ .../app/modules/moduleR6.R | 11 ++++++++++ .../tests/testthat.R | 6 ++++++ .../tests/testthat/test-aliased_functions.R | 15 +++++++++++++ .../tests/testthat/test-aliased_modules.R | 15 +++++++++++++ .../tests/testthat/test-attached_R6.R | 21 +++++++++++++++++++ .../tests/testthat/test-attached_functions.R | 15 +++++++++++++ .../tests/testthat/test-three_dots.R | 21 +++++++++++++++++++ .../test-box_attached_modules_functions.R | 17 +++++++++++++++ 11 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/Testbox_attached_modules_functions/app/app.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/app/modules/module.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/app/modules/moduleR6.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/tests/testthat.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_functions.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_modules.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_functions.R create mode 100644 tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-three_dots.R create mode 100644 tests/testthat/test-box_attached_modules_functions.R diff --git a/DESCRIPTION b/DESCRIPTION index 31f3e7d3..367de0a2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9003 +Version: 3.6.0.9004 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), diff --git a/tests/testthat/Testbox_attached_modules_functions/app/app.R b/tests/testthat/Testbox_attached_modules_functions/app/app.R new file mode 100644 index 00000000..b5bede5d --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/app/app.R @@ -0,0 +1,7 @@ +options(box.path = file.path(getwd())) +rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) + +box::use( + app/modules/module, + app/modules/moduleR6 +) diff --git a/tests/testthat/Testbox_attached_modules_functions/app/modules/module.R b/tests/testthat/Testbox_attached_modules_functions/app/modules/module.R new file mode 100644 index 00000000..33cc2c07 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/app/modules/module.R @@ -0,0 +1,19 @@ +#' an example function +#' +#' @export +a <- function(x) { + if (x <= 1) { + 1 + } else { + 2 + } +} + +#' @export +b <- function(x) { + return(x * 2) +} + +private_function <- function(x) { + x ^ 2 +} diff --git a/tests/testthat/Testbox_attached_modules_functions/app/modules/moduleR6.R b/tests/testthat/Testbox_attached_modules_functions/app/modules/moduleR6.R new file mode 100644 index 00000000..9c2876c3 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/app/modules/moduleR6.R @@ -0,0 +1,11 @@ +#' @export +TestR6 <- R6::R6Class("TestR6", # nolint + public = list( + show = function(x) { + 1 + 3 + }, + print2 = function(x) { + 1 + 2 + } + ) +) diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R new file mode 100644 index 00000000..39706593 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R @@ -0,0 +1,6 @@ +options(box.path = file.path(getwd())) +rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) + +library(testthat) + +test_dir("tests/testthat") diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_functions.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_functions.R new file mode 100644 index 00000000..f5865063 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_functions.R @@ -0,0 +1,15 @@ +box::use( + testthat[test_that, expect_equal] +) + +box::use( + app/modules/module[x = a] +) + +test_that("attached regular function `a` works as expected", { + expect_equal(x(1), 1) + expect_equal(x(2), 2) + expect_equal(x(3), 2) + expect_equal(x(4), 2) + expect_equal(x(0), 1) +}) diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_modules.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_modules.R new file mode 100644 index 00000000..4c84d7e9 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-aliased_modules.R @@ -0,0 +1,15 @@ +box::use( + testthat[test_that, expect_equal] +) + +box::use( + x = app/modules/module +) + +test_that("attached regular function `a` works as expected", { + expect_equal(x$a(1), 1) + expect_equal(x$a(2), 2) + expect_equal(x$a(3), 2) + expect_equal(x$a(4), 2) + expect_equal(x$a(0), 1) +}) diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R new file mode 100644 index 00000000..3e2efc70 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R @@ -0,0 +1,21 @@ +box::use( + testthat[test_that, expect_equal, expect_s3_class] +) + +box::use( + app/modules/moduleR6[TestR6] +) + +test_that("TestR6 class can be instantiated", { + t1 <- TestR6$new() # nolint + + expect_s3_class(t1, "R6") + expect_s3_class(t1, "TestR6") +}) + +test_that("TestR6 Methods can be evaluated", { + t1 <- TestR6$new() # nolint + + expect_equal(t1$show(), 4) + expect_equal(t1$print2(), 3) +}) diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_functions.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_functions.R new file mode 100644 index 00000000..034e823a --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_functions.R @@ -0,0 +1,15 @@ +box::use( + testthat[test_that, expect_equal] +) + +box::use( + app/modules/module[a] +) + +test_that("attached regular function `a` works as expected", { + expect_equal(a(1), 1) + expect_equal(a(2), 2) + expect_equal(a(3), 2) + expect_equal(a(4), 2) + expect_equal(a(0), 1) +}) diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-three_dots.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-three_dots.R new file mode 100644 index 00000000..5f3ace81 --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-three_dots.R @@ -0,0 +1,21 @@ +box::use( + testthat[test_that, expect_equal] +) + +box::use( + app/modules/module[...] +) + +test_that("attached regular function `a` works as expected", { + expect_equal(a(1), 1) + expect_equal(a(2), 2) + expect_equal(a(3), 2) + expect_equal(a(4), 2) + expect_equal(a(0), 1) +}) + +test_that("attached regular function `b` works as expected", { + expect_equal(b(1), 2) + expect_equal(b(2), 4) + expect_equal(b(3), 6) +}) diff --git a/tests/testthat/test-box_attached_modules_functions.R b/tests/testthat/test-box_attached_modules_functions.R new file mode 100644 index 00000000..d10c0ae7 --- /dev/null +++ b/tests/testthat/test-box_attached_modules_functions.R @@ -0,0 +1,17 @@ +context("box-attached-modules-functions") + +test_that("box module coverage is reported", { + withr::with_dir("Testbox_attached_modules_functions", { + cov <- as.data.frame(file_coverage( + source_files = "app/app.R", + test_files = list.files("tests/testthat", full.names = TRUE))) + + expect_equal(cov$value, c(20, 8, 12, 3, 0, 1, 1)) + expect_equal(cov$first_line, c(5, 6, 8, 14, 18, 5, 8)) + expect_equal(cov$last_line, c(5, 6, 8, 14, 18, 5, 8)) + expect_true("a" %in% cov$functions) + expect_true("private_function" %in% cov$functions) + expect_true("show" %in% cov$functions) + }) + +}) From e932fe3821255a80de051da1ed6212f16382905b Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 27 Jan 2023 19:12:44 +0800 Subject: [PATCH 14/24] a little bit of cleanup --- DESCRIPTION | 2 +- R/box.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 367de0a2..ccf943fc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9004 +Version: 3.6.0.9005 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), diff --git a/R/box.R b/R/box.R index addcb44d..40381833 100644 --- a/R/box.R +++ b/R/box.R @@ -2,8 +2,8 @@ replacements_box_modules <- function(env) { unlist(recursive = FALSE, eapply(env, all.names = TRUE, function(obj) { if (inherits(attr(obj, "spec"), "box$mod_spec")) { - obj_impl <- attr(obj, "namespace") - lapply(ls(obj_impl), + obj_impl <- attr(obj, "namespace") + lapply(ls(obj_impl), function(f_name) { f <- get(f_name, obj_impl) if (inherits(f, "function")) { From 1ea85e1feb57e6271ddd18250aa6bd0f3209b41c Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 30 Jan 2023 17:44:38 +0800 Subject: [PATCH 15/24] code cleanup. finally broke the unlist puzzle --- R/box.R | 69 +++++++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/R/box.R b/R/box.R index 40381833..4d3799ee 100644 --- a/R/box.R +++ b/R/box.R @@ -1,67 +1,30 @@ -replacements_box_modules <- function(env) { - unlist(recursive = FALSE, eapply(env, all.names = TRUE, - function(obj) { - if (inherits(attr(obj, "spec"), "box$mod_spec")) { - obj_impl <- attr(obj, "namespace") - lapply(ls(obj_impl), - function(f_name) { - f <- get(f_name, obj_impl) - if (inherits(f, "function")) { - replacement(f_name, env = obj, target_value = f) - } - # This else if looks like it should work, but it doesn't - # else if (inherits(f, "R6ClassGenerator")) { - # traverse_R6(f, obj) - # } - } - ) - } - } - ) - ) -} - -replacements_box_r6 <- function(env) { +replacements_box <- function(env) { unlist(recursive = FALSE, eapply(env, all.names = TRUE, function(obj) { if (inherits(attr(obj, "spec"), "box$mod_spec")) { obj_impl <- attr(obj, "namespace") - unlist(recursive = FALSE, lapply(ls(obj_impl), + compact(c( + lapply(ls(obj_impl), function(f_name) { f <- get(f_name, obj_impl) - if (inherits(f, "R6ClassGenerator")) { - traverse_R6(f, obj) + if (inherits(f, "function")) { + replacement(f_name, env = obj, target_value = f) } - # keeping this here for notes - # if (inherits(f, "R6ClassGenerator")) { - # unlist(recursive = FALSE, eapply(f, all.names = TRUE, - # function(o) { - # if (inherits(o, "list")) { - # lapply(names(o), - # function(m_name) { - # m <- get(m_name, o) - # if (inherits(m, "function")) { - # replacement(m_name, env = obj, target_value = m) - # } - # } - # ) - # } - # } - # ) - # ) - # } } + ), + unlist(recursive = FALSE, + lapply(ls(obj_impl), + function(f_name) { + f <- get(f_name, obj_impl) + if (inherits(f, "R6ClassGenerator")) { + traverse_R6(f, obj) + } + } + ) ) - ) + )) } } ) ) } - -replacements_box <- function(env) { - c( - replacements_box_modules(env), - replacements_box_r6(env) - ) -} From 2a9ab9bb568833d5a13b338f89834b1fbf55811f Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 30 Jan 2023 18:13:23 +0800 Subject: [PATCH 16/24] clean up nested (( --- R/box.R | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/R/box.R b/R/box.R index 4d3799ee..da4c6cda 100644 --- a/R/box.R +++ b/R/box.R @@ -3,26 +3,28 @@ replacements_box <- function(env) { function(obj) { if (inherits(attr(obj, "spec"), "box$mod_spec")) { obj_impl <- attr(obj, "namespace") - compact(c( - lapply(ls(obj_impl), - function(f_name) { - f <- get(f_name, obj_impl) - if (inherits(f, "function")) { - replacement(f_name, env = obj, target_value = f) - } - } - ), - unlist(recursive = FALSE, + compact( + c( lapply(ls(obj_impl), function(f_name) { f <- get(f_name, obj_impl) - if (inherits(f, "R6ClassGenerator")) { - traverse_R6(f, obj) + if (inherits(f, "function")) { + replacement(f_name, env = obj, target_value = f) } } + ), + unlist(recursive = FALSE, + lapply(ls(obj_impl), + function(f_name) { + f <- get(f_name, obj_impl) + if (inherits(f, "R6ClassGenerator")) { + traverse_R6(f, obj) + } + } + ) ) ) - )) + ) } } ) From 513c051f024233718db046034e033a9a0ebfa309 Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Tue, 21 Feb 2023 15:56:45 +0100 Subject: [PATCH 17/24] test: Fix box cache cleaning in tests. --- tests/testthat/Testbox/app/app.R | 4 +++- tests/testthat/Testbox/tests/testthat.R | 4 +++- tests/testthat/Testbox_attached_modules_functions/app/app.R | 4 +++- .../Testbox_attached_modules_functions/tests/testthat.R | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/testthat/Testbox/app/app.R b/tests/testthat/Testbox/app/app.R index b5bede5d..46f7a5e2 100644 --- a/tests/testthat/Testbox/app/app.R +++ b/tests/testthat/Testbox/app/app.R @@ -1,5 +1,7 @@ options(box.path = file.path(getwd())) -rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) box::use( app/modules/module, diff --git a/tests/testthat/Testbox/tests/testthat.R b/tests/testthat/Testbox/tests/testthat.R index 39706593..59bf8cce 100644 --- a/tests/testthat/Testbox/tests/testthat.R +++ b/tests/testthat/Testbox/tests/testthat.R @@ -1,5 +1,7 @@ options(box.path = file.path(getwd())) -rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) library(testthat) diff --git a/tests/testthat/Testbox_attached_modules_functions/app/app.R b/tests/testthat/Testbox_attached_modules_functions/app/app.R index b5bede5d..46f7a5e2 100644 --- a/tests/testthat/Testbox_attached_modules_functions/app/app.R +++ b/tests/testthat/Testbox_attached_modules_functions/app/app.R @@ -1,5 +1,7 @@ options(box.path = file.path(getwd())) -rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) box::use( app/modules/module, diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R b/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R index 39706593..59bf8cce 100644 --- a/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R +++ b/tests/testthat/Testbox_attached_modules_functions/tests/testthat.R @@ -1,5 +1,7 @@ options(box.path = file.path(getwd())) -rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) library(testthat) From 0b9de23b07b9df9e7cee8643539e33a54e60978d Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Tue, 21 Feb 2023 15:57:31 +0100 Subject: [PATCH 18/24] chore: Add box to suggested dependencies. --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ccf943fc..8cda5f06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -68,7 +68,8 @@ Suggests: parallel, memoise, mockery, - covr + covr, + box License: MIT + file LICENSE VignetteBuilder: knitr RoxygenNote: 7.2.1 From 08562d712442a2093f11a4548270611524b4c9c1 Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Tue, 21 Feb 2023 15:57:49 +0100 Subject: [PATCH 19/24] chore: Update package version. --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8cda5f06..6dc1492e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.0.9005 +Version: 3.6.0.9001 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), From a78f548df8c1523bd0f90966c413edf75f72f780 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 3 Apr 2023 11:31:40 +0800 Subject: [PATCH 20/24] added entry in NEWS.md --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 753cf30c..5792cb7c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# covr (development version) + +* Added support for `klmr/box` modules. This works best with `file_coverage()`. (@radbasa, #491) + # covr 3.6.1 * `to_cobertura()` is now explicit about the doctype of the resulting XML. It also sets a source path if recorded. (@mmyrte, #524) From 8ac12685d77676021e49ab9701e7a01f54f7f949 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 20 Apr 2023 18:03:58 +0800 Subject: [PATCH 21/24] Trigger CICD From 5a8a87445683c1f42cdcfe24c0b2904ca53882d6 Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Tue, 10 Oct 2023 06:43:18 +0200 Subject: [PATCH 22/24] Another CI test trigger pr (#21) * Added `replacements_box()` for `klmr/box` support. * Extracted `traverse_R6()` from `replacements_R6()` to reuse code in `replacements_box()`. * R6 class box modules test cases separated to handle a known R6 issues with `r-devel`. `skip_if(is_r_devel())` is used in the R6 test cases. --- .github/workflows/R-CMD-check.yaml | 19 ++++++------ .github/workflows/pkgdown.yaml | 6 ++-- .github/workflows/pr-commands.yaml | 4 +-- .github/workflows/test-coverage.yaml | 29 ++++++++++++++++--- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/covr.R | 2 +- R/trace_calls.R | 2 +- tests/testthat/Testbox/app/app.R | 3 +- tests/testthat/Testbox_R6/app/app.R | 8 +++++ .../app/modules/moduleR6.R | 0 tests/testthat/Testbox_R6/tests/testthat.R | 8 +++++ .../tests/testthat/test-moduleR6.R | 2 ++ .../app/app.R | 3 +- .../app/app.R | 8 +++++ .../app/modules/moduleR6.R | 0 .../tests/testthat.R | 8 +++++ .../tests/testthat/test-attached_R6.R | 2 ++ tests/testthat/test-Compiled.R | 5 ++++ tests/testthat/test-box-R6.R | 21 ++++++++++++++ tests/testthat/test-box.R | 11 +++---- .../test-box_attached_modules_functions-R6.R | 22 ++++++++++++++ .../test-box_attached_modules_functions.R | 12 ++++---- tests/testthat/test-tally_coverage.R | 1 + 24 files changed, 146 insertions(+), 34 deletions(-) create mode 100644 tests/testthat/Testbox_R6/app/app.R rename tests/testthat/{Testbox => Testbox_R6}/app/modules/moduleR6.R (100%) create mode 100644 tests/testthat/Testbox_R6/tests/testthat.R rename tests/testthat/{Testbox => Testbox_R6}/tests/testthat/test-moduleR6.R (89%) create mode 100644 tests/testthat/Testbox_attached_modules_functions_R6/app/app.R rename tests/testthat/{Testbox_attached_modules_functions => Testbox_attached_modules_functions_R6}/app/modules/moduleR6.R (100%) create mode 100644 tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat.R rename tests/testthat/{Testbox_attached_modules_functions => Testbox_attached_modules_functions_R6}/tests/testthat/test-attached_R6.R (89%) create mode 100644 tests/testthat/test-box-R6.R create mode 100644 tests/testthat/test-box_attached_modules_functions-R6.R diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 7e483fdc..ee65ccb5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -22,26 +22,27 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} # Use 3.6 to trigger usage of RTools35 - {os: windows-latest, r: '3.6'} + # use 4.1 to check with rtools40's older compiler + - {os: windows-latest, r: '4.1'} - # Use older ubuntu to maximise backward compatibility - - {os: ubuntu-20.04, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-20.04, r: 'release'} - - {os: ubuntu-20.04, r: 'oldrel-1'} - - {os: ubuntu-20.04, r: 'oldrel-2'} - - {os: ubuntu-20.04, r: 'oldrel-3'} - - {os: ubuntu-20.04, r: 'oldrel-4'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + - {os: ubuntu-latest, r: 'oldrel-2'} + - {os: ubuntu-latest, r: 'oldrel-3'} + - {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 0b260216..ed7650c7 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -19,8 +19,10 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 @@ -39,7 +41,7 @@ jobs: - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@4.1.4 + uses: JamesIves/github-pages-deploy-action@v4.4.1 with: clean: false branch: gh-pages diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml index 97271eb2..71f335b3 100644 --- a/.github/workflows/pr-commands.yaml +++ b/.github/workflows/pr-commands.yaml @@ -14,7 +14,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/pr-fetch@v2 with: @@ -51,7 +51,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/pr-fetch@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 9f201525..634ddc8f 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -15,7 +15,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-r@v2 with: @@ -23,11 +23,32 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::covr needs: coverage - - name: Test coverage + - name: Setup run: | R CMD INSTALL . source shim_package.sh - Rscript -e 'covr::codecov()' + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index 3a0032ca..516b6411 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.1.9001 +Version: 3.6.2.9001 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 5792cb7c..1e9a8f14 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * Added support for `klmr/box` modules. This works best with `file_coverage()`. (@radbasa, #491) +# covr 3.6.2 + # covr 3.6.1 * `to_cobertura()` is now explicit about the doctype of the resulting XML. It also sets a source path if recorded. (@mmyrte, #524) diff --git a/R/covr.R b/R/covr.R index 359b7edb..106d8f03 100644 --- a/R/covr.R +++ b/R/covr.R @@ -538,7 +538,7 @@ package_coverage <- function(path = ".", "src/cpp11.cpp", "R/cpp11.R", line_exclusions, - parse_covr_ignore() + withr::with_dir(root, parse_covr_ignore()) ) exclude(coverage, diff --git a/R/trace_calls.R b/R/trace_calls.R index 8bdb7220..a6813c76 100644 --- a/R/trace_calls.R +++ b/R/trace_calls.R @@ -28,7 +28,7 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) { lapply(y, trace_calls, parent_functions = parent_functions) } - if (is.atomic(x) || is.name(x)) { + if (is.atomic(x) || is.name(x) || is.null(x)) { if (is.null(parent_ref)) { x } diff --git a/tests/testthat/Testbox/app/app.R b/tests/testthat/Testbox/app/app.R index 46f7a5e2..a03a3dfa 100644 --- a/tests/testthat/Testbox/app/app.R +++ b/tests/testthat/Testbox/app/app.R @@ -4,6 +4,5 @@ loaded_mods <- loadNamespace("box")$loaded_mods rm(list = ls(loaded_mods), envir = loaded_mods) box::use( - app/modules/module, - app/modules/moduleR6 + app/modules/module ) diff --git a/tests/testthat/Testbox_R6/app/app.R b/tests/testthat/Testbox_R6/app/app.R new file mode 100644 index 00000000..1930366b --- /dev/null +++ b/tests/testthat/Testbox_R6/app/app.R @@ -0,0 +1,8 @@ +options(box.path = file.path(getwd())) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +box::use( + app/modules/moduleR6 +) diff --git a/tests/testthat/Testbox/app/modules/moduleR6.R b/tests/testthat/Testbox_R6/app/modules/moduleR6.R similarity index 100% rename from tests/testthat/Testbox/app/modules/moduleR6.R rename to tests/testthat/Testbox_R6/app/modules/moduleR6.R diff --git a/tests/testthat/Testbox_R6/tests/testthat.R b/tests/testthat/Testbox_R6/tests/testthat.R new file mode 100644 index 00000000..59bf8cce --- /dev/null +++ b/tests/testthat/Testbox_R6/tests/testthat.R @@ -0,0 +1,8 @@ +options(box.path = file.path(getwd())) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +library(testthat) + +test_dir("tests/testthat") diff --git a/tests/testthat/Testbox/tests/testthat/test-moduleR6.R b/tests/testthat/Testbox_R6/tests/testthat/test-moduleR6.R similarity index 89% rename from tests/testthat/Testbox/tests/testthat/test-moduleR6.R rename to tests/testthat/Testbox_R6/tests/testthat/test-moduleR6.R index 9843e46e..f36608aa 100644 --- a/tests/testthat/Testbox/tests/testthat/test-moduleR6.R +++ b/tests/testthat/Testbox_R6/tests/testthat/test-moduleR6.R @@ -7,6 +7,7 @@ box::use( ) test_that("TestR6 class can be instantiated", { + skip_if(is_r_devel()) t1 <- moduleR6$TestR6$new() # nolint expect_s3_class(t1, "R6") @@ -14,6 +15,7 @@ test_that("TestR6 class can be instantiated", { }) test_that("TestR6 Methods can be evaluated", { + skip_if(is_r_devel()) t1 <- moduleR6$TestR6$new() # nolint expect_equal(t1$show(), 4) diff --git a/tests/testthat/Testbox_attached_modules_functions/app/app.R b/tests/testthat/Testbox_attached_modules_functions/app/app.R index 46f7a5e2..a03a3dfa 100644 --- a/tests/testthat/Testbox_attached_modules_functions/app/app.R +++ b/tests/testthat/Testbox_attached_modules_functions/app/app.R @@ -4,6 +4,5 @@ loaded_mods <- loadNamespace("box")$loaded_mods rm(list = ls(loaded_mods), envir = loaded_mods) box::use( - app/modules/module, - app/modules/moduleR6 + app/modules/module ) diff --git a/tests/testthat/Testbox_attached_modules_functions_R6/app/app.R b/tests/testthat/Testbox_attached_modules_functions_R6/app/app.R new file mode 100644 index 00000000..1930366b --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions_R6/app/app.R @@ -0,0 +1,8 @@ +options(box.path = file.path(getwd())) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +box::use( + app/modules/moduleR6 +) diff --git a/tests/testthat/Testbox_attached_modules_functions/app/modules/moduleR6.R b/tests/testthat/Testbox_attached_modules_functions_R6/app/modules/moduleR6.R similarity index 100% rename from tests/testthat/Testbox_attached_modules_functions/app/modules/moduleR6.R rename to tests/testthat/Testbox_attached_modules_functions_R6/app/modules/moduleR6.R diff --git a/tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat.R b/tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat.R new file mode 100644 index 00000000..59bf8cce --- /dev/null +++ b/tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat.R @@ -0,0 +1,8 @@ +options(box.path = file.path(getwd())) +# remove box cache +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +library(testthat) + +test_dir("tests/testthat") diff --git a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R b/tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat/test-attached_R6.R similarity index 89% rename from tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R rename to tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat/test-attached_R6.R index 3e2efc70..2c147730 100644 --- a/tests/testthat/Testbox_attached_modules_functions/tests/testthat/test-attached_R6.R +++ b/tests/testthat/Testbox_attached_modules_functions_R6/tests/testthat/test-attached_R6.R @@ -7,6 +7,7 @@ box::use( ) test_that("TestR6 class can be instantiated", { + skip_if(is_r_devel()) t1 <- TestR6$new() # nolint expect_s3_class(t1, "R6") @@ -14,6 +15,7 @@ test_that("TestR6 class can be instantiated", { }) test_that("TestR6 Methods can be evaluated", { + skip_if(is_r_devel()) t1 <- TestR6$new() # nolint expect_equal(t1$show(), 4) diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 83083170..221f0ce0 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -1,6 +1,8 @@ context("Compiled") test_that("Compiled code coverage is reported including code in headers", { skip_on_cran() + skip_if(is_windows() && getRversion() == "4.1") + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) simple_cc <- cov[cov$filename == "src/simple.cc", ] @@ -32,6 +34,7 @@ test_that("Compiled code coverage is reported including code in headers", { test_that("Can pass path to relative_path argument", { skip_on_cran() + skip_if(is_windows() && getRversion() == "4.1") cov <- as.data.frame(package_coverage("TestCompiled", relative_path = ".")) expect_true(all(unique(cov$filename) %in% c( @@ -44,6 +47,7 @@ test_that("Can pass path to relative_path argument", { test_that("Source code subdirectories are found", { skip_on_cran() + skip_if(is_windows() && getRversion() == "4.1") cov <- as.data.frame(package_coverage("TestCompiledSubdir", relative_path = TRUE)) expect_equal(cov[cov$first_line == "9", "value"], 4) @@ -59,6 +63,7 @@ test_that("Source code subdirectories are found", { test_that("Compiled code coverage is reported under non-standard char's", { skip_on_cran() + skip_if(is_windows() && getRversion() == "4.1") cov <- as.data.frame(package_coverage("Test+Char/TestCompiled", relative_path = TRUE)) expect_equal(cov[cov$first_line == "9", "value"], 4) diff --git a/tests/testthat/test-box-R6.R b/tests/testthat/test-box-R6.R new file mode 100644 index 00000000..b50b8408 --- /dev/null +++ b/tests/testthat/test-box-R6.R @@ -0,0 +1,21 @@ +context("box-R6") + +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +test_that("R6 box module coverage is reported", { + # Similar to test-R6.R, there is some sort of bug that causes this test + # to fail during R CMD check in R-devel, not sure why, and can't reproduce + # it interactively + skip_if(is_r_devel()) + withr::with_dir("Testbox_R6", { + cov <- as.data.frame(file_coverage( + source_files = "app/app.R", + test_files = list.files("tests/testthat", full.names = TRUE))) + + expect_equal(cov$value, c(1, 1)) + expect_equal(cov$first_line, c(5, 8)) + expect_equal(cov$last_line, c(5, 8)) + expect_true("show" %in% cov$functions) + }) +}) diff --git a/tests/testthat/test-box.R b/tests/testthat/test-box.R index bcec020e..9ee174a0 100644 --- a/tests/testthat/test-box.R +++ b/tests/testthat/test-box.R @@ -1,17 +1,18 @@ context("box") +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + test_that("box module coverage is reported", { withr::with_dir("Testbox", { cov <- as.data.frame(file_coverage( source_files = "app/app.R", test_files = list.files("tests/testthat", full.names = TRUE))) - expect_equal(cov$value, c(5, 2, 3, 3, 1, 1)) - expect_equal(cov$first_line, c(5, 6, 8, 13, 5, 8)) - expect_equal(cov$last_line, c(5, 6, 8, 13, 5, 8)) + expect_equal(cov$value, c(5, 2, 3, 3)) + expect_equal(cov$first_line, c(5, 6, 8, 13)) + expect_equal(cov$last_line, c(5, 6, 8, 13)) expect_true("a" %in% cov$functions) expect_true("private_function" %in% cov$functions) - expect_true("show" %in% cov$functions) }) - }) diff --git a/tests/testthat/test-box_attached_modules_functions-R6.R b/tests/testthat/test-box_attached_modules_functions-R6.R new file mode 100644 index 00000000..ba491dc8 --- /dev/null +++ b/tests/testthat/test-box_attached_modules_functions-R6.R @@ -0,0 +1,22 @@ +context("box-attached-modules-functions-R6") + +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +test_that("R6 box attached module coverage is reported", { + # Similar to test-R6.R, there is some sort of bug that causes this test + # to fail during R CMD check in R-devel, not sure why, and can't reproduce + # it interactively + skip_if(is_r_devel()) + withr::with_dir("Testbox_attached_modules_functions_R6", { + cov <- as.data.frame(file_coverage( + source_files = "app/app.R", + test_files = list.files("tests/testthat", full.names = TRUE))) + + expect_equal(cov$value, c(1, 1)) + expect_equal(cov$first_line, c(5, 8)) + expect_equal(cov$last_line, c(5, 8)) + expect_true("show" %in% cov$functions) + }) + +}) diff --git a/tests/testthat/test-box_attached_modules_functions.R b/tests/testthat/test-box_attached_modules_functions.R index d10c0ae7..06064083 100644 --- a/tests/testthat/test-box_attached_modules_functions.R +++ b/tests/testthat/test-box_attached_modules_functions.R @@ -1,17 +1,19 @@ context("box-attached-modules-functions") -test_that("box module coverage is reported", { +loaded_mods <- loadNamespace("box")$loaded_mods +rm(list = ls(loaded_mods), envir = loaded_mods) + +test_that("box attached module coverage is reported", { withr::with_dir("Testbox_attached_modules_functions", { cov <- as.data.frame(file_coverage( source_files = "app/app.R", test_files = list.files("tests/testthat", full.names = TRUE))) - expect_equal(cov$value, c(20, 8, 12, 3, 0, 1, 1)) - expect_equal(cov$first_line, c(5, 6, 8, 14, 18, 5, 8)) - expect_equal(cov$last_line, c(5, 6, 8, 14, 18, 5, 8)) + expect_equal(cov$value, c(20, 8, 12, 3, 0)) + expect_equal(cov$first_line, c(5, 6, 8, 14, 18)) + expect_equal(cov$last_line, c(5, 6, 8, 14, 18)) expect_true("a" %in% cov$functions) expect_true("private_function" %in% cov$functions) - expect_true("show" %in% cov$functions) }) }) diff --git a/tests/testthat/test-tally_coverage.R b/tests/testthat/test-tally_coverage.R index b68261ff..7e92a992 100644 --- a/tests/testthat/test-tally_coverage.R +++ b/tests/testthat/test-tally_coverage.R @@ -1,5 +1,6 @@ test_that("tally_coverage includes compiled code", { skip_on_cran() + skip_if(is_windows() && getRversion() == "4.1") cov <- package_coverage(test_path("TestCompiled")) tall <- tally_coverage(cov) From 223851908951d0662d767f475f1d20b5343ada02 Mon Sep 17 00:00:00 2001 From: Ricardo Rodrigo Basa Date: Wed, 11 Oct 2023 11:57:24 +0800 Subject: [PATCH 23/24] Update to covr 3.6.3 (#23) * Adjusted DESCRIPTION and NEWS.md * Different condition to skip tests * Bump version for release --------- Co-authored-by: Jim Hester --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ cran-comments.md | 2 +- tests/testthat/helper.R | 5 +++++ tests/testthat/test-Compiled.R | 8 ++++---- tests/testthat/test-tally_coverage.R | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 516b6411..722eff26 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.2.9001 +Version: 3.6.3.9001 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 1e9a8f14..a84d9861 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,12 @@ * Added support for `klmr/box` modules. This works best with `file_coverage()`. (@radbasa, #491) +# covr 3.6.3 + +* Updates to internal usage of `is.atomic()` to work with upcoming R release (@mmaechler , #542) + +* `package_coverage()` now works correctly with ignore files when it is not run in the package root directory (@mpadge, #538) + # covr 3.6.2 # covr 3.6.1 diff --git a/cran-comments.md b/cran-comments.md index 25bf69dd..286e1fb6 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,4 @@ -This is a patch release to fix a test which assumed R is on the PATH, and that it is the same R being used to check. +This is a patch release to fix a change made in R-devel ## R CMD check results There were no NOTEs, ERRORs or WARNINGs. diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 0df6d157..182fe66f 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -1,3 +1,8 @@ is_r_devel <- function() { startsWith(R.version$status, "Under development") } + +is_win_r41 <- function() { + x <- getRversion() + is_windows() && x$major == 4 && x$minor == 1 +} diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 221f0ce0..a9c3defc 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -1,7 +1,7 @@ context("Compiled") test_that("Compiled code coverage is reported including code in headers", { skip_on_cran() - skip_if(is_windows() && getRversion() == "4.1") + skip_if(is_win_r41()) cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) @@ -34,7 +34,7 @@ test_that("Compiled code coverage is reported including code in headers", { test_that("Can pass path to relative_path argument", { skip_on_cran() - skip_if(is_windows() && getRversion() == "4.1") + skip_if(is_win_r41()) cov <- as.data.frame(package_coverage("TestCompiled", relative_path = ".")) expect_true(all(unique(cov$filename) %in% c( @@ -47,7 +47,7 @@ test_that("Can pass path to relative_path argument", { test_that("Source code subdirectories are found", { skip_on_cran() - skip_if(is_windows() && getRversion() == "4.1") + skip_if(is_win_r41()) cov <- as.data.frame(package_coverage("TestCompiledSubdir", relative_path = TRUE)) expect_equal(cov[cov$first_line == "9", "value"], 4) @@ -63,7 +63,7 @@ test_that("Source code subdirectories are found", { test_that("Compiled code coverage is reported under non-standard char's", { skip_on_cran() - skip_if(is_windows() && getRversion() == "4.1") + skip_if(is_win_r41()) cov <- as.data.frame(package_coverage("Test+Char/TestCompiled", relative_path = TRUE)) expect_equal(cov[cov$first_line == "9", "value"], 4) diff --git a/tests/testthat/test-tally_coverage.R b/tests/testthat/test-tally_coverage.R index 7e92a992..93173766 100644 --- a/tests/testthat/test-tally_coverage.R +++ b/tests/testthat/test-tally_coverage.R @@ -1,6 +1,6 @@ test_that("tally_coverage includes compiled code", { skip_on_cran() - skip_if(is_windows() && getRversion() == "4.1") + skip_if(is_win_r41()) cov <- package_coverage(test_path("TestCompiled")) tall <- tally_coverage(cov) From b93fd1bd0f2e4826ef37ad859b4fe923841a66e4 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 8 Feb 2024 10:46:53 +0800 Subject: [PATCH 24/24] box 1.2.0 released with backports compatibility fixes --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b4249b0d..d086e5c0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,7 +69,7 @@ Suggests: memoise, mockery, covr, - box + box (>= 1.2.0) License: MIT + file LICENSE VignetteBuilder: knitr RoxygenNote: 7.2.3