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
Reporter output control via "file" argument or options setting (#629) #635
Changes from 7 commits
53f43be
4b9a35c
3f4d3b0
3bd5ea8
85fab9e
bd2fb1e
e54aea1
71fa6fc
22f9a09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,14 @@ test_that("character vector yields multi reporter", { | |
) | ||
}) | ||
|
||
test_reporter <- function(reporter) { | ||
# Function to run the reporter "test suite" with a given reporter | ||
withr::with_options( | ||
list(expressions = Cstack_info()[["eval_depth"]] + 200), | ||
test_file(test_path("reporters/tests.R"), reporter, wrap = FALSE) | ||
) | ||
} | ||
|
||
test_that("reporters produce consistent output", { | ||
old <- options(width = 80) | ||
on.exit(options(old), add = TRUE) | ||
|
@@ -47,10 +55,7 @@ test_that("reporters produce consistent output", { | |
|
||
expect_known_output( | ||
expect_error( | ||
withr::with_options( | ||
list(expressions = Cstack_info()[["eval_depth"]] + 200), | ||
test_file(test_path("reporters/tests.R"), reporter, wrap = FALSE) | ||
), | ||
test_reporter(reporter), | ||
error_regexp | ||
), | ||
path, update = TRUE) | ||
|
@@ -77,4 +82,111 @@ test_that("reporters produce consistent output", { | |
save_report("silent") | ||
save_report("rstudio") | ||
save_report("junit", reporter = createJunitReporterMock()) | ||
|
||
# Test that MultiReporter can write to two different places | ||
tap_file <- tempfile() | ||
save_report("summary", reporter = MultiReporter$new(list( | ||
SummaryReporter$new(show_praise = FALSE, omit_dots = FALSE), | ||
TapReporter$new(file=tap_file)) | ||
)) | ||
expect_identical(read_lines(tap_file), | ||
read_lines(test_path("reporters", "tap.txt"))) | ||
}) | ||
|
||
|
||
test_report_to_file <- function(name, reporter = find_reporter_one(name, ...), | ||
output_file, error_regexp=NA, ...) { | ||
# output_file is where we expect output to be written to, whether we pass it | ||
# as an argument to Reporter$new() (here, via the ...), or whether it is set | ||
# in an option. | ||
path <- test_path("reporters", paste0(name, ".txt")) | ||
expect_silent( | ||
expect_error( | ||
test_reporter(reporter), | ||
error_regexp | ||
) | ||
) | ||
expect_identical(read_lines(output_file), read_lines(path)) | ||
} | ||
|
||
test_that("reporters accept a 'file' arugment and write to that location", { | ||
output <- tempfile() | ||
test_report_to_file("check", file = output, error_regexp=NULL, output_file = output) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only need to test each reporter once, i.e. not multiple times for |
||
test_report_to_file( | ||
"progress", | ||
ProgressReporter$new(show_praise = FALSE, min_time = Inf, file = output), | ||
output_file = output | ||
) | ||
test_report_to_file( | ||
"summary", | ||
SummaryReporter$new(show_praise = FALSE, omit_dots = FALSE, file = output), | ||
output_file = output | ||
) | ||
test_report_to_file( | ||
"summary-2", | ||
SummaryReporter$new(show_praise = FALSE, max_reports = 2, file = output), | ||
output_file = output | ||
) | ||
test_report_to_file( | ||
"summary-no-dots", | ||
SummaryReporter$new(show_praise = FALSE, omit_dots = TRUE, file = output), | ||
output_file = output | ||
) | ||
test_report_to_file("location", file = output, output_file = output) | ||
test_report_to_file("minimal", file = output, output_file = output) | ||
test_report_to_file("tap", file = output, output_file = output) | ||
test_report_to_file("teamcity", file = output, output_file = output) | ||
test_report_to_file("rstudio", file = output, output_file = output) | ||
test_report_to_file( | ||
"junit", | ||
reporter = createJunitReporterMock(file = output), | ||
output_file = output | ||
) | ||
}) | ||
|
||
test_that("reporters write to 'testthat.output_file', if specified", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this only needs one test since it's only one line of code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was in testing all of the reporters that I found that several of them needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that applies to the test case above, not this one? (Because the option is set in the base class initialiser) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, misread. You're right, will prune. |
||
output_option <- tempfile() | ||
withr::with_options(list(testthat.output_file = output_option), { | ||
test_report_to_file("check", error_regexp=NULL, output_file = output_option) | ||
test_report_to_file( | ||
"progress", | ||
ProgressReporter$new(show_praise = FALSE, min_time = Inf), | ||
output_file = output_option | ||
) | ||
test_report_to_file( | ||
"summary", | ||
SummaryReporter$new(show_praise = FALSE, omit_dots = FALSE), | ||
output_file = output_option | ||
) | ||
test_report_to_file( | ||
"summary-2", | ||
SummaryReporter$new(show_praise = FALSE, max_reports = 2), | ||
output_file = output_option | ||
) | ||
test_report_to_file( | ||
"summary-no-dots", | ||
SummaryReporter$new(show_praise = FALSE, omit_dots = TRUE), | ||
output_file = output_option | ||
) | ||
test_report_to_file("location", output_file = output_option) | ||
test_report_to_file("minimal", output_file = output_option) | ||
test_report_to_file("tap", output_file = output_option) | ||
test_report_to_file("teamcity", output_file = output_option) | ||
test_report_to_file("rstudio", output_file = output_option) | ||
test_report_to_file( | ||
"junit", | ||
reporter = createJunitReporterMock(), | ||
output_file = output_option | ||
) | ||
}) | ||
}) | ||
|
||
test_that("silent reporter accepts the 'file' argument but doesn't write anything", { | ||
output <- tempfile() | ||
expect_silent(test_reporter(SilentReporter$new(file=output))) | ||
expect_false(file.exists(output)) | ||
withr::with_options(list(testthat.output_file = output), { | ||
expect_silent(test_reporter(SilentReporter$new())) | ||
expect_false(file.exists(output)) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this
expect_...