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 2 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
13 changes: 11 additions & 2 deletions R/case.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#' 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 pkg Top-level of package
elimillera marked this conversation as resolved.
Show resolved Hide resolved
#' @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 +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()) {
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")

Expand All @@ -55,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)
}
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(), pkg = ".",
elimillera marked this conversation as resolved.
Show resolved Hide resolved
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, pkg = pkg, after = add_after,
elimillera marked this conversation as resolved.
Show resolved Hide resolved
before = add_before)

if(open){
edit_file(code_name)
}
Expand Down
6 changes: 5 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(),
pkg = ".", 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,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)
}
Expand Down
32 changes: 28 additions & 4 deletions man/new_item.Rd

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

4 changes: 3 additions & 1 deletion man/vt_scrape_news.Rd

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

2 changes: 1 addition & 1 deletion man/vt_use_news_md.Rd

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

46 changes: 46 additions & 0 deletions tests/testthat/test-use_req.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
})
})
47 changes: 47 additions & 0 deletions tests/testthat/test-use_test_case.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
})
})

46 changes: 46 additions & 0 deletions tests/testthat/test-use_test_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
})
})