Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include add_before and add_after in new item functions #91

Merged
merged 7 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions R/case.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#' are located at `./inst/validation/<ItemType>/{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.
#'
Expand All @@ -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")

Expand All @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion R/code.R
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion R/req.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
27 changes: 23 additions & 4 deletions man/new_item.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions tests/testthat/test-coverage-matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = "."),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 = "."),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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())

Expand Down
48 changes: 47 additions & 1 deletion tests/testthat/test-use_req.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test_that("Creating requirements adds correct extension", {
)

req_path2 <- vt_use_req(
name = "req001.badext",
name = "req002.badext",
open = FALSE
)

Expand All @@ -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"
)
)
})
})
49 changes: 48 additions & 1 deletion tests/testthat/test-use_test_case.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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"
)
)
})
})

48 changes: 47 additions & 1 deletion tests/testthat/test-use_test_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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"
)
)
})
})
Loading