From 8e693c78801a4bcb4b8b2759866584531d048637 Mon Sep 17 00:00:00 2001 From: elimillera Date: Thu, 8 Apr 2021 02:20:11 +0000 Subject: [PATCH 1/4] Include add_before and add_after in new item functions --- R/case.R | 12 ++++++-- R/code.R | 7 ++++- R/req.R | 6 +++- man/new_item.Rd | 18 ++++++++--- tests/testthat/test-use_req.R | 46 ++++++++++++++++++++++++++++ tests/testthat/test-use_test_case.R | 47 +++++++++++++++++++++++++++++ tests/testthat/test-use_test_code.R | 46 ++++++++++++++++++++++++++++ 7 files changed, 174 insertions(+), 8 deletions(-) diff --git a/R/case.R b/R/case.R index a4dfa48..a2698b6 100644 --- a/R/case.R +++ b/R/case.R @@ -6,6 +6,9 @@ #' @param username The username to insert into the validation item as the author. #' @param open Should the newly made file be opened for editing. #' @param pkg Top-level of package +#' @param add_before,add_after If either parameters is supplied, the location to +#' add the validation item to the validation configuration. If no parameter is +#' passed the item is added at the end. #' #' @return Path to the newly created validation item file, invisibly. #' @@ -28,10 +31,11 @@ #' # Create req at the cases top level `inst/validation/cases/case1` #' vt_use_test_case("case1", open = FALSE) #' # Create req at `inst/validation/cases/regTests/Update2/case2` -#' vt_use_test_case("regTests/Update2/case2", open = FALSE) +#' vt_use_test_case("regTests/Update2/case2", open = FALSE, add_before = "case1.md") #' #' }) -vt_use_test_case <- function(name, username = vt_username(), title = NULL, open = interactive(), pkg = ".") { +vt_use_test_case <- function(name, username = vt_username(), title = NULL, open = interactive(), + pkg = ".", add_before = NULL, add_after = NULL) { name <- vt_set_ext(name, ext = "md") @@ -56,6 +60,10 @@ vt_use_test_case <- function(name, username = vt_username(), title = NULL, open } + # Add file to validation configuration + vt_add_file_to_config(filename = name, pkg = pkg, after = add_after, + before = add_before) + if(open){ edit_file(case_name) } diff --git a/R/code.R b/R/code.R index 57fcb38..1dbc925 100644 --- a/R/code.R +++ b/R/code.R @@ -1,7 +1,8 @@ # The rest of this documentation is in case.R #' @export #' @rdname new_item -vt_use_test_code <- function(name, username = vt_username(), open = interactive(), pkg = ".") { +vt_use_test_code <- function(name, username = vt_username(), open = interactive(), pkg = ".", + add_before = NULL, add_after = NULL) { name <- vt_set_ext(name, ext = "R") @@ -21,6 +22,10 @@ vt_use_test_code <- function(name, username = vt_username(), open = interactive( )) } + # Add file to validation configuration + vt_add_file_to_config(filename = name, pkg = pkg, after = add_after, + before = add_before) + if(open){ edit_file(code_name) } diff --git a/R/req.R b/R/req.R index b363799..464cf7e 100644 --- a/R/req.R +++ b/R/req.R @@ -4,7 +4,8 @@ #' #' @rdname new_item #' @export -vt_use_req <- function(name, username = vt_username(), title = NULL, open = interactive(), pkg = "."){ +vt_use_req <- function(name, username = vt_username(), title = NULL, open = interactive(), + pkg = ".", add_before = NULL, add_after = NULL){ # ensure file extensions are of the acceptable type name <- vt_set_ext(name, ext = "md") @@ -30,6 +31,9 @@ vt_use_req <- function(name, username = vt_username(), title = NULL, open = inte )) } + vt_add_file_to_config(filename = name, pkg = pkg, after = add_after, + before = add_before) + if(open){ edit_file(req_name) } diff --git a/man/new_item.Rd b/man/new_item.Rd index 973b25c..add9a1d 100644 --- a/man/new_item.Rd +++ b/man/new_item.Rd @@ -11,14 +11,18 @@ vt_use_test_case( username = vt_username(), title = NULL, open = interactive(), - pkg = "." + pkg = ".", + add_before = NULL, + add_after = NULL ) vt_use_test_code( name, username = vt_username(), open = interactive(), - pkg = "." + pkg = ".", + add_before = NULL, + add_after = NULL ) vt_use_req( @@ -26,7 +30,9 @@ vt_use_req( username = vt_username(), title = NULL, open = interactive(), - pkg = "." + pkg = ".", + add_before = NULL, + add_after = NULL ) } \arguments{ @@ -42,6 +48,10 @@ sans file paths or extensions.} \item{open}{Should the newly made file be opened for editing.} \item{pkg}{Top-level of package} + +\item{add_before, add_after}{If either parameters is supplied, the location to +add the validation item to the validation configuration. If no parameter is +passed the item is added at the end.} } \value{ Path to the newly created validation item file, invisibly. @@ -62,7 +72,7 @@ vt_add_user_to_config( # Create req at the cases top level `inst/validation/cases/case1` vt_use_test_case("case1", open = FALSE) # Create req at `inst/validation/cases/regTests/Update2/case2` -vt_use_test_case("regTests/Update2/case2", open = FALSE) +vt_use_test_case("regTests/Update2/case2", open = FALSE, add_before = "case1.md") }) } diff --git a/tests/testthat/test-use_req.R b/tests/testthat/test-use_req.R index ea7bedc..ddfdef8 100644 --- a/tests/testthat/test-use_req.R +++ b/tests/testthat/test-use_req.R @@ -123,3 +123,49 @@ test_that("Creating requirements adds correct extension", { }) }) + +test_that("Cases are added to the config file", { + withr::with_tempdir({ + vt_create_package("example.package", open = FALSE) + setwd("example.package") + vt_add_user_to_config( + username = whoami::username(), + name = "Sample Name", + title = "Sample", + role = "example" + ) + + vt_use_req("req1", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 2), + c( + "validation_files:", + "- req1.md" + ) + ) + + vt_use_test_case("req2", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 3), + c( + "validation_files:", + "- req1.md", + "- req2.md" + ) + ) + + vt_use_test_case("req1a", add_after = "req1.md", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 4), + c( + "validation_files:", + "- req1.md", + "- req1a.md", + "- req2.md" + ) + ) + }) +}) diff --git a/tests/testthat/test-use_test_case.R b/tests/testthat/test-use_test_case.R index 33277ac..852f098 100644 --- a/tests/testthat/test-use_test_case.R +++ b/tests/testthat/test-use_test_case.R @@ -129,3 +129,50 @@ test_that("Creating test cases adds correct extension", { }) }) + +test_that("Cases are added to the config file", { + withr::with_tempdir({ + vt_create_package("example.package", open = FALSE) + setwd("example.package") + vt_add_user_to_config( + username = whoami::username(), + name = "Sample Name", + title = "Sample", + role = "example" + ) + + vt_use_test_case("case1", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 2), + c( + "validation_files:", + "- case1.md" + ) + ) + + vt_use_test_case("case2", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 3), + c( + "validation_files:", + "- case1.md", + "- case2.md" + ) + ) + + vt_use_test_case("case1a", add_after = "case1.md", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 4), + c( + "validation_files:", + "- case1.md", + "- case1a.md", + "- case2.md" + ) + ) + }) +}) + diff --git a/tests/testthat/test-use_test_code.R b/tests/testthat/test-use_test_code.R index 337d49b..ddacd94 100644 --- a/tests/testthat/test-use_test_code.R +++ b/tests/testthat/test-use_test_code.R @@ -133,3 +133,49 @@ test_that("Creating test codes adds correct extension", { }) }) + +test_that("Test Codes are added to the config file", { + withr::with_tempdir({ + vt_create_package("example.package", open = FALSE) + setwd("example.package") + vt_add_user_to_config( + username = whoami::username(), + name = "Sample Name", + title = "Sample", + role = "example" + ) + + vt_use_test_code("code1", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 2), + c( + "validation_files:", + "- code1.R" + ) + ) + + vt_use_test_code("code2", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 3), + c( + "validation_files:", + "- code1.R", + "- code2.R" + ) + ) + + vt_use_test_code("code1a", add_after = "code1.R", open = FALSE) + + expect_equal( + tail(readLines("validation.yml"), 4), + c( + "validation_files:", + "- code1.R", + "- code1a.R", + "- code2.R" + ) + ) + }) +}) From 89c971b393dbfbeab2a4fe1f71672177b5884f97 Mon Sep 17 00:00:00 2001 From: elimillera Date: Fri, 9 Apr 2021 19:33:54 +0000 Subject: [PATCH 2/4] Remove pkg --- R/case.R | 6 ++---- R/code.R | 4 ++-- R/req.R | 5 ++--- man/new_item.Rd | 5 ----- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/R/case.R b/R/case.R index fe16da7..ac14a40 100644 --- a/R/case.R +++ b/R/case.R @@ -5,7 +5,6 @@ #' are located at `./inst/validation//{name}`. #' @param username The username to insert into the validation item as the author. #' @param open Should the newly made file be opened for editing. -#' @param pkg Top-level of package #' @param add_before,add_after If either parameters is supplied, the location to #' add the validation item to the validation configuration. If no parameter is #' passed the item is added at the end. @@ -35,7 +34,7 @@ #' #' }) vt_use_test_case <- function(name, username = vt_username(), title = NULL, open = interactive(), - pkg = ".", add_before = NULL, add_after = NULL) { + add_before = NULL, add_after = NULL) { name <- vt_set_ext(name, ext = "md") @@ -61,8 +60,7 @@ vt_use_test_case <- function(name, username = vt_username(), title = NULL, open } # Add file to validation configuration - vt_add_file_to_config(filename = name, pkg = pkg, after = add_after, - before = add_before) + vt_add_file_to_config(filename = name, after = add_after, before = add_before) if(open){ edit_file(case_name) diff --git a/R/code.R b/R/code.R index f808dd1..25cc3ab 100644 --- a/R/code.R +++ b/R/code.R @@ -1,7 +1,7 @@ # The rest of this documentation is in case.R #' @export #' @rdname new_item -vt_use_test_code <- function(name, username = vt_username(), open = interactive(), pkg = ".", +vt_use_test_code <- function(name, username = vt_username(), open = interactive(), add_before = NULL, add_after = NULL) { name <- vt_set_ext(name, ext = "R") @@ -23,7 +23,7 @@ vt_use_test_code <- function(name, username = vt_username(), open = interactive( } # Add file to validation configuration - vt_add_file_to_config(filename = name, pkg = pkg, after = add_after, + vt_add_file_to_config(filename = name, after = add_after, before = add_before) if(open){ diff --git a/R/req.R b/R/req.R index 79bb1f9..f05625e 100644 --- a/R/req.R +++ b/R/req.R @@ -5,7 +5,7 @@ #' @rdname new_item #' @export vt_use_req <- function(name, username = vt_username(), title = NULL, open = interactive(), - pkg = ".", add_before = NULL, add_after = NULL){ + add_before = NULL, add_after = NULL){ # ensure file extensions are of the acceptable type name <- vt_set_ext(name, ext = "md") @@ -31,8 +31,7 @@ vt_use_req <- function(name, username = vt_username(), title = NULL, open = inte )) } - vt_add_file_to_config(filename = name, pkg = pkg, after = add_after, - before = add_before) + vt_add_file_to_config(filename = name, after = add_after, before = add_before) if(open){ edit_file(req_name) diff --git a/man/new_item.Rd b/man/new_item.Rd index add9a1d..38955ab 100644 --- a/man/new_item.Rd +++ b/man/new_item.Rd @@ -11,7 +11,6 @@ vt_use_test_case( username = vt_username(), title = NULL, open = interactive(), - pkg = ".", add_before = NULL, add_after = NULL ) @@ -20,7 +19,6 @@ vt_use_test_code( name, username = vt_username(), open = interactive(), - pkg = ".", add_before = NULL, add_after = NULL ) @@ -30,7 +28,6 @@ vt_use_req( username = vt_username(), title = NULL, open = interactive(), - pkg = ".", add_before = NULL, add_after = NULL ) @@ -47,8 +44,6 @@ sans file paths or extensions.} \item{open}{Should the newly made file be opened for editing.} -\item{pkg}{Top-level of package} - \item{add_before, add_after}{If either parameters is supplied, the location to add the validation item to the validation configuration. If no parameter is passed the item is added at the end.} From a5f6b54b19bd1bf8c5859e03957a43e340865005 Mon Sep 17 00:00:00 2001 From: elimillera Date: Sat, 10 Apr 2021 23:16:41 +0000 Subject: [PATCH 3/4] Updates tests for auto addition of cases, codes, and reqs --- tests/testthat/test-coverage-matrix.R | 24 ++++++++++-------------- tests/testthat/test-use_req.R | 8 ++++---- tests/testthat/test-use_test_case.R | 8 ++++---- tests/testthat/test-use_test_code.R | 8 ++++---- tests/testthat/test-vt_scrape_roxygen.R | 18 +++++++++--------- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/tests/testthat/test-coverage-matrix.R b/tests/testthat/test-coverage-matrix.R index cf246eb..fc25523 100644 --- a/tests/testthat/test-coverage-matrix.R +++ b/tests/testthat/test-coverage-matrix.R @@ -4,9 +4,9 @@ test_that("coverage matrix from dynam num", { vt_use_test_case("testcase1", username = "a user", open = FALSE) vt_use_test_case("testcase2", username = "a user", open = FALSE) vt_use_test_case("testcase3", username = "a user", open = FALSE) - vt_use_req("req1", username = "a user", open = FALSE) - vt_use_req("req2", username = "a user", open = FALSE) - vt_use_req("req3", username = "a user", open = FALSE) + vt_use_req("req1", username = "a user", open = FALSE, add_before = "testcase1.md") + vt_use_req("req2", username = "a user", open = FALSE, add_before = "testcase2.md") + vt_use_req("req3", username = "a user", open = FALSE, add_before = "testcase3.md") config_wd <- get_config_working_dir() cat( @@ -62,7 +62,7 @@ test_that("coverage matrix from dynam num", { " + T##tc:dynamic_numbering_testcase3.1 More testing. Matches requirements: ##req:dynamic_numbering3.1, ##req:dynamic_numbering3.3, and ##req:dynamic_numbering3.4", "")) - vt_add_file_to_config(c("req1.md", "testcase1.md", "req2.md", "testcase2.md", "req3.md", "testcase3.md")) + #vt_add_file_to_config(c("req1.md", "testcase1.md", "req2.md", "testcase2.md", "req3.md", "testcase3.md")) cov_matrix <- vt_scrape_coverage_matrix() expect_matrix <- data.frame(req_title = rep(paste("Requirement", 1:3), each = 7), req_id = paste(rep(1:3, each = 7), rep(c(1, 1, 2, 2, 3, 3, 4), 3), sep = "."), @@ -277,9 +277,9 @@ test_that("coverage matrix no dynam num", { vt_use_test_case("testcase1", username = "a user", open = FALSE) vt_use_test_case("testcase2", username = "a user", open = FALSE) vt_use_test_case("testcase3", username = "a user", open = FALSE) - vt_use_req("req1", username = "a user", open = FALSE) - vt_use_req("req2", username = "a user", open = FALSE) - vt_use_req("req3", username = "a user", open = FALSE) + vt_use_req("req1", username = "a user", open = FALSE, add_before = "testcase1.md") + vt_use_req("req2", username = "a user", open = FALSE, add_before = "testcase2.md") + vt_use_req("req3", username = "a user", open = FALSE, add_before = "testcase3.md") config_wd <- get_config_working_dir() cat( @@ -335,7 +335,6 @@ test_that("coverage matrix no dynam num", { " + T3.1 More testing. Matches requirements: 3.1, 3.3, and 3.4", "")) - vt_add_file_to_config(c("req1.md", "testcase1.md", "req2.md", "testcase2.md", "req3.md", "testcase3.md")) cov_matrix <- vt_scrape_coverage_matrix() expect_matrix <- data.frame(req_title = rep(paste("Requirement", 1:3), each = 7), req_id = paste(rep(1:3, each = 7), rep(c(1, 1, 2, 2, 3, 3, 4), 3), sep = "."), @@ -382,9 +381,9 @@ test_that("existing reference obj", { vt_use_test_case("testcase1", username = "a user", open = FALSE) vt_use_test_case("testcase2", username = "a user", open = FALSE) vt_use_test_case("testcase3", username = "a user", open = FALSE) - vt_use_req("req1", username = "a user", open = FALSE) - vt_use_req("req2", username = "a user", open = FALSE) - vt_use_req("req3", username = "a user", open = FALSE) + vt_use_req("req1", username = "a user", open = FALSE, add_before = "testcase1.md") + vt_use_req("req2", username = "a user", open = FALSE, add_before = "testcase2.md") + vt_use_req("req3", username = "a user", open = FALSE, add_before = "testcase3.md") config_wd <- get_config_working_dir() cat( @@ -461,9 +460,6 @@ test_that("existing reference obj", { "+ Start documenting requirements here!", "")) - - vt_add_file_to_config(c("req1.md", "testcase1.md", "req2.md", "testcase2.md", "req3.md", "testcase3.md")) - references <- vt_dynamic_referencer$new() expect_equal(references$list_references(), list()) diff --git a/tests/testthat/test-use_req.R b/tests/testthat/test-use_req.R index 97c82b8..7449d84 100644 --- a/tests/testthat/test-use_req.R +++ b/tests/testthat/test-use_req.R @@ -106,7 +106,7 @@ test_that("Creating requirements adds correct extension", { ) req_path2 <- vt_use_req( - name = "req001.badext", + name = "req002.badext", open = FALSE ) @@ -138,7 +138,7 @@ test_that("Cases are added to the config file", { vt_use_req("req1", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 2), + tail(readLines("vignettes/validation/validation.yml"), 2), c( "validation_files:", "- req1.md" @@ -148,7 +148,7 @@ test_that("Cases are added to the config file", { vt_use_test_case("req2", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 3), + tail(readLines("vignettes/validation/validation.yml"), 3), c( "validation_files:", "- req1.md", @@ -159,7 +159,7 @@ test_that("Cases are added to the config file", { vt_use_test_case("req1a", add_after = "req1.md", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 4), + tail(readLines("vignettes/validation/validation.yml"), 4), c( "validation_files:", "- req1.md", diff --git a/tests/testthat/test-use_test_case.R b/tests/testthat/test-use_test_case.R index 4d7abf4..fe4a002 100644 --- a/tests/testthat/test-use_test_case.R +++ b/tests/testthat/test-use_test_case.R @@ -112,7 +112,7 @@ test_that("Creating test cases adds correct extension", { ) test_case_path2 <- vt_use_test_case( - name = "testcase001.badext", + name = "testcase002.badext", open = FALSE ) @@ -144,7 +144,7 @@ test_that("Cases are added to the config file", { vt_use_test_case("case1", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 2), + tail(readLines("vignettes/validation/validation.yml"), 2), c( "validation_files:", "- case1.md" @@ -154,7 +154,7 @@ test_that("Cases are added to the config file", { vt_use_test_case("case2", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 3), + tail(readLines("vignettes/validation/validation.yml"), 3), c( "validation_files:", "- case1.md", @@ -165,7 +165,7 @@ test_that("Cases are added to the config file", { vt_use_test_case("case1a", add_after = "case1.md", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 4), + tail(readLines("vignettes/validation/validation.yml"), 4), c( "validation_files:", "- case1.md", diff --git a/tests/testthat/test-use_test_code.R b/tests/testthat/test-use_test_code.R index 1a28b6b..9d82777 100644 --- a/tests/testthat/test-use_test_code.R +++ b/tests/testthat/test-use_test_code.R @@ -116,7 +116,7 @@ test_that("Creating test codes adds correct extension", { ) test_code_path2 <- vt_use_test_code( - name = "testcode001.badext", + name = "testcode002.badext", open = FALSE ) @@ -148,7 +148,7 @@ test_that("Test Codes are added to the config file", { vt_use_test_code("code1", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 2), + tail(readLines("vignettes/validation/validation.yml"), 2), c( "validation_files:", "- code1.R" @@ -158,7 +158,7 @@ test_that("Test Codes are added to the config file", { vt_use_test_code("code2", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 3), + tail(readLines("vignettes/validation/validation.yml"), 3), c( "validation_files:", "- code1.R", @@ -169,7 +169,7 @@ test_that("Test Codes are added to the config file", { vt_use_test_code("code1a", add_after = "code1.R", open = FALSE) expect_equal( - tail(readLines("validation.yml"), 4), + tail(readLines("vignettes/validation/validation.yml"), 4), c( "validation_files:", "- code1.R", diff --git a/tests/testthat/test-vt_scrape_roxygen.R b/tests/testthat/test-vt_scrape_roxygen.R index ef9ab2a..38c577b 100644 --- a/tests/testthat/test-vt_scrape_roxygen.R +++ b/tests/testthat/test-vt_scrape_roxygen.R @@ -16,12 +16,12 @@ test_that("parsing R function files as expected", { sep = "\n", file = fil ) - + block_list <- vt_scrape_roxygen(fil) - + expect_equal(roxygen2::block_get_tag(block_list[[1]], "editor")$val, "Sample Editor") - + expect_equal(roxygen2::block_get_tag(block_list[[1]], "editDate")$val, "1900-01-01") }) @@ -44,12 +44,12 @@ test_that("parsing R test files as expected", { sep = "\n", file = fil ) - + block_list <- vt_scrape_roxygen(fil,type = "r_test_code") - + expect_equal(roxygen2::block_get_tag(block_list[[1]], "editor")$val, "Sample Editor") - + expect_equal(roxygen2::block_get_tag(block_list[[1]], "editDate")$val, "1900-01-01") }) @@ -71,12 +71,12 @@ test_that("parsing md files as expected", { sep = "\n", file = fil ) - + block_list <- vt_scrape_roxygen(fil) - + expect_equal(roxygen2::block_get_tag(block_list[[1]], "editor")$val, "Sample Editor") - + expect_equal(roxygen2::block_get_tag(block_list[[1]], "editDate")$val, "1900-01-01") }) From 073882a89b8ac3588c87d878b14222b7a4827b61 Mon Sep 17 00:00:00 2001 From: Marie Vendettuoli Date: Mon, 12 Apr 2021 15:15:21 -0700 Subject: [PATCH 4/4] document --- NAMESPACE | 1 - 1 file changed, 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 8e95c89..45a69fb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,7 +39,6 @@ export(vt_scrape_tags_from) export(vt_scrape_val_env) export(vt_use_config) export(vt_use_news_md) -export(vt_use_report) export(vt_use_req) export(vt_use_test_case) export(vt_use_test_code)