diff --git a/R/case.R b/R/case.R index da46b2c..ac14a40 100644 --- a/R/case.R +++ b/R/case.R @@ -5,6 +5,9 @@ #' 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 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. #' @@ -27,10 +30,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()) { +vt_use_test_case <- function(name, username = vt_username(), title = NULL, open = interactive(), + add_before = NULL, add_after = NULL) { name <- vt_set_ext(name, ext = "md") @@ -55,6 +59,9 @@ vt_use_test_case <- function(name, username = vt_username(), title = NULL, open } + # Add file to validation configuration + 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 fa96a89..25cc3ab 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()) { +vt_use_test_code <- function(name, username = vt_username(), open = interactive(), + 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, after = add_after, + before = add_before) + if(open){ edit_file(code_name) } diff --git a/R/req.R b/R/req.R index f8c73fa..f05625e 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()){ +vt_use_req <- function(name, username = vt_username(), title = NULL, open = interactive(), + add_before = NULL, add_after = NULL){ # ensure file extensions are of the acceptable type name <- vt_set_ext(name, ext = "md") @@ -30,6 +31,8 @@ vt_use_req <- function(name, username = vt_username(), title = NULL, open = inte )) } + 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 008ce9a..38955ab 100644 --- a/man/new_item.Rd +++ b/man/new_item.Rd @@ -10,12 +10,27 @@ vt_use_test_case( name, username = vt_username(), title = NULL, - open = interactive() + open = interactive(), + add_before = NULL, + add_after = NULL ) -vt_use_test_code(name, username = vt_username(), open = interactive()) +vt_use_test_code( + name, + username = vt_username(), + open = interactive(), + add_before = NULL, + add_after = NULL +) -vt_use_req(name, username = vt_username(), title = NULL, open = interactive()) +vt_use_req( + name, + username = vt_username(), + title = NULL, + open = interactive(), + add_before = NULL, + add_after = NULL +) } \arguments{ \item{name}{The name/path of the validation item. These can be named with your @@ -28,6 +43,10 @@ are located at \verb{./inst/validation//\{name\}}.} sans file paths or extensions.} \item{open}{Should the newly made file be opened for editing.} + +\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. @@ -48,7 +67,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-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 bd7413b..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 ) @@ -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("vignettes/validation/validation.yml"), 2), + c( + "validation_files:", + "- req1.md" + ) + ) + + vt_use_test_case("req2", open = FALSE) + + expect_equal( + tail(readLines("vignettes/validation/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("vignettes/validation/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 bd5caa9..6ce8b63 100644 --- a/tests/testthat/test-use_test_case.R +++ b/tests/testthat/test-use_test_case.R @@ -110,7 +110,7 @@ test_that("Creating test cases adds correct extension", { ) test_case_path2 <- vt_use_test_case( - name = "testcase001.badext", + name = "testcase002.badext", open = FALSE ) @@ -127,3 +127,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("vignettes/validation/validation.yml"), 2), + c( + "validation_files:", + "- case1.md" + ) + ) + + vt_use_test_case("case2", open = FALSE) + + expect_equal( + tail(readLines("vignettes/validation/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("vignettes/validation/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 5076d40..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 ) @@ -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("vignettes/validation/validation.yml"), 2), + c( + "validation_files:", + "- code1.R" + ) + ) + + vt_use_test_code("code2", open = FALSE) + + expect_equal( + tail(readLines("vignettes/validation/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("vignettes/validation/validation.yml"), 4), + c( + "validation_files:", + "- code1.R", + "- code1a.R", + "- code2.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") })