From 7d53cdf39e250339b678b11f18d9d3014cba2d1b Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 13:46:56 +0800 Subject: [PATCH 01/12] covr support --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/tools.R | 64 ++++++++++++++++++++++++++++++++++++++++++++++ man/covr_r.Rd | 23 +++++++++++++++++ man/covr_report.Rd | 28 ++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 man/covr_r.Rd create mode 100644 man/covr_report.Rd diff --git a/DESCRIPTION b/DESCRIPTION index c442dc30..b21865f6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0 +Version: 1.3.0.1 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/NAMESPACE b/NAMESPACE index f6eb6507..c801696b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,8 @@ export(app) export(build_js) export(build_sass) +export(covr_r) +export(covr_report) export(diagnostics) export(format_r) export(init) diff --git a/R/tools.R b/R/tools.R index 53baf8b4..02ccb4eb 100644 --- a/R/tools.R +++ b/R/tools.R @@ -342,3 +342,67 @@ test_e2e <- function(interactive = FALSE) { npm("run", "test-e2e") } } + +#' Run a covr test coverage check +#' +#' Uses the `{covr}` package to produce unit test coverage reports. +#' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. +#' +#' @return A `covr` coverage dataset. +#' +#' @examples +#' if (interactive()) { +#' # Run a test coverage check for the entire rhino app +#' # using all tests in the `tests/testthat` directory. +#' covr_r() +#' } +#' +#' @export +covr_r <- function() { + rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) + + withr::with_file("box_loader.R", { + module_list <- sub( + "__init__", + "`__init__`", + paste0( + tools::file_path_sans_ext( + list.files("app", pattern = "\\.[rR]$", full.names = TRUE, recursive = TRUE) + ), + "," + ) + ) + + loader_lines <- c("box::use(", module_list, ")") + + writeLines(loader_lines, "box_loader.R") + + coverage <- covr::file_coverage( + source_files = "box_loader.R", + test_files = list.files("tests/testthat", full.names = TRUE) + ) + }) + + return(coverage) +} + +#' Display rhino test coverage results using a standalone report +#' +#' Uses the `{covr}` package to produce unit test coverage reports. +#' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. +#' +#' @param rhino_coverage a rhino coverage dataset, a defaults to `covr_r()`. +#' @param ... additional arguments to pass to +#' [`covr::report()`](https://covr.r-lib.org/reference/report.html) +#' @return None. This function is called for side effects. +#' +#' @examples +#' if (interactive()) { +#' # Run a test coverage report on a rhino app +#' covr_report() +#' } +#' +#' @export +covr_report <- function(rhino_coverage = covr_r(), ...) { + covr::report(x = rhino_coverage, ...) +} diff --git a/man/covr_r.Rd b/man/covr_r.Rd new file mode 100644 index 00000000..7676caef --- /dev/null +++ b/man/covr_r.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tools.R +\name{covr_r} +\alias{covr_r} +\title{Run a test coverage check} +\usage{ +covr_r() +} +\value{ +A \code{covr} coverage dataset. +} +\description{ +Uses the \code{{covr}} package to produce unit test coverage reports. +Uses the \code{{testhat}} package to run all unit tests in \code{tests/testthat} directory. +} +\examples{ +if (interactive()) { + # Run a test coverage check for the entire rhino app + # using all tests in the `tests/testthat` directory. + covr_r() +} + +} diff --git a/man/covr_report.Rd b/man/covr_report.Rd new file mode 100644 index 00000000..a9b619e6 --- /dev/null +++ b/man/covr_report.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tools.R +\name{covr_report} +\alias{covr_report} +\title{Display rhino test coverage results using a standalone report} +\usage{ +covr_report(rhino_coverage = covr_r(), ...) +} +\arguments{ +\item{rhino_coverage}{a rhino coverage dataset, a defaults to \code{covr_r()}.} + +\item{...}{additional arguments to pass to +\href{https://covr.r-lib.org/reference/report.html}{\code{covr::report()}}} +} +\value{ +None. This function is called for side effects. +} +\description{ +Uses the \code{{covr}} package to produce unit test coverage reports. +Uses the \code{{testhat}} package to run all unit tests in \code{tests/testthat} directory. +} +\examples{ +if (interactive()) { + # Run a test coverage report on a rhino app + covr_report() +} + +} From 50a3ddb850fbc7b7d085a81a30b748334dbb1fc4 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 14:17:26 +0800 Subject: [PATCH 02/12] removed box environment clearing --- R/tools.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/tools.R b/R/tools.R index 02ccb4eb..7ac8559e 100644 --- a/R/tools.R +++ b/R/tools.R @@ -359,8 +359,6 @@ test_e2e <- function(interactive = FALSE) { #' #' @export covr_r <- function() { - rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) - withr::with_file("box_loader.R", { module_list <- sub( "__init__", From f25ce9d46485bf1abab79d0943160b6d373a0e87 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 16:26:14 +0800 Subject: [PATCH 03/12] version number change as suggested Co-authored-by: Jakub Nowicki --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b21865f6..a572c5ba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.1 +Version: 1.3.0.9000 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), From fbb3d46b1dbd2f8abf53653e5e12f9785dc82e9a Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 18:02:17 +0800 Subject: [PATCH 04/12] added filter pattern to list.files for test_files to only get test-????.R files --- DESCRIPTION | 2 +- R/tools.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a572c5ba..3c28f6d7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9000 +Version: 1.3.0.9001 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/R/tools.R b/R/tools.R index 7ac8559e..11d1d4c5 100644 --- a/R/tools.R +++ b/R/tools.R @@ -377,7 +377,7 @@ covr_r <- function() { coverage <- covr::file_coverage( source_files = "box_loader.R", - test_files = list.files("tests/testthat", full.names = TRUE) + test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE) ) }) From 01340248fbd3eab46c8eae6b41b7da559a4551ad Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 18:25:16 +0800 Subject: [PATCH 05/12] exposed covr::file_coverage parameters --- DESCRIPTION | 2 +- R/tools.R | 13 +++++++++++-- man/covr_r.Rd | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3c28f6d7..f587cc69 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9001 +Version: 1.3.0.9002 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/R/tools.R b/R/tools.R index 11d1d4c5..f86c091c 100644 --- a/R/tools.R +++ b/R/tools.R @@ -348,6 +348,10 @@ test_e2e <- function(interactive = FALSE) { #' Uses the `{covr}` package to produce unit test coverage reports. #' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. #' +#' @param test_files Character vector of test files with code to test the functions. Defaults to +#' all test files in `tests/testthat` with the `test-.R` filename pattern. +#' @param line_exclusions passed to `covr::file_coverage` +#' @param function_exclusions passed to `covr::file_coverage` #' @return A `covr` coverage dataset. #' #' @examples @@ -358,7 +362,10 @@ test_e2e <- function(interactive = FALSE) { #' } #' #' @export -covr_r <- function() { +covr_r <- function( + test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE), + line_exclusions = NULL, + function_exclusions = NULL) { withr::with_file("box_loader.R", { module_list <- sub( "__init__", @@ -377,7 +384,9 @@ covr_r <- function() { coverage <- covr::file_coverage( source_files = "box_loader.R", - test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE) + test_files = test_files, + line_exclusions = line_exclusions, + function_exclusions = function_exclusions ) }) diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 7676caef..24239fc2 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -2,9 +2,22 @@ % Please edit documentation in R/tools.R \name{covr_r} \alias{covr_r} -\title{Run a test coverage check} +\title{Run a covr test coverage check} \usage{ -covr_r() +covr_r( + test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = + TRUE), + line_exclusions = NULL, + function_exclusions = NULL +) +} +\arguments{ +\item{test_files}{Character vector of test files with code to test the functions. Defaults to +all test files in \code{tests/testthat} with the \verb{test-.R} filename pattern.} + +\item{line_exclusions}{passed to \code{covr::file_coverage}} + +\item{function_exclusions}{passed to \code{covr::file_coverage}} } \value{ A \code{covr} coverage dataset. @@ -15,7 +28,7 @@ Uses the \code{{testhat}} package to run all unit tests in \code{tests/testthat} } \examples{ if (interactive()) { - # Run a test coverage check for the entire rhino app + # Run a test coverage check for the entire rhino app # using all tests in the `tests/testthat` directory. covr_r() } From ffceaf912ed74ba53e8de27e657079dc0353a196 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 18:57:02 +0800 Subject: [PATCH 06/12] github spell check complained about covr --- R/tools.R | 2 +- man/covr_r.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tools.R b/R/tools.R index f86c091c..1d79d88a 100644 --- a/R/tools.R +++ b/R/tools.R @@ -343,7 +343,7 @@ test_e2e <- function(interactive = FALSE) { } } -#' Run a covr test coverage check +#' Run a unit test coverage check #' #' Uses the `{covr}` package to produce unit test coverage reports. #' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 24239fc2..4c903935 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/tools.R \name{covr_r} \alias{covr_r} -\title{Run a covr test coverage check} +\title{Run a unit test coverage check} \usage{ covr_r( test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = From 019be637aecb0bccd182a73052e53edf2a35b0e0 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 27 Jan 2023 16:03:41 +0800 Subject: [PATCH 07/12] let covr_r search for test files recursively --- DESCRIPTION | 2 +- R/tools.R | 5 ++++- man/covr_r.Rd | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f587cc69..409ab736 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9002 +Version: 1.3.0.9003 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/R/tools.R b/R/tools.R index 1d79d88a..43938236 100644 --- a/R/tools.R +++ b/R/tools.R @@ -363,7 +363,10 @@ test_e2e <- function(interactive = FALSE) { #' #' @export covr_r <- function( - test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE), + test_files = list.files("tests/testthat", + pattern = "^test-.*\\.R", + full.names = TRUE, + recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL) { withr::with_file("box_loader.R", { diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 4c903935..aba8be0e 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -6,7 +6,7 @@ \usage{ covr_r( test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = - TRUE), + TRUE, recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL ) From ec28a9ebfaf68e9bf65e91c3bc1ef43cb65b21f1 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 27 Jan 2023 16:12:13 +0800 Subject: [PATCH 08/12] remove extra "a" --- R/tools.R | 2 +- man/covr_report.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tools.R b/R/tools.R index 43938236..a359dbc0 100644 --- a/R/tools.R +++ b/R/tools.R @@ -401,7 +401,7 @@ covr_r <- function( #' Uses the `{covr}` package to produce unit test coverage reports. #' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. #' -#' @param rhino_coverage a rhino coverage dataset, a defaults to `covr_r()`. +#' @param rhino_coverage a rhino coverage dataset, defaults to `covr_r()`. #' @param ... additional arguments to pass to #' [`covr::report()`](https://covr.r-lib.org/reference/report.html) #' @return None. This function is called for side effects. diff --git a/man/covr_report.Rd b/man/covr_report.Rd index a9b619e6..d813c218 100644 --- a/man/covr_report.Rd +++ b/man/covr_report.Rd @@ -7,7 +7,7 @@ covr_report(rhino_coverage = covr_r(), ...) } \arguments{ -\item{rhino_coverage}{a rhino coverage dataset, a defaults to \code{covr_r()}.} +\item{rhino_coverage}{a rhino coverage dataset, defaults to \code{covr_r()}.} \item{...}{additional arguments to pass to \href{https://covr.r-lib.org/reference/report.html}{\code{covr::report()}}} From 5a772e90566a54a5ad98ba70345a8b3e9036148e Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 18:56:00 +0800 Subject: [PATCH 09/12] add purge_box_cache() before any tests are run to clear the environment of box modules --- R/tools.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/tools.R b/R/tools.R index a359dbc0..fe0e76d4 100644 --- a/R/tools.R +++ b/R/tools.R @@ -11,6 +11,7 @@ #' } #' @export test_r <- function() { + purge_box_cache() testthat::test_dir(fs::path("tests", "testthat")) } @@ -369,6 +370,7 @@ covr_r <- function( recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL) { + purge_box_cache() withr::with_file("box_loader.R", { module_list <- sub( "__init__", From 45e7b26c5b5985f35fa368e02239d113c1044177 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 19:05:08 +0800 Subject: [PATCH 10/12] clean environment of box modules before running tests to avoid box::reload() calls in test files --- R/tools.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/tools.R b/R/tools.R index 53baf8b4..120f78fa 100644 --- a/R/tools.R +++ b/R/tools.R @@ -11,6 +11,7 @@ #' } #' @export test_r <- function() { + purge_box_cache() testthat::test_dir(fs::path("tests", "testthat")) } From a335bfaabd5498e47018e0a78dd6c75cc1ccdfdb Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 19:18:52 +0800 Subject: [PATCH 11/12] rationalize versions --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 409ab736..8f4703cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9003 +Version: 1.3.0.9104 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), From 9f3ec62877ed5b0d1ddd2c782a732a14e9a584cd Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 19:24:53 +0800 Subject: [PATCH 12/12] news entry --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 9f8e4063..7fc6ec04 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rhino (development version) + +1. Adds `covr` support for `rhino` apps. + # rhino 1.3.0 1. Rhino now works with `shinytest2` out of the box.