Skip to content

Commit

Permalink
use expect_no_error in tests instead of expect_error(, NA)
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Jan 23, 2024
1 parent 89d2ebc commit 9e5f898
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions tests/testthat/test-Archiver.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))

testthat::test_that("intialize Archiver", {
expect_error(Archiver$new(), NA)
testthat::expect_no_error(Archiver$new())
})

testthat::test_that("new returns an object of type Archiver", {
Expand All @@ -34,7 +34,7 @@ testthat::test_that("Archiver errors with the abstract methods", {
})

testthat::test_that("intialize FileArchiver", {
testthat::expect_error(FileArchiver$new(), NA)
testthat::expect_no_error(FileArchiver$new())
})

testthat::test_that("FileArchiver creates a temp directory when initialized", {
Expand All @@ -58,7 +58,7 @@ testthat::test_that("FileArchiver dectructor removes the temp dir", {
})

testthat::test_that("intialize JSONArchiver", {
testthat::expect_error(JSONArchiver$new(), NA)
testthat::expect_no_error(JSONArchiver$new())
})

testthat::test_that("JSONArchiver creates a temp directory when initialized", {
Expand All @@ -79,7 +79,7 @@ testthat::test_that("JSONArchiver dectructor removes the temp dir", {
archiver <- JSONArchiver$new()

testthat::test_that("JSONArchiver write a reporter", {
testthat::expect_error(archiver$write(reporter), NA)
testthat::expect_no_error(archiver$write(reporter))
})

path_with_files <- archiver$get_output_dir()
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-ContentBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("ContentBlock object can be created", {
testthat::expect_error(ContentBlock$new(), regexp = NA)
testthat::expect_no_error(ContentBlock$new())
})

testthat::test_that("new returns an object of type ContentBlock", {
Expand All @@ -8,7 +8,7 @@ testthat::test_that("new returns an object of type ContentBlock", {

testthat::test_that("set_content accepts a character object", {
block <- ContentBlock$new()
testthat::expect_error(block$set_content("test"), regexp = NA)
testthat::expect_no_error(block$set_content("test"))
})

testthat::test_that("set_content asserts the argument is character", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-DownloadReportModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ knitr_args <- list()
temp_dir <- tempdir()

testthat::test_that("report_render_and_compress - valid arguments", {
testthat::expect_error(report_render_and_compress(reporter, input, knitr_args, temp_dir), NA)
testthat::expect_no_error(report_render_and_compress(reporter, input, knitr_args, temp_dir))
})

testthat::test_that("report_render_and_compress - invalid arguments", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-FileBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("FileBlock object can be created", {
testthat::expect_error(FileBlock$new(), regexp = NA)
testthat::expect_no_error(FileBlock$new())
})

testthat::test_that("new returns an object of type FileBlock", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-NewpageBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("NewpageBlock object can be created", {
testthat::expect_error(NewpageBlock$new(), regexp = NA)
testthat::expect_no_error(NewpageBlock$new())
})

testthat::test_that("new returns an object of type NewpageBlock", {
Expand All @@ -8,5 +8,5 @@ testthat::test_that("new returns an object of type NewpageBlock", {

testthat::test_that("set_content accepts a string", {
block <- NewpageBlock$new()
testthat::expect_error(block$get_content(), regexp = NA)
testthat::expect_no_error(block$get_content())
})
6 changes: 3 additions & 3 deletions tests/testthat/test-RcodeBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("RcodeBlock object can be created", {
testthat::expect_error(RcodeBlock$new(), regexp = NA)
testthat::expect_no_error(RcodeBlock$new())
})

testthat::test_that("new returns an object of type RcodeBlock", {
Expand All @@ -8,7 +8,7 @@ testthat::test_that("new returns an object of type RcodeBlock", {

testthat::test_that("set_content accepts a string", {
block <- RcodeBlock$new()
testthat::expect_error(block$set_content("test"), regexp = NA)
testthat::expect_no_error(block$set_content("test"))
})

testthat::test_that("set_content asserts the argument is a string", {
Expand Down Expand Up @@ -37,7 +37,7 @@ testthat::test_that("set_params accepts one of the styles returned by get_availa
for (param in RcodeBlock$new()$get_available_params()) {
input <- list()
input[[param]] <- NULL
testthat::expect_error(RcodeBlock$new()$set_params(input), regexp = NA)
testthat::expect_no_error(RcodeBlock$new()$set_params(input))
}
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Renderer.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("Renderer object can be created", {
testthat::expect_error(Renderer$new(), regexp = NA)
testthat::expect_no_error(Renderer$new())
})

testthat::test_that("new returns an object of type Renderer", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-ReportCard.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
testthat::test_that("ReportCard object can be created", {
testthat::expect_error(ReportCard$new(), regexp = NA)
testthat::expect_no_error(ReportCard$new())
})

testthat::test_that("new returns an object of type ReportCard", {
testthat::expect_true(inherits(ReportCard$new(), "ReportCard"))
})

testthat::test_that("append_text accepts a character", {
testthat::expect_error(ReportCard$new()$append_text("test"), regexp = NA)
testthat::expect_no_error(ReportCard$new()$append_text("test"))
})

testthat::test_that("append_text returns self", {
Expand Down Expand Up @@ -85,8 +85,8 @@ testthat::test_that("append_metadata returns an object of type ReportCard", {
})

testthat::test_that("append_metadata accepts a character key and a character or list value", {
testthat::expect_error(ReportCard$new()$append_metadata("key1", "value1"), regexp = NA)
testthat::expect_error(ReportCard$new()$append_metadata("key1", list("value1")), regexp = NA)
testthat::expect_no_error(ReportCard$new()$append_metadata("key1", "value1"))
testthat::expect_no_error(ReportCard$new()$append_metadata("key1", list("value1")))
})

testthat::test_that("append_metadata throws error if key is not character", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-Reporter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("Reporter object can be created", {
testthat::expect_error(Reporter$new(), regexp = NA)
testthat::expect_no_error(Reporter$new())
})

testthat::test_that("new returns an object of type Reporter", {
Expand Down Expand Up @@ -77,7 +77,7 @@ testthat::test_that("reactive_add_card", {

testthat::test_that("append_metadata accept only named list", {
reporter <- Reporter$new()
testthat::expect_error(reporter$append_metadata(list(sth = "sth")), NA)
testthat::expect_no_error(reporter$append_metadata(list(sth = "sth")))
testthat::expect_error(reporter$append_metadata("sth"), "'list', not 'character'")
testthat::expect_error(reporter$append_metadata(list("sth")), "Must have names")
})
Expand All @@ -86,13 +86,13 @@ testthat::test_that("append_metadata accept only unique names which could not be
reporter <- Reporter$new()
testthat::expect_error(reporter$append_metadata(list(sth = "sth", sth = 2)), "but element 2 is duplicated")
reporter <- Reporter$new()
testthat::expect_error(reporter$append_metadata(list(sth = "sth")), NA)
testthat::expect_no_error(reporter$append_metadata(list(sth = "sth")))
testthat::expect_error(reporter$append_metadata(list(sth = "sth")), "failed: Must be TRUE")
})

testthat::test_that("get_metadata", {
reporter <- Reporter$new()
testthat::expect_error(reporter$append_metadata(list(sth = "sth")), NA)
testthat::expect_no_error(reporter$append_metadata(list(sth = "sth")))
testthat::expect_identical(reporter$get_metadata(), list(sth = "sth"))
})

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-TableBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("TableBlock object can be created", {
testthat::expect_error(TableBlock$new(), regexp = NA)
testthat::expect_no_error(TableBlock$new())
})

testthat::test_that("new returns an object of type TableBlock", {
Expand All @@ -8,7 +8,7 @@ testthat::test_that("new returns an object of type TableBlock", {

testthat::test_that("set_content accepts a table object", {
block <- TableBlock$new()
testthat::expect_error(block$set_content(iris), regexp = NA)
testthat::expect_no_error(block$set_content(iris))
})

testthat::test_that("set_content asserts the argument is a plot", {
Expand Down Expand Up @@ -52,7 +52,7 @@ testthat::test_that("from_list after to_list to save and retrive", {

testthat::test_that("set_content supports data.frame object", {
block <- TableBlock$new()
testthat::expect_error(block$set_content(iris), NA)
testthat::expect_no_error(block$set_content(iris))
})

testthat::test_that("set_content supports rtables object", {
Expand All @@ -65,5 +65,5 @@ testthat::test_that("set_content supports rtables object", {
"range" = diff(range(x))
)
})
testthat::expect_error(block$set_content(rtables::build_table(l, iris)), NA)
testthat::expect_no_error(block$set_content(rtables::build_table(l, iris)))
})
6 changes: 3 additions & 3 deletions tests/testthat/test-TextBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("TextBlock object can be created", {
testthat::expect_error(TextBlock$new(), regexp = NA)
testthat::expect_no_error(TextBlock$new())
})

testthat::test_that("new returns an object of type TextBlock", {
Expand All @@ -8,7 +8,7 @@ testthat::test_that("new returns an object of type TextBlock", {

testthat::test_that("set_content accepts a string", {
block <- TextBlock$new()
testthat::expect_error(block$set_content("test"), regexp = NA)
testthat::expect_no_error(block$set_content("test"))
})

testthat::test_that("set_content asserts the argument is a string", {
Expand All @@ -35,7 +35,7 @@ testthat::test_that("get_available_styles returns an array of character", {

testthat::test_that("set_style accepts one of the styles returned by get_available_styles", {
for (style in TextBlock$new()$get_available_styles()) {
testthat::expect_error(TextBlock$new()$set_style(!!style), regexp = NA)
testthat::expect_no_error(TextBlock$new()$set_style(!!style))
}
})

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-yaml_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ testthat::test_that("yaml_quoted does not modify the value of the object", {

testthat::test_that("conv_str_logi - accept only a string", {
testthat::expect_error(conv_str_logi(2))
testthat::expect_error(conv_str_logi("string"), NA)
testthat::expect_no_error(conv_str_logi("string"))
})

testthat::test_that("conv_str_logi - not influence the regular character", {
Expand Down Expand Up @@ -47,8 +47,8 @@ testthat::test_that("rmd_outputs - all returned out in the rmarkdown namespace",

testthat::test_that("rmd_output_arguments - accepts only string from possible rmarkdown outputs", {
testthat::expect_error(rmd_output_arguments("random_text"))
testthat::expect_error(rmd_output_arguments("pdf_document"), NA)
testthat::expect_error(rmd_output_arguments("pdf_document", TRUE), NA)
testthat::expect_no_error(rmd_output_arguments("pdf_document"))
testthat::expect_no_error(rmd_output_arguments("pdf_document", TRUE))
})

testthat::test_that("rmd_output_arguments - returned all pdf_document arguments", {
Expand All @@ -69,8 +69,8 @@ testthat::test_that("as_yaml_auto - accept a named list (optionally nested)", {
testthat::expect_error(as_yaml_auto(list(1)))
testthat::expect_error(as_yaml_auto("sth"))

testthat::expect_error(as_yaml_auto(list(author = "", output = list(pdf_document = list(toc = TRUE)))), NA)
testthat::expect_error(as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE)), NA)
testthat::expect_no_error(as_yaml_auto(list(author = "", output = list(pdf_document = list(toc = TRUE)))))
testthat::expect_no_error(as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE)))
})

testthat::test_that("as_yaml_auto - works the same as yaml::as.yaml for a nested list when as_header is FALSE", {
Expand Down

0 comments on commit 9e5f898

Please sign in to comment.