From faa75498db747b2863e857fbeff8fd1552ba23b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 24 Oct 2017 09:52:11 +0200 Subject: [PATCH 1/7] scope = "spaces", strict = FALSE --- R/colour-text.R | 1 - R/compare.R | 3 +-- R/evaluate-promise.R | 1 - R/expect-named.R | 2 +- R/expect-output.R | 18 +++++++++--------- R/old-school.R | 1 - R/reporter-junit.R | 10 +++++----- R/reporter-list.R | 5 ++--- R/reporter-multi.R | 1 - R/stack.R | 2 +- R/test-compiled-code.R | 1 - R/test-directory.R | 2 +- R/test-files.R | 2 +- R/traceback.R | 1 - R/utils.R | 2 +- tests/testthat/test-compare-character.R | 4 ++-- tests/testthat/test-compare-time.R | 4 ++-- tests/testthat/test-debug-reporter.R | 2 +- tests/testthat/test-describe.R | 2 +- tests/testthat/test-expect-equality.R | 2 +- tests/testthat/test-expect-length.R | 4 ++-- tests/testthat/test-expect-named.R | 1 - tests/testthat/test-expect-output.R | 2 +- tests/testthat/test-mock.R | 2 +- tests/testthat/test-reporter-list.R | 11 +++++------ tests/testthat/test-reporter-multi.R | 1 - tests/testthat/test-reporter.R | 4 ++-- tests/testthat/test-source_dir.R | 10 +++++----- tests/testthat/test-teardown-1.R | 1 - tests/testthat/test-test-that.R | 14 +++++++------- tests/testthat/test-test_dir.R | 18 +++++++++--------- tests/testthat/test-watcher.R | 4 ++-- tests/testthat/test_dir/helper_hello.R | 2 +- tests/testthat/test_dir/test-empty.R | 7 +++---- tests/testthat/test_dir/test-errors.R | 22 +++++++++++----------- tests/testthat/test_dir/test-failures.R | 18 +++++++++--------- tests/testthat/test_dir/test-helper.R | 9 ++++----- 37 files changed, 91 insertions(+), 105 deletions(-) diff --git a/R/colour-text.R b/R/colour-text.R index c8a19c1c9..90ff63be4 100644 --- a/R/colour-text.R +++ b/R/colour-text.R @@ -15,4 +15,3 @@ colourise <- function(text, as = c("success", "skip", "warning", "failure", "err ) testthat_colours[[as]](text) } - diff --git a/R/compare.R b/R/compare.R index 13b9b3d77..868f30074 100644 --- a/R/compare.R +++ b/R/compare.R @@ -44,7 +44,7 @@ print.comparison <- function(x, ...) { #' @export #' @rdname compare -compare.default <- function(x, y, ..., max_diffs = 9){ +compare.default <- function(x, y, ..., max_diffs = 9) { same <- all.equal(x, y, ...) if (length(same) > max_diffs) { same <- c(same[1:max_diffs], "...") @@ -92,4 +92,3 @@ vector_equal <- function(x, y) { vector_equal_tol <- function(x, y, tolerance = .Machine$double.eps ^ 0.5) { (is.na(x) & is.na(y)) | (!is.na(x) & !is.na(y) & abs(x - y) < tolerance) } - diff --git a/R/evaluate-promise.R b/R/evaluate-promise.R index 7620f899f..b9d8d35c6 100644 --- a/R/evaluate-promise.R +++ b/R/evaluate-promise.R @@ -53,4 +53,3 @@ evaluate_promise <- function(code, print = FALSE) { messages = get_messages(messages$as_list()) ) } - diff --git a/R/expect-named.R b/R/expect-named.R index 97448eace..bcab26e46 100644 --- a/R/expect-named.R +++ b/R/expect-named.R @@ -58,7 +58,7 @@ normalise_names <- function(x, ignore.order = FALSE, ignore.case = FALSE) { if (is.null(x)) return() if (ignore.order) x <- sort(x) - if (ignore.case) x <- tolower(x) + if (ignore.case) x <- tolower(x) x } diff --git a/R/expect-output.R b/R/expect-output.R index 7165720e2..2ee683c00 100644 --- a/R/expect-output.R +++ b/R/expect-output.R @@ -129,11 +129,11 @@ expect_error <- function(object, #' @export #' @rdname output-expectations expect_condition <- function(object, - regexp = NULL, - class = NULL, - ..., - info = NULL, - label = NULL) { + regexp = NULL, + class = NULL, + ..., + info = NULL, + label = NULL) { act <- quasi_capture(enquo(object), capture_condition, label = label) msg <- compare_condition(act$cap, act$lab, regexp = regexp, class = class, ..., @@ -253,10 +253,10 @@ compare_condition <- function(cond, lab, regexp = NULL, class = NULL, ..., compare_messages <- function(messages, - lab, - regexp = NA, ..., - all = FALSE, - cond_type = "messages") { + lab, + regexp = NA, ..., + all = FALSE, + cond_type = "messages") { bullets <- paste0("* ", messages, collapse = "\n") # Expecting no messages diff --git a/R/old-school.R b/R/old-school.R index e0051ed53..3fe3c79b7 100644 --- a/R/old-school.R +++ b/R/old-school.R @@ -136,4 +136,3 @@ takes_less_than <- function(amount) { ) } } - diff --git a/R/reporter-junit.R b/R/reporter-junit.R index 16a7ea4a1..4afe20b20 100644 --- a/R/reporter-junit.R +++ b/R/reporter-junit.R @@ -60,7 +60,7 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, self$timer <- private$proctime() self$doc <- xml2::xml_new_document() - self$root <- xml2::xml_add_child(self$doc, 'testsuites') + self$root <- xml2::xml_add_child(self$doc, "testsuites") self$reset_suite() }, @@ -104,13 +104,13 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, # add an extra XML child node if not a success if (expectation_error(result)) { # "type" in Java is the exception class - error <- xml2::xml_add_child(testcase, 'error', type = 'error', message = first_line(result)) + error <- xml2::xml_add_child(testcase, "error", type = "error", message = first_line(result)) xml2::xml_text(error) <- format(result) self$errors <- self$errors + 1 } else if (expectation_failure(result)) { # "type" in Java is the type of assertion that failed - failure <- xml2::xml_add_child(testcase, 'failure', type = 'failure', message = first_line(result)) + failure <- xml2::xml_add_child(testcase, "failure", type = "failure", message = first_line(result)) xml2::xml_text(failure) <- format(result) self$failures <- self$failures + 1 @@ -128,10 +128,10 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, xml2::write_xml(self$doc, file, format = TRUE) write_lines(read_lines(file), self$out) } else { - stop('unsupported output type: ', toString(self$out)) + stop("unsupported output type: ", toString(self$out)) } } # end_reporter - ), #public + ), # public private = list ( proctime = function () { diff --git a/R/reporter-list.R b/R/reporter-list.R index aef1c8516..acd5183be 100644 --- a/R/reporter-list.R +++ b/R/reporter-list.R @@ -2,7 +2,7 @@ NULL -methods::setOldClass('proc_time') +methods::setOldClass("proc_time") #' List reporter: gather all test results along with elapsed time and #' file information. @@ -120,7 +120,7 @@ sumarize_one_test_results <- function(test) { nb_warning <- sum(vapply(test_results, expectation_warning, logical(1))) } - context <- if (length(test$context) > 0) test$context else '' + context <- if (length(test$context) > 0) test$context else "" res <- data.frame(file = test$file, context = context, test = test$test, nb = nb_tests, failed = nb_failed, skipped = as.logical(nb_skipped), @@ -136,4 +136,3 @@ sumarize_one_test_results <- function(test) { print.testthat_results <- function(x, ...) { print(as.data.frame(x)) } - diff --git a/R/reporter-multi.R b/R/reporter-multi.R index 5646b1aa8..989bb3b1c 100644 --- a/R/reporter-multi.R +++ b/R/reporter-multi.R @@ -44,4 +44,3 @@ MultiReporter <- R6::R6Class("MultiReporter", inherit = Reporter, o_apply <- function(objects, method, ...) { lapply(objects, function(x) x[[method]](...)) } - diff --git a/R/stack.R b/R/stack.R index b0f706e78..04b4de761 100644 --- a/R/stack.R +++ b/R/stack.R @@ -5,7 +5,7 @@ # A Stack object backed by a list. The backing list will grow or shrink as # the stack changes in size. Stack <- R6Class( - 'Stack', + "Stack", class = FALSE, public = list( diff --git a/R/test-compiled-code.R b/R/test-compiled-code.R index e2ec16e33..de0aa7176 100644 --- a/R/test-compiled-code.R +++ b/R/test-compiled-code.R @@ -253,4 +253,3 @@ get_routine <- function(package, routine) { (function() { .Call(run_testthat_tests) }) - diff --git a/R/test-directory.R b/R/test-directory.R index 6a65e37d1..3cc515e9c 100644 --- a/R/test-directory.R +++ b/R/test-directory.R @@ -161,7 +161,7 @@ test_check <- function(package, }) test_path <- "testthat" - if (!utils::file_test('-d', test_path)) { + if (!utils::file_test("-d", test_path)) { stop("No tests found for ", package, call. = FALSE) } diff --git a/R/test-files.R b/R/test-files.R index 817c3c542..965a965c1 100644 --- a/R/test-files.R +++ b/R/test-files.R @@ -19,7 +19,7 @@ test_files <- function(paths, wrap = TRUE ) { if (length(paths) == 0) { - stop('No matching test file in dir') + stop("No matching test file in dir") } current_reporter <- find_reporter(reporter) diff --git a/R/traceback.R b/R/traceback.R index 4ec876f2b..5685801c9 100644 --- a/R/traceback.R +++ b/R/traceback.R @@ -25,4 +25,3 @@ create_traceback <- function(callstack) { first_last(calls) } - diff --git a/R/utils.R b/R/utils.R index f7be8f2e1..ace940e2b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -63,7 +63,7 @@ env_name <- function(x) { find_first_srcref <- function(calls) { for (call in calls) { - srcref <- attr(call, 'srcref') + srcref <- attr(call, "srcref") if (!is.null(srcref)) return(srcref) } diff --git a/tests/testthat/test-compare-character.R b/tests/testthat/test-compare-character.R index 695023bed..4c3390ac3 100644 --- a/tests/testthat/test-compare-character.R +++ b/tests/testthat/test-compare-character.R @@ -49,7 +49,7 @@ test_that("equal if both missing or both the same (multiple values)", { # Output ------------------------------------------------------------------ test_that("computes correct number of mismatches", { - x <- mismatch_character(c("a","b","c"), c("c", "d", "e")) + x <- mismatch_character(c("a", "b", "c"), c("c", "d", "e")) expect_equal(x$n, 3) }) @@ -73,7 +73,7 @@ test_that("not all lines are shown", { }) test_that("vectors longer than `max_diffs` (#513)", { - comp <- compare(letters[1:2], LETTERS[1:2], max_diffs=1) + comp <- compare(letters[1:2], LETTERS[1:2], max_diffs = 1) expect_is(comp, "comparison") expect_false(comp$equal) expect_equal(comp$message, "2/2 mismatches\nx[1]: \"a\"\ny[1]: \"A\"") diff --git a/tests/testthat/test-compare-time.R b/tests/testthat/test-compare-time.R index 6e05b3b28..1fda89ee9 100644 --- a/tests/testthat/test-compare-time.R +++ b/tests/testthat/test-compare-time.R @@ -21,8 +21,8 @@ test_that("base lengths must be identical", { }) test_that("tzones must be identical", { - t1 <- ISOdatetime(2016,2,29,12,13,14,'EST') - t2 <- ISOdatetime(2016,2,29,12,13,14,'US/Eastern') + t1 <- ISOdatetime(2016, 2, 29, 12, 13, 14, "EST") + t2 <- ISOdatetime(2016, 2, 29, 12, 13, 14, "US/Eastern") expect_match(compare(t1, t2)$message, '"tzone": 1 string mismatch') }) diff --git a/tests/testthat/test-debug-reporter.R b/tests/testthat/test-debug-reporter.R index 275f8a69d..397984649 100644 --- a/tests/testthat/test-debug-reporter.R +++ b/tests/testthat/test-debug-reporter.R @@ -11,7 +11,7 @@ get_frame_from_debug_reporter <- function(choice, fun, envir = parent.frame()) { with_mock( show_menu = function(choices, title = NULL) { - #if (choice > 0) print(choices) + # if (choice > 0) print(choices) my_choice <- choice choice <<- 0L my_choice diff --git a/tests/testthat/test-describe.R b/tests/testthat/test-describe.R index e02eb18c5..30251f165 100644 --- a/tests/testthat/test-describe.R +++ b/tests/testthat/test-describe.R @@ -24,7 +24,7 @@ describe("describe", { it("has to have a description for the block", { expect_that(describe({ }), throws_error()) - expect_that(describe("",{ + expect_that(describe("", { }), throws_error()) expect_that(describe("test", { it() diff --git a/tests/testthat/test-expect-equality.R b/tests/testthat/test-expect-equality.R index 2a6847ecd..e3e7c5466 100644 --- a/tests/testthat/test-expect-equality.R +++ b/tests/testthat/test-expect-equality.R @@ -7,7 +7,7 @@ test_that("basically principles of equality hold", { test_that("default labels use unquoting", { x <- 2 - expect_failure(expect_equal(1, !!x), "1 not equal to 2") + expect_failure(expect_equal(1, !! x), "1 not equal to 2") }) test_that("expect_equivalent ignores attributes for integers", { diff --git a/tests/testthat/test-expect-length.R b/tests/testthat/test-expect-length.R index 24fdc81ab..2e104da20 100644 --- a/tests/testthat/test-expect-length.R +++ b/tests/testthat/test-expect-length.R @@ -8,9 +8,9 @@ test_that("length computed correctly", { }) test_that("uses S4 length method", { - A <- setClass("ExpectLengthA", slots=c(x="numeric", y="numeric")) + A <- setClass("ExpectLengthA", slots = c(x = "numeric", y = "numeric")) setMethod("length", "ExpectLengthA", function (x) 5L) - expect_success(expect_length(A(x=1:9, y=3), 5)) + expect_success(expect_length(A(x = 1:9, y = 3), 5)) }) test_that("returns input", { diff --git a/tests/testthat/test-expect-named.R b/tests/testthat/test-expect-named.R index ef7eb3431..0b4a31e04 100644 --- a/tests/testthat/test-expect-named.R +++ b/tests/testthat/test-expect-named.R @@ -17,4 +17,3 @@ test_that("expected_named optionally ignores case", { test_that("expected_named optionally ignores order", { expect_success(expect_named(c(a = 1, b = 2), c("b", "a"), ignore.order = TRUE)) }) - diff --git a/tests/testthat/test-expect-output.R b/tests/testthat/test-expect-output.R index feca65255..63466e854 100644 --- a/tests/testthat/test-expect-output.R +++ b/tests/testthat/test-expect-output.R @@ -16,7 +16,7 @@ test_that("expect = NULL checks for some output", { test_that("expect = string checks for match", { expect_success(expect_output(g(), "!")) expect_failure(expect_output(g(), "x"), 'does not match "x"') - expect_failure(expect_output("a", "x"), 'produced no output') + expect_failure(expect_output("a", "x"), "produced no output") }) test_that("multiline outputs captures and matches", { diff --git a/tests/testthat/test-mock.R b/tests/testthat/test-mock.R index e99f60f78..92ceb41a7 100644 --- a/tests/testthat/test-mock.R +++ b/tests/testthat/test-mock.R @@ -80,7 +80,7 @@ test_that("can access variables defined in function", { test_that("can mock if package is not loaded", { if ("package:devtools" %in% search()) - skip('devtools is loaded') + skip("devtools is loaded") skip_if_not_installed("devtools") with_mock(`devtools::add_path` = identity, expect_identical(devtools::add_path, identity)) }) diff --git a/tests/testthat/test-reporter-list.R b/tests/testthat/test-reporter-list.R index 2d3b922ed..b92a9b7a4 100644 --- a/tests/testthat/test-reporter-list.R +++ b/tests/testthat/test-reporter-list.R @@ -2,28 +2,27 @@ context("ListReporter") test_that("ListReporter with test_file", { report <- ListReporter$new() - report$start_file('context.R') + report$start_file("context.R") test_file(test_path("context.R"), report) res <- report$results$as_list() - expect_is(res, 'list') + expect_is(res, "list") expect_equal(length(res), 4) # Check context and file are set - contexts <- sapply(res, '[[', 'context') + contexts <- sapply(res, "[[", "context") expect_equal(contexts, rep(c("First context.", "Second context."), each = 2)) - files <- sapply(res, '[[', 'file') + files <- sapply(res, "[[", "file") expect_equal(files, rep(c("context.R"), 4)) # Check results are as expected last_results <- res[[4]]$results - expect_is(last_results, 'list') + expect_is(last_results, "list") expect_equal(length(last_results), 1) fl <- last_results[[1]] expect_equal(expectation_type(fl), "failure") }) - diff --git a/tests/testthat/test-reporter-multi.R b/tests/testthat/test-reporter-multi.R index 1e73d0dee..b71ee03b6 100644 --- a/tests/testthat/test-reporter-multi.R +++ b/tests/testthat/test-reporter-multi.R @@ -11,4 +11,3 @@ test_that("MultiReporter", { expect_equal(dfs[[2]][1:7], dfs[[1]][1:7]) expect_equal(dfs[[3]][1:7], dfs[[1]][1:7]) }) - diff --git a/tests/testthat/test-reporter.R b/tests/testthat/test-reporter.R index de6e8c640..f59c39970 100644 --- a/tests/testthat/test-reporter.R +++ b/tests/testthat/test-reporter.R @@ -77,7 +77,7 @@ test_that("reporters produce consistent output", { tap_file <- tempfile() save_report("summary", reporter = MultiReporter$new(list( SummaryReporter$new(show_praise = FALSE, omit_dots = FALSE), - TapReporter$new(file=tap_file)) + TapReporter$new(file = tap_file)) )) expect_identical(read_lines(tap_file), read_lines(test_path("reporters", "tap.txt"))) @@ -138,6 +138,6 @@ test_that("reporters write to 'testthat.output_file', if specified", { test_that("silent reporter accepts the 'file' argument but doesn't write anything", { output <- tempfile() - expect_silent(test_reporter(SilentReporter$new(file=output))) + expect_silent(test_reporter(SilentReporter$new(file = output))) expect_false(file.exists(output)) }) diff --git a/tests/testthat/test-source_dir.R b/tests/testthat/test-source_dir.R index f0449a36f..44dcc1976 100644 --- a/tests/testthat/test-source_dir.R +++ b/tests/testthat/test-source_dir.R @@ -1,15 +1,15 @@ context("source_dir") -test_that('source_dir()', { - res <- source_dir('test_dir', pattern = 'hello', chdir = TRUE, wrap = FALSE) +test_that("source_dir()", { + res <- source_dir("test_dir", pattern = "hello", chdir = TRUE, wrap = FALSE) expect_equal(res[[1]](), "Hello World") - res <- source_dir(normalizePath('test_dir'), pattern = 'hello', chdir = TRUE, wrap = FALSE) + res <- source_dir(normalizePath("test_dir"), pattern = "hello", chdir = TRUE, wrap = FALSE) expect_equal(res[[1]](), "Hello World") - res <- source_dir('test_dir', pattern = 'hello', chdir = FALSE, wrap = FALSE) + res <- source_dir("test_dir", pattern = "hello", chdir = FALSE, wrap = FALSE) expect_equal(res[[1]](), "Hello World") - res <- source_dir(normalizePath('test_dir'), pattern = 'hello', chdir = FALSE, wrap = FALSE) + res <- source_dir(normalizePath("test_dir"), pattern = "hello", chdir = FALSE, wrap = FALSE) expect_equal(res[[1]](), "Hello World") }) diff --git a/tests/testthat/test-teardown-1.R b/tests/testthat/test-teardown-1.R index 4963e56cc..d4e8792ad 100644 --- a/tests/testthat/test-teardown-1.R +++ b/tests/testthat/test-teardown-1.R @@ -37,4 +37,3 @@ test_that("file is created", { teardown({ file.remove("teardown.txt") }) - diff --git a/tests/testthat/test-test-that.R b/tests/testthat/test-test-that.R index c7161da18..dd2b611fe 100644 --- a/tests/testthat/test-test-that.R +++ b/tests/testthat/test-test-that.R @@ -89,8 +89,8 @@ expectation_lines <- function(code) { test_that("line numbers captured in simple case", { lines <- expectation_lines({ - context('testing testFile') # line 1 - test_that('simple', { # line 2 + context("testing testFile") # line 1 + test_that("simple", { # line 2 expect_true(FALSE) # line 3 }) # line 4 }) @@ -99,7 +99,7 @@ test_that("line numbers captured in simple case", { test_that("line numbers captured inside another function", { lines <- expectation_lines({ - test_that('simple', { # line 1 + test_that("simple", { # line 1 suppressMessages(expect_true(FALSE)) # line 2 }) }) @@ -108,8 +108,8 @@ test_that("line numbers captured inside another function", { test_that("line numbers captured inside a loop", { lines <- expectation_lines({ - test_that('simple', { # line 1 - for(i in 1:4) expect_true(TRUE) # line 2 + test_that("simple", { # line 1 + for (i in 1:4) expect_true(TRUE) # line 2 }) }) expect_equal(lines, rep(2, 4)) @@ -117,7 +117,7 @@ test_that("line numbers captured inside a loop", { test_that("line numbers captured for skip()s", { lines <- expectation_lines({ - test_that('simple', { # line 1 + test_that("simple", { # line 1 skip("Not this time") # line 2 }) # line 3 }) @@ -126,7 +126,7 @@ test_that("line numbers captured for skip()s", { test_that("line numbers captured for stop()s", { lines <- expectation_lines({ - test_that('simple', { # line 1 + test_that("simple", { # line 1 skip("Not this time") # line 2 }) # line 3 }) diff --git a/tests/testthat/test-test_dir.R b/tests/testthat/test-test_dir.R index 1f43a45ac..a0c0e7b73 100644 --- a/tests/testthat/test-test_dir.R +++ b/tests/testthat/test-test_dir.R @@ -8,8 +8,8 @@ test_that("TESTHAT env var set to true", { expect_true(is_testing()) }) -test_that('test_dir()', { - res <- test_dir(test_path('test_dir'), reporter = 'silent') +test_that("test_dir()", { + res <- test_dir(test_path("test_dir"), reporter = "silent") df <- as.data.frame(res) df$user <- df$system <- df$real <- NULL @@ -17,19 +17,19 @@ test_that('test_dir()', { expect_known_value(df, "test_dir.rds") }) -test_that('test_dir() filter', { - res <- test_dir('test_dir', reporter = 'silent', filter = 'basic|empty') +test_that("test_dir() filter", { + res <- test_dir("test_dir", reporter = "silent", filter = "basic|empty") df <- as.data.frame(res) expect_identical(unique(df$context), c("Basic", "empty")) }) -test_that('test_dir() helpers', { - res <- test_dir('test_dir', reporter = 'silent', filter = 'helper') +test_that("test_dir() helpers", { + res <- test_dir("test_dir", reporter = "silent", filter = "helper") df <- as.data.frame(res) expect_true(all(!df$error & df$failed == 0)) }) -test_that('filter_test_scripts() with tricky names', { +test_that("filter_test_scripts() with tricky names", { files <- c( "test-basic.R", "test-blah.really.Rtrick.R", "test-hello.rtest.R" ) @@ -45,7 +45,7 @@ test_that('filter_test_scripts() with tricky names', { # errors ------------------------------------------------------------------ -test_that("can control if failures generate errors",{ +test_that("can control if failures generate errors", { test_error <- function(...) { test_dir(test_path("test-error"), reporter = "silent", ...) } @@ -55,7 +55,7 @@ test_that("can control if failures generate errors",{ }) -test_that("can control if warnings errors",{ +test_that("can control if warnings errors", { test_warning <- function(...) { test_dir(test_path("test-warning"), reporter = "silent", ...) } diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index 14b171a86..68f4e9e88 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -28,7 +28,7 @@ test_that("compare state works correctly", { expect_that(basename(diff$added), equals("test-2.txt")) diff <- compare_state(c(file1 = "62da2", file2 = "e14a6", file3 = "6e6dd"), - c(file1 = "62da2", file2 = "e14a6", file21= "532fa", file3 = "3f4sa")) + c(file1 = "62da2", file2 = "e14a6", file21 = "532fa", file3 = "3f4sa")) expect_that(diff$n, equals(2)) expect_that(basename(diff$added), equals("file21")) expect_that(basename(diff$modified), equals("file3")) @@ -53,7 +53,7 @@ test_that("watcher works correctly", { dir.create(test_path) delayed.bash.cmd <- function(command) { - system(paste0("bash -c 'sleep 1;", command, "'"), wait=FALSE) + system(paste0("bash -c 'sleep 1;", command, "'"), wait = FALSE) } add.code.file <- function(file.name) { diff --git a/tests/testthat/test_dir/helper_hello.R b/tests/testthat/test_dir/helper_hello.R index 496e7410d..dd96afc4c 100644 --- a/tests/testthat/test_dir/helper_hello.R +++ b/tests/testthat/test_dir/helper_hello.R @@ -1 +1 @@ -hello <- function() 'Hello World' +hello <- function() "Hello World" diff --git a/tests/testthat/test_dir/test-empty.R b/tests/testthat/test_dir/test-empty.R index 241018242..3bc98415e 100644 --- a/tests/testthat/test_dir/test-empty.R +++ b/tests/testthat/test_dir/test-empty.R @@ -1,6 +1,5 @@ -context('empty') +context("empty") -test_that('empty test', NULL) - -test_that('empty test with error', stop('Argh')) +test_that("empty test", NULL) +test_that("empty test with error", stop("Argh")) diff --git a/tests/testthat/test_dir/test-errors.R b/tests/testthat/test_dir/test-errors.R index 23a9f5433..5b4025d7b 100644 --- a/tests/testthat/test_dir/test-errors.R +++ b/tests/testthat/test_dir/test-errors.R @@ -1,24 +1,24 @@ -context('error') +context("error") -test_that('simple', { - stop('argh') +test_that("simple", { + stop("argh") }) -test_that('after one success', { +test_that("after one success", { expect_true(TRUE) - stop('argh') + stop("argh") expect_true(TRUE) }) -test_that('after one failure', { +test_that("after one failure", { expect_true(FALSE) - stop('argh') + stop("argh") }) -test_that('in the test', { - expect_true(stop('Argh')) +test_that("in the test", { + expect_true(stop("Argh")) }) -test_that('in expect_error', { - expect_error(stop('Argh')) +test_that("in expect_error", { + expect_error(stop("Argh")) }) diff --git a/tests/testthat/test_dir/test-failures.R b/tests/testthat/test_dir/test-failures.R index a37c1da8c..f96e50626 100644 --- a/tests/testthat/test_dir/test-failures.R +++ b/tests/testthat/test_dir/test-failures.R @@ -1,15 +1,15 @@ -context('failures') +context("failures") -test_that('just one failure', { - expect_true(FALSE) +test_that("just one failure", { + expect_true(FALSE) }) -test_that('one failure on two', { - expect_false(FALSE) - expect_true(FALSE) +test_that("one failure on two", { + expect_false(FALSE) + expect_true(FALSE) }) -test_that('no failure', { - expect_false(FALSE) - expect_true(TRUE) +test_that("no failure", { + expect_false(FALSE) + expect_true(TRUE) }) diff --git a/tests/testthat/test_dir/test-helper.R b/tests/testthat/test_dir/test-helper.R index 5819f21fa..14da77fe5 100644 --- a/tests/testthat/test_dir/test-helper.R +++ b/tests/testthat/test_dir/test-helper.R @@ -1,7 +1,6 @@ -# test that the companion helper script is sourced by test_dir -context('helper') +# test that the companion helper script is sourced by test_dir +context("helper") -test_that('helper test', { - expect_equal(hello(), 'Hello World') +test_that("helper test", { + expect_equal(hello(), "Hello World") }) - From b04ab6bc7b0c96eb6a78f7066aa2e30381bff05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 24 Oct 2017 10:13:35 +0200 Subject: [PATCH 2/7] scope = "indention", strict = FALSE --- R/expect-output.R | 2 +- R/expectation.R | 2 +- R/mock.R | 4 ++-- R/recover.R | 2 +- R/reporter-debug.R | 2 +- R/reporter-tap.R | 2 +- R/test-directory.R | 9 +++------ R/test-files.R | 5 ++--- tests/testthat/test-bare.R | 4 ++-- tests/testthat/test-cpp.R | 2 +- tests/testthat/test-reporter.R | 2 +- tests/testthat/test-watcher.R | 4 ++-- 12 files changed, 18 insertions(+), 22 deletions(-) diff --git a/R/expect-output.R b/R/expect-output.R index 2ee683c00..effe90937 100644 --- a/R/expect-output.R +++ b/R/expect-output.R @@ -204,7 +204,7 @@ compare_condition <- function(cond, lab, regexp = NULL, class = NULL, ..., cond_type, cond$message, paste(class(cond), collapse = "/") - )) + )) } else { return() } diff --git a/R/expectation.R b/R/expectation.R index 6305380d5..40645efaa 100644 --- a/R/expectation.R +++ b/R/expectation.R @@ -161,7 +161,7 @@ as.expectation <- function(x, ...) UseMethod("as.expectation", x) #' @export as.expectation.default <- function(x, ..., srcref = NULL) { stop("Don't know how to convert '", paste(class(x), collapse = "', '"), - "' to expectation.", call. = FALSE) + "' to expectation.", call. = FALSE) } #' @export diff --git a/R/mock.R b/R/mock.R index 11b6033cb..8ae8c5ce6 100644 --- a/R/mock.R +++ b/R/mock.R @@ -43,7 +43,7 @@ with_mock <- function(..., .env = topenv()) { if (all(mock_qual_names == "")) { warning("Not mocking anything. Please use named parameters to specify the functions you want to mock.", - call. = FALSE) + call. = FALSE) code_pos <- rep(TRUE, length(new_values)) } else { code_pos <- (mock_qual_names == "") @@ -95,7 +95,7 @@ extract_mocks <- function(new_values, .env, eval_env = parent.frame()) { if (!exists(name, envir = env, mode = "function")) stop("Function ", name, " not found in environment ", - environmentName(env), ".", call. = FALSE) + environmentName(env), ".", call. = FALSE) mock(name = name, env = env, new = eval(new_values[[qual_name]], eval_env, eval_env)) } ) diff --git a/R/recover.R b/R/recover.R index 4e35796d0..782a6bffa 100644 --- a/R/recover.R +++ b/R/recover.R @@ -42,5 +42,5 @@ show_menu <- function(choices, title = NULL) { browse_frame <- function(frame, skip) { eval(substitute(browser(skipCalls = skip), list(skip = skip)), - envir = frame) + envir = frame) } diff --git a/R/reporter-debug.R b/R/reporter-debug.R index 378a24d0b..9cfe64ec1 100644 --- a/R/reporter-debug.R +++ b/R/reporter-debug.R @@ -18,7 +18,7 @@ DebugReporter <- R6::R6Class("DebugReporter", inherit = Reporter, } recover2(start_frame = result$start_frame, - end_frame = result$end_frame) + end_frame = result$end_frame) } } ) diff --git a/R/reporter-tap.R b/R/reporter-tap.R index 24379df53..59186e72c 100644 --- a/R/reporter-tap.R +++ b/R/reporter-tap.R @@ -44,7 +44,7 @@ TapReporter <- R6::R6Class("TapReporter", inherit = Reporter, self$cat_line(msg) } else { self$cat_line("ok ", i, " # ", toupper(expectation_type(result)), " ", - format(result)) + format(result)) } } } diff --git a/R/test-directory.R b/R/test-directory.R index 3cc515e9c..d00ec3c2e 100644 --- a/R/test-directory.R +++ b/R/test-directory.R @@ -63,8 +63,7 @@ test_dir <- function(path, load_helpers = TRUE, stop_on_failure = FALSE, stop_on_warning = FALSE, - wrap = TRUE - ) { + wrap = TRUE) { if (!missing(encoding) && !identical(encoding, "UTF-8")) { warning("`encoding` is deprecated; all files now assumed to be UTF-8", call. = FALSE) } @@ -97,8 +96,7 @@ test_package <- function(package, reporter = check_repoter(), ..., stop_on_failure = TRUE, - stop_on_warning = FALSE - ) { + stop_on_warning = FALSE) { library(testthat) # Ensure that test package returns silently if called recursively - this @@ -148,8 +146,7 @@ test_check <- function(package, ..., stop_on_failure = TRUE, stop_on_warning = FALSE, - wrap = TRUE - ) { + wrap = TRUE) { library(testthat) require(package, character.only = TRUE) diff --git a/R/test-files.R b/R/test-files.R index 965a965c1..ff7933da1 100644 --- a/R/test-files.R +++ b/R/test-files.R @@ -16,8 +16,7 @@ test_files <- function(paths, env = test_env(), stop_on_failure = FALSE, stop_on_warning = FALSE, - wrap = TRUE - ) { + wrap = TRUE) { if (length(paths) == 0) { stop("No matching test file in dir") } @@ -129,7 +128,7 @@ test_file <- function(path, reporter = default_reporter(), env = test_env(), lister$start_file(basename(path)) source_file(path, new.env(parent = env), - chdir = TRUE, wrap = wrap) + chdir = TRUE, wrap = wrap) end_context() } diff --git a/tests/testthat/test-bare.R b/tests/testthat/test-bare.R index 04aab037f..8cecc0154 100644 --- a/tests/testthat/test-bare.R +++ b/tests/testthat/test-bare.R @@ -6,9 +6,9 @@ expect_error(stop("!")) stopifnot( tryCatch(expect_true(TRUE), - expectation_failure = function(e) FALSE) + expectation_failure = function(e) FALSE) ) stopifnot( tryCatch(expect_true(FALSE), - expectation_failure = function(e) TRUE) + expectation_failure = function(e) TRUE) ) diff --git a/tests/testthat/test-cpp.R b/tests/testthat/test-cpp.R index 5d4bcf1cd..60e50aadf 100644 --- a/tests/testthat/test-cpp.R +++ b/tests/testthat/test-cpp.R @@ -1,4 +1,4 @@ context("C++") test_that("Catch unit tests pass", { - expect_cpp_tests_pass("testthat") + expect_cpp_tests_pass("testthat") }) diff --git a/tests/testthat/test-reporter.R b/tests/testthat/test-reporter.R index f59c39970..ba3063bf3 100644 --- a/tests/testthat/test-reporter.R +++ b/tests/testthat/test-reporter.R @@ -54,7 +54,7 @@ test_that("reporters produce consistent output", { with_mock( show_menu = function(choices, title = NULL) { cat(paste0(format(seq_along(choices)), ": ", choices, sep = "\n"), "\n", - sep = "") + sep = "") 0L }, sink_number = function() 0L, diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index 68f4e9e88..b476d3d69 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -28,11 +28,11 @@ test_that("compare state works correctly", { expect_that(basename(diff$added), equals("test-2.txt")) diff <- compare_state(c(file1 = "62da2", file2 = "e14a6", file3 = "6e6dd"), - c(file1 = "62da2", file2 = "e14a6", file21 = "532fa", file3 = "3f4sa")) + c(file1 = "62da2", file2 = "e14a6", file21 = "532fa", file3 = "3f4sa")) expect_that(diff$n, equals(2)) expect_that(basename(diff$added), equals("file21")) expect_that(basename(diff$modified), equals("file3")) - }) +}) test_that("watcher works correctly", { skip_on_cran() From 1851f0c108cb17189c4a39b1103d0282496ea924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 24 Oct 2017 10:18:05 +0200 Subject: [PATCH 3/7] manual change --- R/describe.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/describe.R b/R/describe.R index 38e297794..df47252cd 100644 --- a/R/describe.R +++ b/R/describe.R @@ -57,8 +57,8 @@ describe <- function(description, code) { is_invalid_description <- function (description) { - (!is.character(description) || length(description) != 1 - || nchar(description) == 0) + !is.character(description) || length(description) != 1 || + nchar(description) == 0 } if (is_invalid_description(description)) { From 3053abaa189c756299e67d9a954e411fafd7621c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 24 Oct 2017 10:37:44 +0200 Subject: [PATCH 4/7] scope = "line_breaks", strict = FALSE --- R/recover.R | 3 +-- tests/testthat/reporters/tests.R | 20 +++++++++++++++----- tests/testthat/test-evaluate-promise.R | 8 ++++++-- tests/testthat/test-expect-message.R | 4 +++- tests/testthat/test-label.R | 4 +++- tests/testthat/test-mock.R | 4 +++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/R/recover.R b/R/recover.R index 782a6bffa..b7e034f82 100644 --- a/R/recover.R +++ b/R/recover.R @@ -15,8 +15,7 @@ # # A copy of the GNU General Public License is available at # https://www.R-project.org/Licenses/ -recover2 <- function(start_frame = 1L, end_frame = sys.nframe()) -{ +recover2 <- function(start_frame = 1L, end_frame = sys.nframe()) { calls <- sys.calls() if (.isMethodsDispatchOn()) { diff --git a/tests/testthat/reporters/tests.R b/tests/testthat/reporters/tests.R index 38877b34d..18282748c 100644 --- a/tests/testthat/reporters/tests.R +++ b/tests/testthat/reporters/tests.R @@ -29,9 +29,15 @@ test_that("Error:1", { }) test_that("Error:3", { - f <- function() {g()} - g <- function() {h()} - h <- function() {stop("!")} + f <- function() { + g() + } + g <- function() { + h() + } + h <- function() { + stop("!") + } f() }) @@ -52,7 +58,9 @@ test_that("Skip:1", { }) test_that("Skip:2", { - f <- function() {skip("skip")} + f <- function() { + skip("skip") + } f() }) @@ -65,7 +73,9 @@ test_that("Warning:1", { warning("abc") }) test_that("Warning:2", { - f <- function() {warning("ghi")} + f <- function() { + warning("ghi") + } warning("def") f() }) diff --git a/tests/testthat/test-evaluate-promise.R b/tests/testthat/test-evaluate-promise.R index 7fe3d916e..3590f0adf 100644 --- a/tests/testthat/test-evaluate-promise.R +++ b/tests/testthat/test-evaluate-promise.R @@ -14,12 +14,16 @@ test_that("captures warnings, messages and output", { }) test_that("capture_warnings captures warnings", { - out <- capture_warnings({warning("a"); warning("b")}) + out <- capture_warnings({ + warning("a"); warning("b") + }) expect_equal(out, c("a", "b")) }) test_that("capture_messages captures messages", { - out <- capture_messages({message("a"); message("b")}) + out <- capture_messages({ + message("a"); message("b") + }) expect_equal(out, c("a\n", "b\n")) # message adds LF by default }) diff --git a/tests/testthat/test-expect-message.R b/tests/testthat/test-expect-message.R index 3b3aac216..1e10df156 100644 --- a/tests/testthat/test-expect-message.R +++ b/tests/testthat/test-expect-message.R @@ -1,7 +1,9 @@ context("expect_message") test_that("inputs evaluated in correct scope", { - expect_message({message("a"); x <- 10}) + expect_message({ + message("a"); x <- 10 + }) expect_identical(x, 10) }) diff --git a/tests/testthat/test-label.R b/tests/testthat/test-label.R index dcb14b89c..47f1a551b 100644 --- a/tests/testthat/test-label.R +++ b/tests/testthat/test-label.R @@ -1,7 +1,9 @@ context("label") test_that("labelling compound {} expression gives single string", { - out <- expr_label(quote({1 + 2})) + out <- expr_label(quote({ + 1 + 2 + })) expect_length(out, 1) expect_type(out, "character") diff --git a/tests/testthat/test-mock.R b/tests/testthat/test-mock.R index 92ceb41a7..b0364ee0a 100644 --- a/tests/testthat/test-mock.R +++ b/tests/testthat/test-mock.R @@ -115,6 +115,8 @@ test_that("mocks can access local variables", { with_mock( expect_equal(2 * 3, 4), - compare = function(x, y, ...) {value} + compare = function(x, y, ...) { + value + } ) }) From 25676090061c684a230ddffc0b8f00e94ea797c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 24 Oct 2017 10:44:31 +0200 Subject: [PATCH 5/7] scope = "tokens", strict = FALSE --- tests/testthat/test-evaluate-promise.R | 6 ++++-- tests/testthat/test-expect-message.R | 3 ++- tests/testthat/test-watcher.R | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-evaluate-promise.R b/tests/testthat/test-evaluate-promise.R index 3590f0adf..17c6f970a 100644 --- a/tests/testthat/test-evaluate-promise.R +++ b/tests/testthat/test-evaluate-promise.R @@ -15,14 +15,16 @@ test_that("captures warnings, messages and output", { test_that("capture_warnings captures warnings", { out <- capture_warnings({ - warning("a"); warning("b") + warning("a") + warning("b") }) expect_equal(out, c("a", "b")) }) test_that("capture_messages captures messages", { out <- capture_messages({ - message("a"); message("b") + message("a") + message("b") }) expect_equal(out, c("a\n", "b\n")) # message adds LF by default }) diff --git a/tests/testthat/test-expect-message.R b/tests/testthat/test-expect-message.R index 1e10df156..575a0bfc1 100644 --- a/tests/testthat/test-expect-message.R +++ b/tests/testthat/test-expect-message.R @@ -2,7 +2,8 @@ context("expect_message") test_that("inputs evaluated in correct scope", { expect_message({ - message("a"); x <- 10 + message("a") + x <- 10 }) expect_identical(x, 10) }) diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index b476d3d69..4a53649fa 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -46,8 +46,8 @@ test_that("watcher works correctly", { loc <- tempfile("watcher", tmpdir = "/tmp") dir.create(loc) - code_path = file.path(loc, "R") - test_path = file.path(loc, "tests") + code_path <- file.path(loc, "R") + test_path <- file.path(loc, "tests") dir.create(code_path) dir.create(test_path) From 0f61d06bf0e3bd382831ffbe6b2bf8f13cff0bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 24 Oct 2017 13:34:38 +0200 Subject: [PATCH 6/7] scope = "tokens", strict = TRUE --- R/auto-test.R | 8 ++-- R/compare-character.R | 2 - R/compare-numeric.R | 7 ++-- R/compare.R | 3 +- R/describe.R | 2 +- R/evaluate-promise.R | 4 +- R/expect-comparison.R | 4 +- R/expect-equality.R | 5 --- R/expect-known.R | 3 -- R/expect-named.R | 4 +- R/expect-output.R | 18 ++++----- R/expect-self-test.R | 3 +- R/expectation.R | 10 +++-- R/expectations-matches.R | 7 ++-- R/make-expectation.R | 12 ++++-- R/mock.R | 12 ++++-- R/old-school.R | 12 ++++-- R/recover.R | 10 +++-- R/reporter-check.R | 6 ++- R/reporter-debug.R | 9 +++-- R/reporter-fail.R | 3 +- R/reporter-junit.R | 51 +++++++++++++------------- R/reporter-list.R | 35 +++++++++++------- R/reporter-location.R | 3 +- R/reporter-minimal.R | 3 +- R/reporter-multi.R | 3 +- R/reporter-progress.R | 8 ++-- R/reporter-rstudio.R | 6 ++- R/reporter-silent.R | 3 +- R/reporter-stop.R | 3 +- R/reporter-summary.R | 6 ++- R/reporter-tap.R | 12 ++++-- R/reporter-teamcity.R | 6 ++- R/reporter.R | 4 +- R/skip.R | 12 +++--- R/stack.R | 7 ++-- R/test-compiled-code.R | 28 ++++++++------ R/test-directory.R | 6 ++- R/test-files.R | 6 ++- R/test-path.R | 9 +++-- R/test-that.R | 20 +++++----- R/traceback.R | 12 ++++-- R/try-again.R | 3 +- R/utils.R | 3 +- R/watcher.R | 1 - tests/testthat/helper-junitmock.R | 15 ++++---- tests/testthat/test-bare.R | 12 ++++-- tests/testthat/test-context.R | 3 +- tests/testthat/test-examples.R | 4 +- tests/testthat/test-expect-length.R | 2 +- tests/testthat/test-expect-self-test.R | 2 +- tests/testthat/test-mock.R | 3 +- tests/testthat/test-old-school.R | 1 - tests/testthat/test-reporter-list.R | 1 - tests/testthat/test-reporter.R | 29 +++++++++------ tests/testthat/test-test-that.R | 28 +++++++------- tests/testthat/test-test_dir.R | 4 +- tests/testthat/test-watcher.R | 6 ++- 58 files changed, 287 insertions(+), 217 deletions(-) diff --git a/R/auto-test.R b/R/auto-test.R index 6d7e1ba3e..3c30abb52 100644 --- a/R/auto-test.R +++ b/R/auto-test.R @@ -61,7 +61,6 @@ auto_test <- function(code_path, test_path, reporter = default_reporter(), TRUE } watch(c(code_path, test_path), watcher, hash = hash) - } #' Watches a package for changes, rerunning tests as appropriate. @@ -75,8 +74,10 @@ auto_test <- function(code_path, test_path, reporter = default_reporter(), #' @seealso [auto_test()] for details on how method works auto_test_package <- function(pkg = ".", reporter = default_reporter(), hash = TRUE) { if (!requireNamespace("devtools", quietly = TRUE)) { - stop("devtools required to run auto_test_package(). Please install.", - call. = FALSE) + stop( + "devtools required to run auto_test_package(). Please install.", + call. = FALSE + ) } pkg <- devtools::as.package(pkg) @@ -120,5 +121,4 @@ auto_test_package <- function(pkg = ".", reporter = default_reporter(), hash = T TRUE } watch(c(code_path, test_path), watcher, hash = hash) - } diff --git a/R/compare-character.R b/R/compare-character.R index a7d27a48a..70b9b9f4b 100644 --- a/R/compare-character.R +++ b/R/compare-character.R @@ -27,7 +27,6 @@ compare.character <- function(x, y, check.attributes = TRUE, ..., max_diffs = 5, max_lines = 5, width = console_width()) { - if (identical(x, y)) { return(no_difference()) } @@ -61,7 +60,6 @@ compare.character <- function(x, y, check.attributes = TRUE, ..., } mismatch_character <- function(x, y, diff = !vector_equal(x, y)) { - structure( list( i = which(diff), diff --git a/R/compare-numeric.R b/R/compare-numeric.R index f9ce6ad11..0063ca83f 100644 --- a/R/compare-numeric.R +++ b/R/compare-numeric.R @@ -20,8 +20,10 @@ compare.numeric <- function(x, y, tolerance = .Machine$double.eps ^ 0.5, check.attributes = TRUE, ..., max_diffs = 9) { - all_equal <- all.equal(x, y, tolerance = tolerance, - check.attributes = check.attributes, ...) + all_equal <- all.equal( + x, y, tolerance = tolerance, + check.attributes = check.attributes, ... + ) if (isTRUE(all_equal)) { return(no_difference()) } @@ -65,7 +67,6 @@ mismatch_numeric <- function(x, y, diff = !vector_equal(x, y)) { #' @export format.mismatch_numeric <- function(x, ..., max_diffs = 9, digits = 3) { - summary <- paste0(x$n_diff, "/", x$n, " mismatches") if (x$n_diff > 1) { mu <- format(x$mu_diff, digits = digits, trim = TRUE) diff --git a/R/compare.R b/R/compare.R index 868f30074..cbc84f8e5 100644 --- a/R/compare.R +++ b/R/compare.R @@ -67,8 +67,9 @@ same_type <- function(x, y) identical(typeof(x), typeof(y)) diff_type <- function(x, y) difference(fmt = "Types not compatible: %s is not %s", typeof(x), typeof(y)) same_class <- function(x, y) { - if (!is.object(x) && !is.object(y)) + if (!is.object(x) && !is.object(y)) { return(TRUE) + } identical(class(x), class(y)) } diff_class <- function(x, y) { diff --git a/R/describe.R b/R/describe.R index df47252cd..9741abaef 100644 --- a/R/describe.R +++ b/R/describe.R @@ -56,7 +56,7 @@ #' }) describe <- function(description, code) { - is_invalid_description <- function (description) { + is_invalid_description <- function(description) { !is.character(description) || length(description) != 1 || nchar(description) == 0 } diff --git a/R/evaluate-promise.R b/R/evaluate-promise.R index b9d8d35c6..a1c16df9e 100644 --- a/R/evaluate-promise.R +++ b/R/evaluate-promise.R @@ -16,7 +16,6 @@ #' 4 #' }) evaluate_promise <- function(code, print = FALSE) { - warnings <- Stack$new() handle_warning <- function(condition) { warnings$push(condition) @@ -32,7 +31,8 @@ evaluate_promise <- function(code, print = FALSE) { temp <- file() on.exit(close(temp)) - result <- withr::with_output_sink(temp, + result <- withr::with_output_sink( + temp, withCallingHandlers( withVisible(code), warning = handle_warning, diff --git a/R/expect-comparison.R b/R/expect-comparison.R index dec6fb942..4fd1ae0ad 100644 --- a/R/expect-comparison.R +++ b/R/expect-comparison.R @@ -28,9 +28,9 @@ expect_compare <- function(operator = c("<", "<=", ">", ">="), act, exp) { stopifnot(is.numeric(exp$val), length(exp$val) == 1) msg <- c( - "<" = "not strictly less than", + "<" = "not strictly less than", "<=" = "not less than", - ">" = "not strictly more than", + ">" = "not strictly more than", ">=" = "not more than" )[[operator]] diff --git a/R/expect-equality.R b/R/expect-equality.R index b27c9eb1e..43f8a6968 100644 --- a/R/expect-equality.R +++ b/R/expect-equality.R @@ -48,7 +48,6 @@ NULL #' @param ... other values passed to [all.equal()] expect_equal <- function(object, expected, ..., info = NULL, label = NULL, expected.label = NULL) { - act <- quasi_label(enquo(object), label) exp <- quasi_label(enquo(expected), expected.label) @@ -66,7 +65,6 @@ expect_equal <- function(object, expected, ..., info = NULL, label = NULL, #' @export #' @rdname equality-expectations expect_setequal <- function(object, expected) { - act <- quasi_label(enquo(object)) exp <- quasi_label(enquo(expected)) @@ -103,7 +101,6 @@ expect_equivalent <- function(object, expected, ..., info = NULL, label = NULL, #' @rdname equality-expectations expect_identical <- function(object, expected, info = NULL, label = NULL, expected.label = NULL) { - act <- quasi_label(enquo(object), label) exp <- quasi_label(enquo(expected), expected.label) @@ -131,7 +128,6 @@ expect_identical <- function(object, expected, info = NULL, label = NULL, #' @rdname equality-expectations expect_identical <- function(object, expected, info = NULL, label = NULL, expected.label = NULL) { - act <- quasi_label(enquo(object), label) exp <- quasi_label(enquo(expected), expected.label) @@ -159,7 +155,6 @@ expect_identical <- function(object, expected, info = NULL, label = NULL, #' @rdname equality-expectations expect_reference <- function(object, expected, info = NULL, label = NULL, expected.label = NULL) { - act <- quasi_label(enquo(object), label) exp <- quasi_label(enquo(expected), expected.label) diff --git a/R/expect-known.R b/R/expect-known.R index 24895a68e..67c85b29f 100644 --- a/R/expect-known.R +++ b/R/expect-known.R @@ -44,7 +44,6 @@ expect_known_output <- function(object, file, label = NULL, print = FALSE, width = 80) { - act <- list() act$quo <- enquo(object) act$lab <- label %||% quo_label(act$quo) @@ -86,7 +85,6 @@ expect_known_value <- function(object, file, ..., info = NULL, label = NULL) { - act <- quasi_label(enquo(object), label) if (!file.exists(file)) { @@ -126,7 +124,6 @@ expect_equal_to_reference <- function(..., update = FALSE) { #' @param hash Known hash value. Leave empty and you'll be informed what #' to use in the test output. expect_known_hash <- function(object, hash = NULL) { - act <- quasi_label(enquo(object)) act_hash <- digest::digest(act$val) if (!is.null(hash)) { diff --git a/R/expect-named.R b/R/expect-named.R index bcab26e46..2695d78bf 100644 --- a/R/expect-named.R +++ b/R/expect-named.R @@ -28,7 +28,6 @@ expect_named <- function(object, expected, ignore.order = FALSE, ignore.case = FALSE, info = NULL, label = NULL) { - act <- quasi_label(enquo(object), label = label) act$names <- names(act$val) @@ -43,7 +42,8 @@ expect_named <- function(object, expected, ignore.order = FALSE, expect( identical(act$names, exp_names), - sprintf("Names of %s (%s) don't match %s", + sprintf( + "Names of %s (%s) don't match %s", act$lab, paste0("'", act$names, "'", collapse = ", "), paste0("'", exp_names, "'", collapse = ", ") diff --git a/R/expect-output.R b/R/expect-output.R index effe90937..3cf64aeff 100644 --- a/R/expect-output.R +++ b/R/expect-output.R @@ -87,7 +87,6 @@ NULL #' @export #' @rdname output-expectations expect_output <- function(object, regexp = NULL, ..., info = NULL, label = NULL) { - act <- quasi_capture(enquo(object), capture_output, label = label) if (identical(regexp, NA)) { @@ -118,7 +117,6 @@ expect_error <- function(object, ..., info = NULL, label = NULL) { - act <- quasi_capture(enquo(object), capture_error, label = label) msg <- compare_condition(act$cap, act$lab, regexp = regexp, class = class, ...) expect(is.null(msg), msg, info = info) @@ -134,10 +132,11 @@ expect_condition <- function(object, ..., info = NULL, label = NULL) { - act <- quasi_capture(enquo(object), capture_condition, label = label) - msg <- compare_condition(act$cap, act$lab, regexp = regexp, class = class, ..., - cond_type = "condition") + msg <- compare_condition( + act$cap, act$lab, regexp = regexp, class = class, ..., + cond_type = "condition" + ) expect(is.null(msg), msg, info = info) invisible(act$val %||% act$err) @@ -148,7 +147,6 @@ expect_condition <- function(object, #' @rdname output-expectations expect_message <- function(object, regexp = NULL, ..., all = FALSE, info = NULL, label = NULL) { - act <- quasi_capture(enquo(object), capture_messages, label = label) msg <- compare_messages(act$cap, act$lab, regexp = regexp, all = all, ...) expect(is.null(msg), msg, info = info) @@ -160,10 +158,11 @@ expect_message <- function(object, regexp = NULL, ..., all = FALSE, #' @rdname output-expectations expect_warning <- function(object, regexp = NULL, ..., all = FALSE, info = NULL, label = NULL) { - act <- quasi_capture(enquo(object), capture_warnings, label = label) - msg <- compare_messages(act$cap, act$lab, regexp = regexp, all = all, ..., - cond_type = "warnings") + msg <- compare_messages( + act$cap, act$lab, regexp = regexp, all = all, ..., + cond_type = "warnings" + ) expect(is.null(msg), msg, info = info) invisible(act$val) @@ -257,7 +256,6 @@ compare_messages <- function(messages, regexp = NA, ..., all = FALSE, cond_type = "messages") { - bullets <- paste0("* ", messages, collapse = "\n") # Expecting no messages if (identical(regexp, NA)) { diff --git a/R/expect-self-test.R b/R/expect-self-test.R index 97d4d5a05..d0d881521 100644 --- a/R/expect-self-test.R +++ b/R/expect-self-test.R @@ -67,7 +67,8 @@ show_failure <- function(expr) { #' @rdname expect_success #' @param path Path to save failure output expect_known_failure <- function(path, expr) { - FailureReporter <- R6::R6Class("FailureReporter", inherit = CheckReporter, + FailureReporter <- R6::R6Class( + "FailureReporter", inherit = CheckReporter, public = list(end_reporter = function(...) {}) ) diff --git a/R/expectation.R b/R/expectation.R index 40645efaa..cda80ad85 100644 --- a/R/expectation.R +++ b/R/expectation.R @@ -160,8 +160,10 @@ as.expectation <- function(x, ...) UseMethod("as.expectation", x) #' @export as.expectation.default <- function(x, ..., srcref = NULL) { - stop("Don't know how to convert '", paste(class(x), collapse = "', '"), - "' to expectation.", call. = FALSE) + stop( + "Don't know how to convert '", paste(class(x), collapse = "', '"), + "' to expectation.", call. = FALSE + ) } #' @export @@ -234,9 +236,9 @@ format.expectation <- function(x, ...) { single_letter_summary <- function(x) { switch(expectation_type(x), - skip = colourise("S", "skip"), + skip = colourise("S", "skip"), success = colourise(".", "success"), - error = colourise("E", "error"), + error = colourise("E", "error"), failure = colourise("F", "failure"), warning = colourise("W", "warning"), "?" diff --git a/R/expectations-matches.R b/R/expectations-matches.R index ca1c1cea9..ea44bfa7c 100644 --- a/R/expectations-matches.R +++ b/R/expectations-matches.R @@ -20,7 +20,6 @@ #' } expect_match <- function(object, regexp, perl = FALSE, fixed = FALSE, ..., all = TRUE, info = NULL, label = NULL) { - if (fixed) escape <- identity else escape <- escape_regex @@ -38,8 +37,10 @@ expect_match <- function(object, regexp, perl = FALSE, fixed = FALSE, ..., all = if (length(act$val) == 1) { values <- paste0("Actual value: \"", escape(encodeString(act$val)), "\"") } else { - values <- paste0("Actual values:\n", - paste0("* ", escape(encodeString(act$val)), collapse = "\n")) + values <- paste0( + "Actual values:\n", + paste0("* ", escape(encodeString(act$val)), collapse = "\n") + ) } expect( if (all) all(matches) else any(matches), diff --git a/R/make-expectation.R b/R/make-expectation.R index 1069f40cd..96507cc02 100644 --- a/R/make-expectation.R +++ b/R/make-expectation.R @@ -18,9 +18,13 @@ #' make_expectation(df) make_expectation <- function(x, expectation = "equals") { obj <- substitute(x) - expectation <- match.arg(expectation, - c("equals", "is_equivalent_to", "is_identical_to")) + expectation <- match.arg( + expectation, + c("equals", "is_equivalent_to", "is_identical_to") + ) - dput(substitute(expect_equal(obj, values), - list(obj = obj, expectation = as.name(expectation), values = x))) + dput(substitute( + expect_equal(obj, values), + list(obj = obj, expectation = as.name(expectation), values = x) + )) } diff --git a/R/mock.R b/R/mock.R index 8ae8c5ce6..b043b6365 100644 --- a/R/mock.R +++ b/R/mock.R @@ -42,8 +42,10 @@ with_mock <- function(..., .env = topenv()) { mock_qual_names <- names(new_values) if (all(mock_qual_names == "")) { - warning("Not mocking anything. Please use named parameters to specify the functions you want to mock.", - call. = FALSE) + warning( + "Not mocking anything. Please use named parameters to specify the functions you want to mock.", + call. = FALSE + ) code_pos <- rep(TRUE, length(new_values)) } else { code_pos <- (mock_qual_names == "") @@ -82,8 +84,10 @@ extract_mocks <- function(new_values, .env, eval_env = parent.frame()) { pkg_name <- gsub(pkg_and_name_rx, "\\1", qual_name) if (is_base_pkg(pkg_name)) { - stop("Can't mock functions in base packages (", pkg_name, ")", - call. = FALSE) + stop( + "Can't mock functions in base packages (", pkg_name, ")", + call. = FALSE + ) } name <- gsub(pkg_and_name_rx, "\\2", qual_name) diff --git a/R/old-school.R b/R/old-school.R index 3fe3c79b7..635863091 100644 --- a/R/old-school.R +++ b/R/old-school.R @@ -14,8 +14,10 @@ NULL #' @export #' @rdname oldskool is_null <- function() { - warning("is_null is deprecated. Please use `expect_null` instead.", - call. = FALSE) + warning( + "is_null is deprecated. Please use `expect_null` instead.", + call. = FALSE + ) function(x) expect_null(x) } @@ -124,8 +126,10 @@ matches <- function(regexp, all = TRUE, ...) { #' @export #' @param amount maximum duration in seconds takes_less_than <- function(amount) { - warning("takes_less_than() is deprecated because it is stochastic and unreliable", - call. = FALSE) + warning( + "takes_less_than() is deprecated because it is stochastic and unreliable", + call. = FALSE + ) function(expr) { duration <- system.time(force(expr))["elapsed"] diff --git a/R/recover.R b/R/recover.R index b7e034f82..c9187f790 100644 --- a/R/recover.R +++ b/R/recover.R @@ -31,7 +31,9 @@ recover2 <- function(start_frame = 1L, end_frame = sys.nframe()) { frame <- sys.frame(start_frame - 2 + which) browse_frame(frame, skip = 7 - which) } - else break + else { + break + } } } @@ -40,6 +42,8 @@ show_menu <- function(choices, title = NULL) { } browse_frame <- function(frame, skip) { - eval(substitute(browser(skipCalls = skip), list(skip = skip)), - envir = frame) + eval( + substitute(browser(skipCalls = skip), list(skip = skip)), + envir = frame + ) } diff --git a/R/reporter-check.R b/R/reporter-check.R index 1b5754134..763907c5a 100644 --- a/R/reporter-check.R +++ b/R/reporter-check.R @@ -8,7 +8,8 @@ NULL #' #' @export #' @family reporters -CheckReporter <- R6::R6Class("CheckReporter", inherit = Reporter, +CheckReporter <- R6::R6Class( + "CheckReporter", inherit = Reporter, public = list( failures = list(), n_ok = 0L, @@ -62,8 +63,9 @@ CheckReporter <- R6::R6Class("CheckReporter", inherit = Reporter, labels <- format(paste0(1:length(show), ".")) self$cat_paragraph(paste0(labels, " ", fails, collapse = "\n")) - if (self$stop_on_failure) + if (self$stop_on_failure) { stop("testthat unit tests failed", call. = FALSE) + } } ) ) diff --git a/R/reporter-debug.R b/R/reporter-debug.R index 9cfe64ec1..d26722315 100644 --- a/R/reporter-debug.R +++ b/R/reporter-debug.R @@ -8,7 +8,8 @@ NULL #' #' @export #' @family reporters -DebugReporter <- R6::R6Class("DebugReporter", inherit = Reporter, +DebugReporter <- R6::R6Class( + "DebugReporter", inherit = Reporter, public = list( add_result = function(context, test, result) { if (!expectation_success(result)) { @@ -17,8 +18,10 @@ DebugReporter <- R6::R6Class("DebugReporter", inherit = Reporter, on.exit(sink(), add = TRUE) } - recover2(start_frame = result$start_frame, - end_frame = result$end_frame) + recover2( + start_frame = result$start_frame, + end_frame = result$end_frame + ) } } ) diff --git a/R/reporter-fail.R b/R/reporter-fail.R index 67a154a18..7807e3759 100644 --- a/R/reporter-fail.R +++ b/R/reporter-fail.R @@ -9,7 +9,8 @@ NULL #' #' @export #' @family reporters -FailReporter <- R6::R6Class("FailReporter", inherit = Reporter, +FailReporter <- R6::R6Class( + "FailReporter", inherit = Reporter, public = list( failed = FALSE, diff --git a/R/reporter-junit.R b/R/reporter-junit.R index 4afe20b20..0a77b235f 100644 --- a/R/reporter-junit.R +++ b/R/reporter-junit.R @@ -26,17 +26,18 @@ classnameOK <- function(text) { #' \url{http://llg.cubic.org/docs/junit/} #' #' @export -JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, +JunitReporter <- R6::R6Class( + "JunitReporter", inherit = Reporter, public = list( - results = NULL, - timer = NULL, - doc = NULL, - errors = NULL, + results = NULL, + timer = NULL, + doc = NULL, + errors = NULL, failures = NULL, - skipped = NULL, - tests = NULL, - root = NULL, - suite = NULL, + skipped = NULL, + tests = NULL, + root = NULL, + suite = NULL, suite_time = NULL, elapsed_time = function() { @@ -45,11 +46,11 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, time }, - reset_suite = function () { - self$errors <- 0 + reset_suite = function() { + self$errors <- 0 self$failures <- 0 - self$skipped <- 0 - self$tests <- 0 + self$skipped <- 0 + self$tests <- 0 self$suite_time <- 0 }, @@ -59,17 +60,18 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, } self$timer <- private$proctime() - self$doc <- xml2::xml_new_document() - self$root <- xml2::xml_add_child(self$doc, "testsuites") + self$doc <- xml2::xml_new_document() + self$root <- xml2::xml_add_child(self$doc, "testsuites") self$reset_suite() }, start_context = function(context) { - self$suite <- xml2::xml_add_child(self$root, + self$suite <- xml2::xml_add_child( + self$root, "testsuite", - name = context, + name = context, timestamp = private$timestamp(), - hostname = private$hostname() + hostname = private$hostname() ) }, @@ -91,7 +93,8 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, # XML node for test case name <- test %||% "(unnamed)" - testcase <- xml2::xml_add_child(self$suite, "testcase", + testcase <- xml2::xml_add_child( + self$suite, "testcase", time = toString(time), classname = classnameOK(context), name = classnameOK(name) @@ -107,13 +110,11 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, error <- xml2::xml_add_child(testcase, "error", type = "error", message = first_line(result)) xml2::xml_text(error) <- format(result) self$errors <- self$errors + 1 - } else if (expectation_failure(result)) { # "type" in Java is the type of assertion that failed failure <- xml2::xml_add_child(testcase, "failure", type = "failure", message = first_line(result)) xml2::xml_text(failure) <- format(result) self$failures <- self$failures + 1 - } else if (expectation_skip(result)) { xml2::xml_add_child(testcase, "skipped") self$skipped <- self$skipped + 1 @@ -133,14 +134,14 @@ JunitReporter <- R6::R6Class("JunitReporter", inherit = Reporter, } # end_reporter ), # public - private = list ( - proctime = function () { + private = list( + proctime = function() { proc.time() }, - timestamp = function () { + timestamp = function() { toString(Sys.time()) }, - hostname = function () { + hostname = function() { Sys.info()[["nodename"]] } ) # private diff --git a/R/reporter-list.R b/R/reporter-list.R index acd5183be..84fa49a16 100644 --- a/R/reporter-list.R +++ b/R/reporter-list.R @@ -12,7 +12,8 @@ methods::setOldClass("proc_time") #' #' @export #' @family reporters -ListReporter <- R6::R6Class("ListReporter", inherit = Reporter, +ListReporter <- R6::R6Class( + "ListReporter", inherit = Reporter, public = list( current_start_time = NA, current_expectations = NULL, @@ -30,20 +31,21 @@ ListReporter <- R6::R6Class("ListReporter", inherit = Reporter, }, add_result = function(context, test, result) { - if (!is.null(self$current_expectations)) + if (!is.null(self$current_expectations)) { self$current_expectations$push(result) + } }, end_test = function(context, test) { elapsed <- as.double(proc.time() - self$current_start_time) self$results$push(list( - file = self$current_file %||% NA_character_, + file = self$current_file %||% NA_character_, context = context, - test = test, - user = elapsed[1], - system = elapsed[2], - real = elapsed[3], + test = test, + user = elapsed[1], + system = elapsed[2], + real = elapsed[3], results = self$current_expectations$as_list() )) }, @@ -65,23 +67,25 @@ ListReporter <- R6::R6Class("ListReporter", inherit = Reporter, #' @return its list argument as a `testthat_results` object #' @seealso ListReporter #' @keywords internal -testthat_results <- function(results) { +testthat_results <- function(results) { stopifnot(is.list(results)) structure(results, class = "testthat_results") } # return if all tests are successful w/o error all_passed <- function(res) { - if (length(res) == 0) + if (length(res) == 0) { return(TRUE) + } df <- as.data.frame.testthat_results(res) sum(df$failed) == 0 && all(!df$error) } any_warnings <- function(res) { - if (length(res) == 0) + if (length(res) == 0) { return(FALSE) + } df <- as.data.frame.testthat_results(res) any(df$warning > 0) @@ -90,8 +94,9 @@ any_warnings <- function(res) { #' @export as.data.frame.testthat_results <- function(x, ...) { - if (length(x) == 0) + if (length(x) == 0) { return(data.frame()) + } rows <- lapply(x, sumarize_one_test_results) do.call(rbind, rows) @@ -114,7 +119,7 @@ sumarize_one_test_results <- function(test) { nb_tests <- length(test_results) } - nb_passed <- sum(vapply(test_results, expectation_success, logical(1))) + nb_passed <- sum(vapply(test_results, expectation_success, logical(1))) nb_skipped <- sum(vapply(test_results, expectation_skip, logical(1))) nb_failed <- sum(vapply(test_results, expectation_failure, logical(1))) nb_warning <- sum(vapply(test_results, expectation_warning, logical(1))) @@ -122,11 +127,13 @@ sumarize_one_test_results <- function(test) { context <- if (length(test$context) > 0) test$context else "" - res <- data.frame(file = test$file, context = context, test = test$test, + res <- data.frame( + file = test$file, context = context, test = test$test, nb = nb_tests, failed = nb_failed, skipped = as.logical(nb_skipped), error = error, warning = nb_warning, user = test$user, system = test$system, real = test$real, - stringsAsFactors = FALSE) + stringsAsFactors = FALSE + ) res } diff --git a/R/reporter-location.R b/R/reporter-location.R index 8efcf3750..50115d237 100644 --- a/R/reporter-location.R +++ b/R/reporter-location.R @@ -9,7 +9,8 @@ NULL #' #' @export #' @family reporters -LocationReporter <- R6::R6Class("LocationReporter", inherit = Reporter, +LocationReporter <- R6::R6Class( + "LocationReporter", inherit = Reporter, public = list( start_test = function(context, test) { self$cat_line("Start test: ", test) diff --git a/R/reporter-minimal.R b/R/reporter-minimal.R index 86358332c..def3ce28d 100644 --- a/R/reporter-minimal.R +++ b/R/reporter-minimal.R @@ -10,7 +10,8 @@ NULL #' #' @export #' @family reporters -MinimalReporter <- R6::R6Class("MinimalReporter", inherit = Reporter, +MinimalReporter <- R6::R6Class( + "MinimalReporter", inherit = Reporter, public = list( add_result = function(context, test, result) { self$cat_tight(single_letter_summary(result)) diff --git a/R/reporter-multi.R b/R/reporter-multi.R index 989bb3b1c..b7ca2e47b 100644 --- a/R/reporter-multi.R +++ b/R/reporter-multi.R @@ -8,7 +8,8 @@ NULL #' #' @export #' @family reporters -MultiReporter <- R6::R6Class("MultiReporter", inherit = Reporter, +MultiReporter <- R6::R6Class( + "MultiReporter", inherit = Reporter, public = list( reporters = list(), diff --git a/R/reporter-progress.R b/R/reporter-progress.R index c29680768..e38d5b91d 100644 --- a/R/reporter-progress.R +++ b/R/reporter-progress.R @@ -13,7 +13,8 @@ NULL #' @export #' @family reporters #' @importFrom clisymbols symbol -ProgressReporter <- R6::R6Class("ProgressReporter", inherit = Reporter, +ProgressReporter <- R6::R6Class( + "ProgressReporter", inherit = Reporter, public = list( show_praise = TRUE, min_time = 0.1, @@ -76,7 +77,6 @@ ProgressReporter <- R6::R6Class("ProgressReporter", inherit = Reporter, }, show_status = function(complete = FALSE) { - if (complete) { if (self$ctxt_n_fail > 0) { status <- crayon::red(symbol$cross) @@ -134,7 +134,6 @@ ProgressReporter <- R6::R6Class("ProgressReporter", inherit = Reporter, self$n_fail <- self$n_fail + 1 self$ctxt_n_fail <- self$ctxt_n_fail + 1 self$ctxt_issues$push(result) - } else if (expectation_skip(result)) { self$n_skip <- self$n_skip + 1 self$ctxt_n_skip <- self$ctxt_n_skip + 1 @@ -170,8 +169,9 @@ ProgressReporter <- R6::R6Class("ProgressReporter", inherit = Reporter, self$cat_line("Warnings: ", colour_if(self$n_warn, "warn")) self$cat_line("Skipped: ", colour_if(self$n_skip, "skip")) - if (!self$show_praise || runif(1) > 0.1) + if (!self$show_praise || runif(1) > 0.1) { return() + } self$cat_line() if (self$n_fail == 0) { diff --git a/R/reporter-rstudio.R b/R/reporter-rstudio.R index 4947ccba2..77a959a00 100644 --- a/R/reporter-rstudio.R +++ b/R/reporter-rstudio.R @@ -8,11 +8,13 @@ NULL #' #' @export #' @family reporters -RstudioReporter <- R6::R6Class("RstudioReporter", inherit = Reporter, +RstudioReporter <- R6::R6Class( + "RstudioReporter", inherit = Reporter, public = list( add_result = function(context, test, result) { - if (expectation_success(result)) + if (expectation_success(result)) { return() + } ref <- result$srcref if (is.null(ref)) { diff --git a/R/reporter-silent.R b/R/reporter-silent.R index d26dc724c..778715464 100644 --- a/R/reporter-silent.R +++ b/R/reporter-silent.R @@ -10,7 +10,8 @@ NULL #' #' @export #' @family reporters -SilentReporter <- R6::R6Class("SilentReporter", inherit = Reporter, +SilentReporter <- R6::R6Class( + "SilentReporter", inherit = Reporter, public = list( .expectations = NULL, diff --git a/R/reporter-stop.R b/R/reporter-stop.R index f440e7cc0..1b39264ba 100644 --- a/R/reporter-stop.R +++ b/R/reporter-stop.R @@ -13,7 +13,8 @@ NULL #' #' @export #' @family reporters -StopReporter <- R6::R6Class("StopReporter", inherit = Reporter, +StopReporter <- R6::R6Class( + "StopReporter", inherit = Reporter, public = list( failures = NULL, diff --git a/R/reporter-summary.R b/R/reporter-summary.R index a896b1a40..3bc2956a6 100644 --- a/R/reporter-summary.R +++ b/R/reporter-summary.R @@ -16,7 +16,8 @@ NULL #' #' @export #' @family reporters -SummaryReporter <- R6::R6Class("SummaryReporter", inherit = Reporter, +SummaryReporter <- R6::R6Class( + "SummaryReporter", inherit = Reporter, public = list( failures = NULL, skips = NULL, @@ -110,8 +111,9 @@ SummaryReporter <- R6::R6Class("SummaryReporter", inherit = Reporter, cat_reports = function(header, expectations, max_n, summary_fun, collapse = "\n\n") { n <- length(expectations) - if (n == 0L) + if (n == 0L) { return() + } self$rule(header) diff --git a/R/reporter-tap.R b/R/reporter-tap.R index 59186e72c..3e4e5cd9a 100644 --- a/R/reporter-tap.R +++ b/R/reporter-tap.R @@ -9,7 +9,8 @@ NULL #' #' @export #' @family reporters -TapReporter <- R6::R6Class("TapReporter", inherit = Reporter, +TapReporter <- R6::R6Class( + "TapReporter", inherit = Reporter, public = list( results = list(), n = 0L, @@ -27,8 +28,9 @@ TapReporter <- R6::R6Class("TapReporter", inherit = Reporter, }, end_reporter = function() { - if (!self$has_tests) + if (!self$has_tests) { return() + } self$cat_line("1..", self$n) for (i in 1:self$n) { @@ -43,8 +45,10 @@ TapReporter <- R6::R6Class("TapReporter", inherit = Reporter, msg <- gsub("(^|\n)", "\\1 ", format(result)) self$cat_line(msg) } else { - self$cat_line("ok ", i, " # ", toupper(expectation_type(result)), " ", - format(result)) + self$cat_line( + "ok ", i, " # ", toupper(expectation_type(result)), " ", + format(result) + ) } } } diff --git a/R/reporter-teamcity.R b/R/reporter-teamcity.R index a70a2a1e2..1220fb7d0 100644 --- a/R/reporter-teamcity.R +++ b/R/reporter-teamcity.R @@ -9,7 +9,8 @@ NULL #' #' @export #' @family reporters -TeamcityReporter <- R6::R6Class("TeamcityReporter", inherit = Reporter, +TeamcityReporter <- R6::R6Class( + "TeamcityReporter", inherit = Reporter, public = list( i = NA_integer_, @@ -46,7 +47,8 @@ TeamcityReporter <- R6::R6Class("TeamcityReporter", inherit = Reporter, if (!expectation_ok(result)) { lines <- strsplit(format(result), "\n")[[1]] - private$report_event("testFailed", testName, message = lines[1], + private$report_event( + "testFailed", testName, message = lines[1], details = paste(lines[-1], collapse = "\n") ) } diff --git a/R/reporter.R b/R/reporter.R index 4401f7c53..fec86f092 100644 --- a/R/reporter.R +++ b/R/reporter.R @@ -8,7 +8,8 @@ #' @export Reporter #' @aliases Reporter #' @importFrom R6 R6Class -Reporter <- R6::R6Class("Reporter", +Reporter <- R6::R6Class( + "Reporter", public = list( start_reporter = function() {}, start_context = function(context) {}, @@ -80,7 +81,6 @@ Reporter <- R6::R6Class("Reporter", # in the same way as tests and expectations. .context = NULL, .start_context = function(context) { - if (!is.null(self$.context)) { self$end_context(self$.context) } diff --git a/R/skip.R b/R/skip.R index bd1e85cc0..00f49c799 100644 --- a/R/skip.R +++ b/R/skip.R @@ -113,15 +113,17 @@ skip_on_cran <- function() { #' `"windows"`, `"mac"`, `"linux"` and `"solaris"`. #' @rdname skip skip_on_os <- function(os) { - os <- match.arg(os, c("windows", "mac", "linux", "solaris"), - several.ok = TRUE) + os <- match.arg( + os, c("windows", "mac", "linux", "solaris"), + several.ok = TRUE + ) sysname <- tolower(Sys.info()[["sysname"]]) switch(sysname, windows = if ("windows" %in% os) skip("On windows"), - darwin = if ("mac" %in% os) skip("On Mac"), - linux = if ("linux" %in% os) skip("On Linux"), - sunos = if ("solaris" %in% os) skip("On Solaris") + darwin = if ("mac" %in% os) skip("On Mac"), + linux = if ("linux" %in% os) skip("On Linux"), + sunos = if ("solaris" %in% os) skip("On Solaris") ) invisible(TRUE) diff --git a/R/stack.R b/R/stack.R index 04b4de761..b94662e89 100644 --- a/R/stack.R +++ b/R/stack.R @@ -8,7 +8,6 @@ Stack <- R6Class( "Stack", class = FALSE, public = list( - initialize = function(init = 20L) { # init is the initial size of the list. It is also used as the minimum # size of the list as it shrinks. @@ -43,8 +42,8 @@ Stack <- R6Class( ), private = list( - stack = NULL, # A list that holds the items - count = 0L, # Current number of items in the stack - init = 20L # Initial and minimum size of the stack + stack = NULL, # A list that holds the items + count = 0L, # Current number of items in the stack + init = 20L # Initial and minimum size of the stack ) ) diff --git a/R/test-compiled-code.R b/R/test-compiled-code.R index de0aa7176..89a8c004a 100644 --- a/R/test-compiled-code.R +++ b/R/test-compiled-code.R @@ -13,7 +13,6 @@ #' #' @export expect_cpp_tests_pass <- function(package) { - run_testthat_tests <- get_routine(package, "run_testthat_tests") output <- "" @@ -30,7 +29,6 @@ expect_cpp_tests_pass <- function(package) { info <- paste(output[-1], collapse = "\n") expect(tests_passed, paste("C++ unit tests:", info, sep = "\n")) - } #' Use Catch for C++ Unit Testing @@ -157,19 +155,21 @@ expect_cpp_tests_pass <- function(package) { #' @seealso \href{https://github.com/philsquared/Catch}{Catch}, the #' library used to enable C++ unit testing. use_catch <- function(dir = getwd()) { - desc_path <- file.path(dir, "DESCRIPTION") - if (!file.exists(desc_path)) + if (!file.exists(desc_path)) { stop("no DESCRIPTION file at path '", desc_path, "'", call. = FALSE) + } desc <- read.dcf(desc_path, all = TRUE) pkg <- desc$Package - if (!nzchar(pkg)) + if (!nzchar(pkg)) { stop("no 'Package' field in DESCRIPTION file '", desc_path, "'", call. = FALSE) + } src_dir <- file.path(dir, "src") - if (!file.exists(src_dir) && !dir.create(src_dir)) + if (!file.exists(src_dir) && !dir.create(src_dir)) { stop("failed to create 'src/' directory '", src_dir, "'", call. = FALSE) + } test_runner_path <- file.path(src_dir, "test-runner.cpp") @@ -180,8 +180,9 @@ use_catch <- function(dir = getwd()) { overwrite = TRUE ) - if (!success) + if (!success) { stop("failed to copy 'test-runner.cpp' to '", src_dir, "'", call. = FALSE) + } # Copy the test example. success <- file.copy( @@ -190,13 +191,15 @@ use_catch <- function(dir = getwd()) { overwrite = TRUE ) - if (!success) + if (!success) { stop("failed to copy 'test-example.cpp' to '", src_dir, "'", call. = FALSE) + } # Copy the 'test-cpp.R' file. test_dir <- file.path(dir, "tests", "testthat") - if (!file.exists(test_dir) && !dir.create(test_dir, recursive = TRUE)) + if (!file.exists(test_dir) && !dir.create(test_dir, recursive = TRUE)) { stop("failed to create 'tests/testthat/' directory '", test_dir, "'", call. = FALSE) + } template_file <- system.file(package = "testthat", "resources", "test-cpp.R") contents <- readChar(template_file, file.info(template_file)$size, TRUE) @@ -214,7 +217,6 @@ use_catch <- function(dir = getwd()) { message("> Added C++ unit testing infrastructure.") message("> Please ensure you have 'LinkingTo: testthat' in your DESCRIPTION.") message("> Please ensure you have 'useDynLib(", pkg, ", .registration = TRUE)' in your NAMESPACE.") - } get_routine <- function(package, routine) { @@ -229,8 +231,9 @@ get_routine <- function(package, routine) { name <- paste(prefix, routine, sep = "") if (exists(name, envir = namespace)) { symbol <- get(name, envir = namespace) - if (inherits(symbol, "NativeSymbolInfo")) + if (inherits(symbol, "NativeSymbolInfo")) { return(symbol) + } } } @@ -241,8 +244,9 @@ get_routine <- function(package, routine) { getNativeSymbolInfo(routine, PACKAGE = package), error = function(e) NULL ) - if (inherits(resolved, "NativeSymbolInfo")) + if (inherits(resolved, "NativeSymbolInfo")) { return(symbol) + } } # if we got here, we failed to find the symbol -- throw an error diff --git a/R/test-directory.R b/R/test-directory.R index d00ec3c2e..b1ae9cd92 100644 --- a/R/test-directory.R +++ b/R/test-directory.R @@ -102,8 +102,9 @@ test_package <- function(package, # Ensure that test package returns silently if called recursively - this # will occur if test-all.R ends up in the same directory as all the other # tests. - if (env_test$in_test) + if (env_test$in_test) { return(invisible()) + } env_test$in_test <- TRUE env_test$package <- package @@ -113,8 +114,9 @@ test_package <- function(package, }) test_path <- system.file("tests", package = package) - if (test_path == "") + if (test_path == "") { stop("No tests found for ", package, call. = FALSE) + } # If testthat subdir exists, use that test_path2 <- file.path(test_path, "testthat") diff --git a/R/test-files.R b/R/test-files.R index ff7933da1..151fc7b4f 100644 --- a/R/test-files.R +++ b/R/test-files.R @@ -127,8 +127,10 @@ test_file <- function(path, reporter = default_reporter(), env = test_env(), { lister$start_file(basename(path)) - source_file(path, new.env(parent = env), - chdir = TRUE, wrap = wrap) + source_file( + path, new.env(parent = env), + chdir = TRUE, wrap = wrap + ) end_context() } diff --git a/R/test-path.R b/R/test-path.R index b541dff1e..1a7ebf18d 100644 --- a/R/test-path.R +++ b/R/test-path.R @@ -15,8 +15,10 @@ test_path <- function(...) { } else { base <- "tests/testthat" if (!file.exists(base)) { - stop("Can't find `tests/testthat` in current directory.", - call. = FALSE) + stop( + "Can't find `tests/testthat` in current directory.", + call. = FALSE + ) } path <- file.path(base, ...) } @@ -27,8 +29,9 @@ test_path <- function(...) { in_testing_dir <- function(path) { path <- normalizePath(path) - if (basename(path) != "testthat") + if (basename(path) != "testthat") { return(FALSE) + } parent <- dirname(path) if (grepl("-tests$", parent)) { diff --git a/R/test-that.R b/R/test-that.R index 26a5d45b3..0bebcdb98 100644 --- a/R/test-that.R +++ b/R/test-that.R @@ -147,21 +147,23 @@ test_code <- function(test, code, env = test_env(), skip_on_empty = TRUE) { test_env <- new.env(parent = env) tryCatch( - withCallingHandlers({ - eval(code, test_env) - if (!handled && !is.null(test)) - skip_empty() + withCallingHandlers( + { + eval(code, test_env) + if (!handled && !is.null(test)) { + skip_empty() + } }, expectation = handle_expectation, - skip = handle_skip, - warning = handle_warning, - message = handle_message, - error = handle_error + skip = handle_skip, + warning = handle_warning, + message = handle_message, + error = handle_error ), # some errors may need handling here, e.g., stack overflow error = handle_fatal, # skip silently terminate code - skip = function(e) {} + skip = function(e) {} ) diff --git a/R/traceback.R b/R/traceback.R index 5685801c9..98195f03d 100644 --- a/R/traceback.R +++ b/R/traceback.R @@ -12,10 +12,14 @@ create_traceback <- function(callstack) { # Extract srcrefs srcrefs <- lapply(callstack, attr, "srcref") has_ref <- vapply(srcrefs, function(x) inherits(x, "srcref"), logical(1)) - files <- vapply(srcrefs[has_ref], function(x) attr(x, "srcfile")$filename, - FUN.VALUE = character(1)) - lines <- vapply(srcrefs[has_ref], function(x) as.vector(x)[1], - FUN.VALUE = integer(1)) + files <- vapply( + srcrefs[has_ref], function(x) attr(x, "srcfile")$filename, + FUN.VALUE = character(1) + ) + lines <- vapply( + srcrefs[has_ref], function(x) as.vector(x)[1], + FUN.VALUE = integer(1) + ) calls[has_ref] <- paste0(calls[has_ref], " at ", files, ":", lines) diff --git a/R/try-again.R b/R/try-again.R index dc6d35041..39b8acfd4 100644 --- a/R/try-again.R +++ b/R/try-again.R @@ -35,8 +35,9 @@ try_again <- function(times, code) { } ) - if (is.null(e)) + if (is.null(e)) { return(invisible(TRUE)) + } times <- times - 1L } diff --git a/R/utils.R b/R/utils.R index ace940e2b..b19a20cdc 100644 --- a/R/utils.R +++ b/R/utils.R @@ -64,8 +64,9 @@ env_name <- function(x) { find_first_srcref <- function(calls) { for (call in calls) { srcref <- attr(call, "srcref") - if (!is.null(srcref)) + if (!is.null(srcref)) { return(srcref) + } } NULL } diff --git a/R/watcher.R b/R/watcher.R index c48fb5dc8..f66c5ab20 100644 --- a/R/watcher.R +++ b/R/watcher.R @@ -17,7 +17,6 @@ #' @export #' @keywords internal watch <- function(path, callback, pattern = NULL, hash = TRUE) { - prev <- dir_state(path, pattern, hash = hash) repeat { diff --git a/tests/testthat/helper-junitmock.R b/tests/testthat/helper-junitmock.R index a4b7080e8..3a82738dc 100644 --- a/tests/testthat/helper-junitmock.R +++ b/tests/testthat/helper-junitmock.R @@ -6,18 +6,19 @@ # - timestamp - originally wrapper for toString(Sys.time()) # - hostname - originally wrapper for Sys.info()[["nodename"]] # -createJunitReporterMock <- function (...) { - JunitReporterMock <- R6::R6Class("JunitReporterMock", +createJunitReporterMock <- function(...) { + JunitReporterMock <- R6::R6Class( + "JunitReporterMock", inherit = JunitReporter, - public = list (), - private = list ( - proctime = function () { + public = list(), + private = list( + proctime = function() { c(user = 0, system = 0, elapsed = 0) }, - timestamp = function () { + timestamp = function() { "1999:12:31 23:59:59" }, - hostname = function () { + hostname = function() { "nodename" } ) diff --git a/tests/testthat/test-bare.R b/tests/testthat/test-bare.R index 8cecc0154..0f2d084e2 100644 --- a/tests/testthat/test-bare.R +++ b/tests/testthat/test-bare.R @@ -5,10 +5,14 @@ expect_true(TRUE) expect_error(stop("!")) stopifnot( - tryCatch(expect_true(TRUE), - expectation_failure = function(e) FALSE) + tryCatch( + expect_true(TRUE), + expectation_failure = function(e) FALSE + ) ) stopifnot( - tryCatch(expect_true(FALSE), - expectation_failure = function(e) TRUE) + tryCatch( + expect_true(FALSE), + expectation_failure = function(e) TRUE + ) ) diff --git a/tests/testthat/test-context.R b/tests/testthat/test-context.R index 0030a5675..fb000a515 100644 --- a/tests/testthat/test-context.R +++ b/tests/testthat/test-context.R @@ -1,6 +1,7 @@ context("Contexts") -CountReporter <- R6::R6Class("CountReporter", inherit = Reporter, +CountReporter <- R6::R6Class( + "CountReporter", inherit = Reporter, public = list( context_i = 0, context_count = 0, diff --git a/tests/testthat/test-examples.R b/tests/testthat/test-examples.R index 0e39b76df..b1f78d3d0 100644 --- a/tests/testthat/test-examples.R +++ b/tests/testthat/test-examples.R @@ -7,7 +7,7 @@ test_that("test_examples works with installed packages", { test_rd = identity, { res <- test_examples() - - }) + } + ) expect_true(length(res) > 1) }) diff --git a/tests/testthat/test-expect-length.R b/tests/testthat/test-expect-length.R index 2e104da20..2c306984f 100644 --- a/tests/testthat/test-expect-length.R +++ b/tests/testthat/test-expect-length.R @@ -9,7 +9,7 @@ test_that("length computed correctly", { test_that("uses S4 length method", { A <- setClass("ExpectLengthA", slots = c(x = "numeric", y = "numeric")) - setMethod("length", "ExpectLengthA", function (x) 5L) + setMethod("length", "ExpectLengthA", function(x) 5L) expect_success(expect_length(A(x = 1:9, y = 3), 5)) }) diff --git a/tests/testthat/test-expect-self-test.R b/tests/testthat/test-expect-self-test.R index 02a8702d1..0fa609bac 100644 --- a/tests/testthat/test-expect-self-test.R +++ b/tests/testthat/test-expect-self-test.R @@ -1,6 +1,6 @@ context("expect-self-test") -test_that("fail always fails", { +test_that("fail always fails", { expect_failure(fail()) expect_failure(fail("abc"), "abc") }) diff --git a/tests/testthat/test-mock.R b/tests/testthat/test-mock.R index b0364ee0a..9351a33ab 100644 --- a/tests/testthat/test-mock.R +++ b/tests/testthat/test-mock.R @@ -79,8 +79,9 @@ test_that("can access variables defined in function", { }) test_that("can mock if package is not loaded", { - if ("package:devtools" %in% search()) + if ("package:devtools" %in% search()) { skip("devtools is loaded") + } skip_if_not_installed("devtools") with_mock(`devtools::add_path` = identity, expect_identical(devtools::add_path, identity)) }) diff --git a/tests/testthat/test-old-school.R b/tests/testthat/test-old-school.R index 31ff93c7a..4ed818308 100644 --- a/tests/testthat/test-old-school.R +++ b/tests/testthat/test-old-school.R @@ -7,7 +7,6 @@ test_that("old school logical works", { test_that("old school types still work", { expect_success(expect_that(1L, is_a("integer"))) - }) test_that("tidyverse conflicts throw warnings", { diff --git a/tests/testthat/test-reporter-list.R b/tests/testthat/test-reporter-list.R index b92a9b7a4..3911cb52d 100644 --- a/tests/testthat/test-reporter-list.R +++ b/tests/testthat/test-reporter-list.R @@ -24,5 +24,4 @@ test_that("ListReporter with test_file", { fl <- last_results[[1]] expect_equal(expectation_type(fl), "failure") - }) diff --git a/tests/testthat/test-reporter.R b/tests/testthat/test-reporter.R index ba3063bf3..685e5ae1f 100644 --- a/tests/testthat/test-reporter.R +++ b/tests/testthat/test-reporter.R @@ -3,11 +3,11 @@ context("Reporter") test_that("can locate reporter from name", { expect_that(find_reporter("minimal"), equals(MinimalReporter$new())) expect_that(find_reporter("summary"), equals(SummaryReporter$new())) - expect_that(find_reporter("tap"), equals(TapReporter$new())) - expect_that(find_reporter("list"), equals(ListReporter$new())) - expect_that(find_reporter("multi"), equals(MultiReporter$new())) - expect_that(find_reporter("junit"), equals(JunitReporter$new())) - expect_that(find_reporter(""), equals(Reporter$new())) + expect_that(find_reporter("tap"), equals(TapReporter$new())) + expect_that(find_reporter("list"), equals(ListReporter$new())) + expect_that(find_reporter("multi"), equals(MultiReporter$new())) + expect_that(find_reporter("junit"), equals(JunitReporter$new())) + expect_that(find_reporter(""), equals(Reporter$new())) }) test_that("useful error message if can't find reporter", { @@ -23,7 +23,8 @@ test_that("character vector yields multi reporter", { MultiReporter$new( reporters = list( SummaryReporter$new(), - StopReporter$new()) + StopReporter$new() + ) ) ) expect_equal( @@ -53,8 +54,10 @@ test_that("reporters produce consistent output", { with_mock( show_menu = function(choices, title = NULL) { - cat(paste0(format(seq_along(choices)), ": ", choices, sep = "\n"), "\n", - sep = "") + cat( + paste0(format(seq_along(choices)), ": ", choices, sep = "\n"), "\n", + sep = "" + ) 0L }, sink_number = function() 0L, @@ -77,10 +80,12 @@ test_that("reporters produce consistent output", { 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"))) + TapReporter$new(file = tap_file) + ))) + expect_identical( + read_lines(tap_file), + read_lines(test_path("reporters", "tap.txt")) + ) }) diff --git a/tests/testthat/test-test-that.R b/tests/testthat/test-test-that.R index dd2b611fe..f7f5e1cb3 100644 --- a/tests/testthat/test-test-that.R +++ b/tests/testthat/test-test-that.R @@ -89,18 +89,18 @@ expectation_lines <- function(code) { test_that("line numbers captured in simple case", { lines <- expectation_lines({ - context("testing testFile") # line 1 - test_that("simple", { # line 2 - expect_true(FALSE) # line 3 - }) # line 4 + context("testing testFile") # line 1 + test_that("simple", { # line 2 + expect_true(FALSE) # line 3 + }) # line 4 }) expect_equal(lines, 3) }) test_that("line numbers captured inside another function", { lines <- expectation_lines({ - test_that("simple", { # line 1 - suppressMessages(expect_true(FALSE)) # line 2 + test_that("simple", { # line 1 + suppressMessages(expect_true(FALSE)) # line 2 }) }) expect_equal(lines, 2) @@ -108,8 +108,8 @@ test_that("line numbers captured inside another function", { test_that("line numbers captured inside a loop", { lines <- expectation_lines({ - test_that("simple", { # line 1 - for (i in 1:4) expect_true(TRUE) # line 2 + test_that("simple", { # line 1 + for (i in 1:4) expect_true(TRUE) # line 2 }) }) expect_equal(lines, rep(2, 4)) @@ -117,18 +117,18 @@ test_that("line numbers captured inside a loop", { test_that("line numbers captured for skip()s", { lines <- expectation_lines({ - test_that("simple", { # line 1 - skip("Not this time") # line 2 - }) # line 3 + test_that("simple", { # line 1 + skip("Not this time") # line 2 + }) # line 3 }) expect_equal(lines, 2) }) test_that("line numbers captured for stop()s", { lines <- expectation_lines({ - test_that("simple", { # line 1 - skip("Not this time") # line 2 - }) # line 3 + test_that("simple", { # line 1 + skip("Not this time") # line 2 + }) # line 3 }) expect_equal(lines, 2) }) diff --git a/tests/testthat/test-test_dir.R b/tests/testthat/test-test_dir.R index a0c0e7b73..92d981071 100644 --- a/tests/testthat/test-test_dir.R +++ b/tests/testthat/test-test_dir.R @@ -12,7 +12,7 @@ test_that("test_dir()", { res <- test_dir(test_path("test_dir"), reporter = "silent") df <- as.data.frame(res) - df$user <- df$system <- df$real <- NULL + df$user <- df$system <- df$real <- NULL expect_known_value(df, "test_dir.rds") }) @@ -20,7 +20,7 @@ test_that("test_dir()", { test_that("test_dir() filter", { res <- test_dir("test_dir", reporter = "silent", filter = "basic|empty") df <- as.data.frame(res) - expect_identical(unique(df$context), c("Basic", "empty")) + expect_identical(unique(df$context), c("Basic", "empty")) }) test_that("test_dir() helpers", { diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index 4a53649fa..cc8a11bd4 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -27,8 +27,10 @@ test_that("compare state works correctly", { expect_that(basename(diff$deleted), equals("test-1.txt")) expect_that(basename(diff$added), equals("test-2.txt")) - diff <- compare_state(c(file1 = "62da2", file2 = "e14a6", file3 = "6e6dd"), - c(file1 = "62da2", file2 = "e14a6", file21 = "532fa", file3 = "3f4sa")) + diff <- compare_state( + c(file1 = "62da2", file2 = "e14a6", file3 = "6e6dd"), + c(file1 = "62da2", file2 = "e14a6", file21 = "532fa", file3 = "3f4sa") + ) expect_that(diff$n, equals(2)) expect_that(basename(diff$added), equals("file21")) expect_that(basename(diff$modified), equals("file3")) From e24df9f3a1d3eaf703b7e9115705acf01e8baeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 25 Oct 2017 09:07:32 +0200 Subject: [PATCH 7/7] manual style tweaks --- R/expect-comparison.R | 4 ++-- R/expect-self-test.R | 4 ++-- R/expectation.R | 4 ++-- R/reporter-check.R | 4 ++-- R/reporter-debug.R | 4 ++-- R/reporter-fail.R | 4 ++-- R/reporter-junit.R | 24 ++++++++++++------------ R/reporter-list.R | 14 +++++++------- R/reporter-location.R | 4 ++-- R/reporter-minimal.R | 4 ++-- R/reporter-multi.R | 4 ++-- R/reporter-progress.R | 4 ++-- R/reporter-rstudio.R | 4 ++-- R/reporter-silent.R | 4 ++-- R/reporter-stop.R | 4 ++-- R/reporter-summary.R | 4 ++-- R/reporter-tap.R | 4 ++-- R/reporter-teamcity.R | 4 ++-- R/reporter.R | 3 +-- R/skip.R | 6 +++--- R/stack.R | 6 +++--- R/test-that.R | 10 +++++----- tests/testthat/helper-junitmock.R | 5 ++--- tests/testthat/test-context.R | 4 ++-- tests/testthat/test-reporter.R | 10 +++++----- tests/testthat/test-test-that.R | 28 ++++++++++++++-------------- 26 files changed, 86 insertions(+), 88 deletions(-) diff --git a/R/expect-comparison.R b/R/expect-comparison.R index 4fd1ae0ad..dec6fb942 100644 --- a/R/expect-comparison.R +++ b/R/expect-comparison.R @@ -28,9 +28,9 @@ expect_compare <- function(operator = c("<", "<=", ">", ">="), act, exp) { stopifnot(is.numeric(exp$val), length(exp$val) == 1) msg <- c( - "<" = "not strictly less than", + "<" = "not strictly less than", "<=" = "not less than", - ">" = "not strictly more than", + ">" = "not strictly more than", ">=" = "not more than" )[[operator]] diff --git a/R/expect-self-test.R b/R/expect-self-test.R index d0d881521..b6806bbe8 100644 --- a/R/expect-self-test.R +++ b/R/expect-self-test.R @@ -67,8 +67,8 @@ show_failure <- function(expr) { #' @rdname expect_success #' @param path Path to save failure output expect_known_failure <- function(path, expr) { - FailureReporter <- R6::R6Class( - "FailureReporter", inherit = CheckReporter, + FailureReporter <- R6::R6Class("FailureReporter", + inherit = CheckReporter, public = list(end_reporter = function(...) {}) ) diff --git a/R/expectation.R b/R/expectation.R index cda80ad85..6dfd50463 100644 --- a/R/expectation.R +++ b/R/expectation.R @@ -236,9 +236,9 @@ format.expectation <- function(x, ...) { single_letter_summary <- function(x) { switch(expectation_type(x), - skip = colourise("S", "skip"), + skip = colourise("S", "skip"), success = colourise(".", "success"), - error = colourise("E", "error"), + error = colourise("E", "error"), failure = colourise("F", "failure"), warning = colourise("W", "warning"), "?" diff --git a/R/reporter-check.R b/R/reporter-check.R index 763907c5a..c3aa21718 100644 --- a/R/reporter-check.R +++ b/R/reporter-check.R @@ -8,8 +8,8 @@ NULL #' #' @export #' @family reporters -CheckReporter <- R6::R6Class( - "CheckReporter", inherit = Reporter, +CheckReporter <- R6::R6Class("CheckReporter", + inherit = Reporter, public = list( failures = list(), n_ok = 0L, diff --git a/R/reporter-debug.R b/R/reporter-debug.R index d26722315..117e703a0 100644 --- a/R/reporter-debug.R +++ b/R/reporter-debug.R @@ -8,8 +8,8 @@ NULL #' #' @export #' @family reporters -DebugReporter <- R6::R6Class( - "DebugReporter", inherit = Reporter, +DebugReporter <- R6::R6Class("DebugReporter", + inherit = Reporter, public = list( add_result = function(context, test, result) { if (!expectation_success(result)) { diff --git a/R/reporter-fail.R b/R/reporter-fail.R index 7807e3759..7770dc677 100644 --- a/R/reporter-fail.R +++ b/R/reporter-fail.R @@ -9,8 +9,8 @@ NULL #' #' @export #' @family reporters -FailReporter <- R6::R6Class( - "FailReporter", inherit = Reporter, +FailReporter <- R6::R6Class("FailReporter", + inherit = Reporter, public = list( failed = FALSE, diff --git a/R/reporter-junit.R b/R/reporter-junit.R index 0a77b235f..e6fab0991 100644 --- a/R/reporter-junit.R +++ b/R/reporter-junit.R @@ -26,18 +26,18 @@ classnameOK <- function(text) { #' \url{http://llg.cubic.org/docs/junit/} #' #' @export -JunitReporter <- R6::R6Class( - "JunitReporter", inherit = Reporter, +JunitReporter <- R6::R6Class("JunitReporter", + inherit = Reporter, public = list( - results = NULL, - timer = NULL, - doc = NULL, - errors = NULL, + results = NULL, + timer = NULL, + doc = NULL, + errors = NULL, failures = NULL, - skipped = NULL, - tests = NULL, - root = NULL, - suite = NULL, + skipped = NULL, + tests = NULL, + root = NULL, + suite = NULL, suite_time = NULL, elapsed_time = function() { @@ -69,9 +69,9 @@ JunitReporter <- R6::R6Class( self$suite <- xml2::xml_add_child( self$root, "testsuite", - name = context, + name = context, timestamp = private$timestamp(), - hostname = private$hostname() + hostname = private$hostname() ) }, diff --git a/R/reporter-list.R b/R/reporter-list.R index 84fa49a16..dc5f3e7ec 100644 --- a/R/reporter-list.R +++ b/R/reporter-list.R @@ -12,8 +12,8 @@ methods::setOldClass("proc_time") #' #' @export #' @family reporters -ListReporter <- R6::R6Class( - "ListReporter", inherit = Reporter, +ListReporter <- R6::R6Class("ListReporter", + inherit = Reporter, public = list( current_start_time = NA, current_expectations = NULL, @@ -40,12 +40,12 @@ ListReporter <- R6::R6Class( elapsed <- as.double(proc.time() - self$current_start_time) self$results$push(list( - file = self$current_file %||% NA_character_, + file = self$current_file %||% NA_character_, context = context, - test = test, - user = elapsed[1], - system = elapsed[2], - real = elapsed[3], + test = test, + user = elapsed[1], + system = elapsed[2], + real = elapsed[3], results = self$current_expectations$as_list() )) }, diff --git a/R/reporter-location.R b/R/reporter-location.R index 50115d237..df99f5f25 100644 --- a/R/reporter-location.R +++ b/R/reporter-location.R @@ -9,8 +9,8 @@ NULL #' #' @export #' @family reporters -LocationReporter <- R6::R6Class( - "LocationReporter", inherit = Reporter, +LocationReporter <- R6::R6Class("LocationReporter", + inherit = Reporter, public = list( start_test = function(context, test) { self$cat_line("Start test: ", test) diff --git a/R/reporter-minimal.R b/R/reporter-minimal.R index def3ce28d..d56716148 100644 --- a/R/reporter-minimal.R +++ b/R/reporter-minimal.R @@ -10,8 +10,8 @@ NULL #' #' @export #' @family reporters -MinimalReporter <- R6::R6Class( - "MinimalReporter", inherit = Reporter, +MinimalReporter <- R6::R6Class("MinimalReporter", + inherit = Reporter, public = list( add_result = function(context, test, result) { self$cat_tight(single_letter_summary(result)) diff --git a/R/reporter-multi.R b/R/reporter-multi.R index b7ca2e47b..9227845a4 100644 --- a/R/reporter-multi.R +++ b/R/reporter-multi.R @@ -8,8 +8,8 @@ NULL #' #' @export #' @family reporters -MultiReporter <- R6::R6Class( - "MultiReporter", inherit = Reporter, +MultiReporter <- R6::R6Class("MultiReporter", + inherit = Reporter, public = list( reporters = list(), diff --git a/R/reporter-progress.R b/R/reporter-progress.R index e38d5b91d..e0c2bcb5b 100644 --- a/R/reporter-progress.R +++ b/R/reporter-progress.R @@ -13,8 +13,8 @@ NULL #' @export #' @family reporters #' @importFrom clisymbols symbol -ProgressReporter <- R6::R6Class( - "ProgressReporter", inherit = Reporter, +ProgressReporter <- R6::R6Class("ProgressReporter", + inherit = Reporter, public = list( show_praise = TRUE, min_time = 0.1, diff --git a/R/reporter-rstudio.R b/R/reporter-rstudio.R index 77a959a00..b1869885c 100644 --- a/R/reporter-rstudio.R +++ b/R/reporter-rstudio.R @@ -8,8 +8,8 @@ NULL #' #' @export #' @family reporters -RstudioReporter <- R6::R6Class( - "RstudioReporter", inherit = Reporter, +RstudioReporter <- R6::R6Class("RstudioReporter", + inherit = Reporter, public = list( add_result = function(context, test, result) { if (expectation_success(result)) { diff --git a/R/reporter-silent.R b/R/reporter-silent.R index 778715464..b4fe9713a 100644 --- a/R/reporter-silent.R +++ b/R/reporter-silent.R @@ -10,8 +10,8 @@ NULL #' #' @export #' @family reporters -SilentReporter <- R6::R6Class( - "SilentReporter", inherit = Reporter, +SilentReporter <- R6::R6Class("SilentReporter", + inherit = Reporter, public = list( .expectations = NULL, diff --git a/R/reporter-stop.R b/R/reporter-stop.R index 1b39264ba..34f658f43 100644 --- a/R/reporter-stop.R +++ b/R/reporter-stop.R @@ -13,8 +13,8 @@ NULL #' #' @export #' @family reporters -StopReporter <- R6::R6Class( - "StopReporter", inherit = Reporter, +StopReporter <- R6::R6Class("StopReporter", + inherit = Reporter, public = list( failures = NULL, diff --git a/R/reporter-summary.R b/R/reporter-summary.R index 3bc2956a6..b591d9b2e 100644 --- a/R/reporter-summary.R +++ b/R/reporter-summary.R @@ -16,8 +16,8 @@ NULL #' #' @export #' @family reporters -SummaryReporter <- R6::R6Class( - "SummaryReporter", inherit = Reporter, +SummaryReporter <- R6::R6Class("SummaryReporter", + inherit = Reporter, public = list( failures = NULL, skips = NULL, diff --git a/R/reporter-tap.R b/R/reporter-tap.R index 3e4e5cd9a..37557b51b 100644 --- a/R/reporter-tap.R +++ b/R/reporter-tap.R @@ -9,8 +9,8 @@ NULL #' #' @export #' @family reporters -TapReporter <- R6::R6Class( - "TapReporter", inherit = Reporter, +TapReporter <- R6::R6Class("TapReporter", + inherit = Reporter, public = list( results = list(), n = 0L, diff --git a/R/reporter-teamcity.R b/R/reporter-teamcity.R index 1220fb7d0..3d1180b11 100644 --- a/R/reporter-teamcity.R +++ b/R/reporter-teamcity.R @@ -9,8 +9,8 @@ NULL #' #' @export #' @family reporters -TeamcityReporter <- R6::R6Class( - "TeamcityReporter", inherit = Reporter, +TeamcityReporter <- R6::R6Class("TeamcityReporter", + inherit = Reporter, public = list( i = NA_integer_, diff --git a/R/reporter.R b/R/reporter.R index fec86f092..6293e4616 100644 --- a/R/reporter.R +++ b/R/reporter.R @@ -8,8 +8,7 @@ #' @export Reporter #' @aliases Reporter #' @importFrom R6 R6Class -Reporter <- R6::R6Class( - "Reporter", +Reporter <- R6::R6Class("Reporter", public = list( start_reporter = function() {}, start_context = function(context) {}, diff --git a/R/skip.R b/R/skip.R index 00f49c799..0392dde4a 100644 --- a/R/skip.R +++ b/R/skip.R @@ -121,9 +121,9 @@ skip_on_os <- function(os) { switch(sysname, windows = if ("windows" %in% os) skip("On windows"), - darwin = if ("mac" %in% os) skip("On Mac"), - linux = if ("linux" %in% os) skip("On Linux"), - sunos = if ("solaris" %in% os) skip("On Solaris") + darwin = if ("mac" %in% os) skip("On Mac"), + linux = if ("linux" %in% os) skip("On Linux"), + sunos = if ("solaris" %in% os) skip("On Solaris") ) invisible(TRUE) diff --git a/R/stack.R b/R/stack.R index b94662e89..920521f03 100644 --- a/R/stack.R +++ b/R/stack.R @@ -42,8 +42,8 @@ Stack <- R6Class( ), private = list( - stack = NULL, # A list that holds the items - count = 0L, # Current number of items in the stack - init = 20L # Initial and minimum size of the stack + stack = NULL, # A list that holds the items + count = 0L, # Current number of items in the stack + init = 20L # Initial and minimum size of the stack ) ) diff --git a/R/test-that.R b/R/test-that.R index 0bebcdb98..94332592b 100644 --- a/R/test-that.R +++ b/R/test-that.R @@ -155,15 +155,15 @@ test_code <- function(test, code, env = test_env(), skip_on_empty = TRUE) { } }, expectation = handle_expectation, - skip = handle_skip, - warning = handle_warning, - message = handle_message, - error = handle_error + skip = handle_skip, + warning = handle_warning, + message = handle_message, + error = handle_error ), # some errors may need handling here, e.g., stack overflow error = handle_fatal, # skip silently terminate code - skip = function(e) {} + skip = function(e) {} ) diff --git a/tests/testthat/helper-junitmock.R b/tests/testthat/helper-junitmock.R index 3a82738dc..628840dc9 100644 --- a/tests/testthat/helper-junitmock.R +++ b/tests/testthat/helper-junitmock.R @@ -7,10 +7,9 @@ # - hostname - originally wrapper for Sys.info()[["nodename"]] # createJunitReporterMock <- function(...) { - JunitReporterMock <- R6::R6Class( - "JunitReporterMock", + JunitReporterMock <- R6::R6Class("JunitReporterMock", inherit = JunitReporter, - public = list(), + public = list(), private = list( proctime = function() { c(user = 0, system = 0, elapsed = 0) diff --git a/tests/testthat/test-context.R b/tests/testthat/test-context.R index fb000a515..a88d3298b 100644 --- a/tests/testthat/test-context.R +++ b/tests/testthat/test-context.R @@ -1,7 +1,7 @@ context("Contexts") -CountReporter <- R6::R6Class( - "CountReporter", inherit = Reporter, +CountReporter <- R6::R6Class("CountReporter", + inherit = Reporter, public = list( context_i = 0, context_count = 0, diff --git a/tests/testthat/test-reporter.R b/tests/testthat/test-reporter.R index 685e5ae1f..f9533b3e6 100644 --- a/tests/testthat/test-reporter.R +++ b/tests/testthat/test-reporter.R @@ -3,11 +3,11 @@ context("Reporter") test_that("can locate reporter from name", { expect_that(find_reporter("minimal"), equals(MinimalReporter$new())) expect_that(find_reporter("summary"), equals(SummaryReporter$new())) - expect_that(find_reporter("tap"), equals(TapReporter$new())) - expect_that(find_reporter("list"), equals(ListReporter$new())) - expect_that(find_reporter("multi"), equals(MultiReporter$new())) - expect_that(find_reporter("junit"), equals(JunitReporter$new())) - expect_that(find_reporter(""), equals(Reporter$new())) + expect_that(find_reporter("tap"), equals(TapReporter$new())) + expect_that(find_reporter("list"), equals(ListReporter$new())) + expect_that(find_reporter("multi"), equals(MultiReporter$new())) + expect_that(find_reporter("junit"), equals(JunitReporter$new())) + expect_that(find_reporter(""), equals(Reporter$new())) }) test_that("useful error message if can't find reporter", { diff --git a/tests/testthat/test-test-that.R b/tests/testthat/test-test-that.R index f7f5e1cb3..1b4badc49 100644 --- a/tests/testthat/test-test-that.R +++ b/tests/testthat/test-test-that.R @@ -89,18 +89,18 @@ expectation_lines <- function(code) { test_that("line numbers captured in simple case", { lines <- expectation_lines({ - context("testing testFile") # line 1 - test_that("simple", { # line 2 - expect_true(FALSE) # line 3 - }) # line 4 + context("testing testFile") # line 1 + test_that("simple", { # line 2 + expect_true(FALSE) # line 3 + }) # line 4 }) expect_equal(lines, 3) }) test_that("line numbers captured inside another function", { lines <- expectation_lines({ - test_that("simple", { # line 1 - suppressMessages(expect_true(FALSE)) # line 2 + test_that("simple", { # line 1 + suppressMessages(expect_true(FALSE)) # line 2 }) }) expect_equal(lines, 2) @@ -108,8 +108,8 @@ test_that("line numbers captured inside another function", { test_that("line numbers captured inside a loop", { lines <- expectation_lines({ - test_that("simple", { # line 1 - for (i in 1:4) expect_true(TRUE) # line 2 + test_that("simple", { # line 1 + for (i in 1:4) expect_true(TRUE) # line 2 }) }) expect_equal(lines, rep(2, 4)) @@ -117,18 +117,18 @@ test_that("line numbers captured inside a loop", { test_that("line numbers captured for skip()s", { lines <- expectation_lines({ - test_that("simple", { # line 1 - skip("Not this time") # line 2 - }) # line 3 + test_that("simple", { # line 1 + skip("Not this time") # line 2 + }) # line 3 }) expect_equal(lines, 2) }) test_that("line numbers captured for stop()s", { lines <- expectation_lines({ - test_that("simple", { # line 1 - skip("Not this time") # line 2 - }) # line 3 + test_that("simple", { # line 1 + skip("Not this time") # line 2 + }) # line 3 }) expect_equal(lines, 2) })