diff --git a/R/expect-equality.R b/R/expect-equality.R index 31a668a6e..619b0efcf 100644 --- a/R/expect-equality.R +++ b/R/expect-equality.R @@ -136,12 +136,10 @@ expect_waldo_equal_ <- function( ) if (length(comp) != 0) { msg <- sprintf( - "%s (%s) is not %s to %s (%s).\n\n%s", + "%s is not %s to %s.\n\n%s", act$lab, - "`actual`", type, exp$lab, - "`expected`", paste0(comp, collapse = "\n\n") ) return(fail(msg, info = info, trace_env = trace_env)) diff --git a/R/expect-setequal.R b/R/expect-setequal.R index 2b42b78d7..340798015 100644 --- a/R/expect-setequal.R +++ b/R/expect-setequal.R @@ -41,9 +41,9 @@ expect_setequal <- function(object, expected) { if (length(exp_miss) || length(act_miss)) { return(fail(paste0( act$lab, - " (`actual`) and ", + " doesn't have the same values as ", exp$lab, - " (`expected`) don't have the same values.\n", + ".\n", if (length(act_miss)) { paste0("* Only in `actual`: ", values(act_miss), "\n") }, @@ -138,11 +138,11 @@ expect_contains <- function(object, expected) { if (any(exp_miss)) { return(fail(paste0( act$lab, - " (`actual`) doesn't fully contain all the values in ", + " doesn't fully contain all the values in ", exp$lab, - " (`expected`).\n", - paste0("* Missing from `actual`: ", values(exp$val[exp_miss]), "\n"), - paste0("* Present in `actual`: ", values(act$val), "\n") + ".\n", + paste0("* Missing from ", act$lab, ": ", values(exp$val[exp_miss]), "\n"), + paste0("* Present in ", act$lab, ": ", values(act$val), "\n") ))) } @@ -164,11 +164,11 @@ expect_in <- function(object, expected) { if (any(act_miss)) { return(fail(paste0( act$lab, - " (`actual`) isn't fully contained within ", + " isn't fully contained within ", exp$lab, - " (`expected`).\n", - paste0("* Missing from `expected`: ", values(act$val[act_miss]), "\n"), - paste0("* Present in `expected`: ", values(exp$val), "\n") + ".\n", + paste0("* Missing from ", act$lab, ": ", values(act$val[act_miss]), "\n"), + paste0("* Present in ", act$lab, ": ", values(exp$val), "\n") ))) } diff --git a/R/quasi-label.R b/R/quasi-label.R index c869381af..0af6ce4fa 100644 --- a/R/quasi-label.R +++ b/R/quasi-label.R @@ -41,11 +41,10 @@ quasi_label <- function(quo, label = NULL, arg = "quo") { } expr <- quo_get_expr(quo) + value <- eval_bare(expr, quo_get_env(quo)) + label <- label %||% auto_label(expr, value) - labelled_value( - eval_bare(expr, quo_get_env(quo)), - label %||% expr_label(expr) - ) + labelled_value(value, label) } labelled_value <- function(value, label) { @@ -66,6 +65,39 @@ quasi_capture <- function(.quo, .label, .capture, ...) { act } +auto_label <- function(expr, value) { + if (is.call(expr) || is.name(expr)) { + label <- expr_label(expr) + if (can_inline(value)) { + paste0(label, " (", as_label(value), ")") + } else { + label + } + } else { + expr_label(expr) + } +} + +can_inline <- function(x) { + if (is.null(x)) { + return(TRUE) + } + if (!is.atomic(x) || !is.vector(x)) { + return(FALSE) + } + if (length(x) != 1) { + return(FALSE) + } + + if (is.character(x)) { + is.na(x) || (!grepl("\n", x) && nchar(x) < 100) + } else if (is.logical(x) || is.numeric(x)) { + TRUE + } else { + FALSE + } +} + expr_label <- function(x) { if (is_syntactic_literal(x)) { deparse1(x) diff --git a/tests/testthat/_snaps/expect-constant.md b/tests/testthat/_snaps/expect-constant.md index 2347c401a..f36c4ce49 100644 --- a/tests/testthat/_snaps/expect-constant.md +++ b/tests/testthat/_snaps/expect-constant.md @@ -1,34 +1,34 @@ # logical tests act as expected - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE --- - TRUE (`actual`) is not equal to FALSE (`expected`). + TRUE is not equal to FALSE. `actual`: TRUE `expected`: FALSE # can compare non-vectors - quote(x) (`actual`) is not equal to TRUE (`expected`). + quote(x) is not equal to TRUE. `actual` is a symbol `expected` is a logical vector (TRUE) # expect_null works - 1L (`actual`) is not equal to FALSE (`expected`). + 1L is not equal to FALSE. `actual` is an integer vector (1) `expected` is NULL --- - environment() (`actual`) is not equal to FALSE (`expected`). + environment() is not equal to FALSE. `actual` is an environment `expected` is NULL diff --git a/tests/testthat/_snaps/expect-equality.md b/tests/testthat/_snaps/expect-equality.md index 0aac96e6c..98c42e34a 100644 --- a/tests/testthat/_snaps/expect-equality.md +++ b/tests/testthat/_snaps/expect-equality.md @@ -1,24 +1,24 @@ # provide useful feedback on failure - 1 (`actual`) is not identical to "a" (`expected`). + `x` (1) is not identical to "a". `actual` is a double vector (1) `expected` is a character vector ('a') --- - 1 (`actual`) is not equal to "a" (`expected`). + `x` (1) is not equal to "a". `actual` is a double vector (1) `expected` is a character vector ('a') --- - 1 not identical to "a". + `x` (1) not identical to "a". Types not compatible: double is not character --- - 1 not equal to "a". + `x` (1) not equal to "a". Types not compatible: double is not character diff --git a/tests/testthat/_snaps/expect-match.md b/tests/testthat/_snaps/expect-match.md index 07b6533a4..919f78c56 100644 --- a/tests/testthat/_snaps/expect-match.md +++ b/tests/testthat/_snaps/expect-match.md @@ -4,7 +4,7 @@ --- - `one` does not match regexp "asdf". + `one` ("bcde") does not match regexp "asdf". Text: "bcde" --- @@ -47,11 +47,11 @@ # expect_no_match works - `x` matches string "e*". + `x` ("te*st") matches string "e*". Text: "te*st" --- - `x` matches regexp "TEST". + `x` ("test") matches regexp "TEST". Text: "test" diff --git a/tests/testthat/_snaps/expect-self-test.md b/tests/testthat/_snaps/expect-self-test.md index 3f754c2bc..0cbb3709d 100644 --- a/tests/testthat/_snaps/expect-self-test.md +++ b/tests/testthat/_snaps/expect-self-test.md @@ -17,7 +17,7 @@ show_failure(expect_true(FALSE)) Output Failed expectation: - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/expect-setequal.md b/tests/testthat/_snaps/expect-setequal.md index 87ccd0fe9..1106047bb 100644 --- a/tests/testthat/_snaps/expect-setequal.md +++ b/tests/testthat/_snaps/expect-setequal.md @@ -1,67 +1,73 @@ # useful message on failure - "actual" (`actual`) and "expected" (`expected`) don't have the same values. + "actual" doesn't have the same values as "expected". * Only in `actual`: "actual" * Only in `expected`: "expected" --- - 1:2 (`actual`) and 2 (`expected`) don't have the same values. + `x` doesn't have the same values as `y` (2). * Only in `actual`: 1 --- - 2 (`actual`) and 2:3 (`expected`) don't have the same values. + `x` (2) doesn't have the same values as `y`. * Only in `expected`: 3 --- - 1:2 (`actual`) and 2:3 (`expected`) don't have the same values. + `x` doesn't have the same values as `y`. * Only in `actual`: 1 * Only in `expected`: 3 --- - c("a", "a") (`actual`) and c("b", "b", "b") (`expected`) don't have the same values. + `x` doesn't have the same values as `y`. * Only in `actual`: "a" * Only in `expected`: "b" +--- + + `x` doesn't have the same values as c("a", "b", "c", "d"). + * Only in `expected`: "d" + + # truncates long vectors - 1:2 (`actual`) and 1:50 (`expected`) don't have the same values. + `x` doesn't have the same values as `y`. * Only in `expected`: 3, 4, 5, 6, 7, 8, 9, 10, 11, ... # expect_contains() gives useful message on failure - `x1` (`actual`) doesn't fully contain all the values in `x2` (`expected`). - * Missing from `actual`: "d" - * Present in `actual`: "a", "b", "c" + `x1` doesn't fully contain all the values in `x2`. + * Missing from `x1`: "d" + * Present in `x1`: "a", "b", "c" --- - `x1` (`actual`) doesn't fully contain all the values in `x3` (`expected`). - * Missing from `actual`: "d", "e" - * Present in `actual`: "a", "b", "c" + `x1` doesn't fully contain all the values in `x3`. + * Missing from `x1`: "d", "e" + * Present in `x1`: "a", "b", "c" # expect_in() gives useful message on failure - `x1` (`actual`) isn't fully contained within `x2` (`expected`). - * Missing from `expected`: "a" - * Present in `expected`: "b", "c" + `x1` isn't fully contained within `x2`. + * Missing from `x1`: "a" + * Present in `x1`: "b", "c" --- - `x1` (`actual`) isn't fully contained within `x3` (`expected`). - * Missing from `expected`: "a", "b" - * Present in `expected`: "d", "e" + `x1` isn't fully contained within `x3`. + * Missing from `x1`: "a", "b" + * Present in `x1`: "d", "e" diff --git a/tests/testthat/_snaps/reporter-check.md b/tests/testthat/_snaps/reporter-check.md index a0198f5ce..3e77908d7 100644 --- a/tests/testthat/_snaps/reporter-check.md +++ b/tests/testthat/_snaps/reporter-check.md @@ -15,12 +15,12 @@ == Failed tests ================================================================ -- Failure ('reporters/tests.R:12:3'): Failure:1 ------------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- Failure ('reporters/tests.R:16:8'): Failure:2a ------------------------------ - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -71,12 +71,12 @@ == Failed tests ================================================================ -- Failure ('reporters/tests.R:12:3'): Failure:1 ------------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- Failure ('reporters/tests.R:16:8'): Failure:2a ------------------------------ - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/reporter-junit.md b/tests/testthat/_snaps/reporter-junit.md index e0f33ceba..75cbeae9b 100644 --- a/tests/testthat/_snaps/reporter-junit.md +++ b/tests/testthat/_snaps/reporter-junit.md @@ -7,13 +7,13 @@ - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/reporter-progress.md b/tests/testthat/_snaps/reporter-progress.md index fd616f0fb..7be14a264 100644 --- a/tests/testthat/_snaps/reporter-progress.md +++ b/tests/testthat/_snaps/reporter-progress.md @@ -66,67 +66,67 @@ x | 11 0 | reporters/fail-many -------------------------------------------------------------------------------- Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -137,67 +137,67 @@ == Results ===================================================================== -- Failed tests ---------------------------------------------------------------- Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE Failure ('reporters/fail-many.R:3:5'): Example - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -268,25 +268,22 @@ x 1. +-testthat::expect_s3_class(foo(), "foo") 2. | \-testthat::quasi_label(enquo(object), arg = "object") - 3. | +-testthat:::labelled_value(...) - 4. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 5. \-foo() + 3. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 4. \-foo() Error ('reporters/backtraces.R:13:10'): errors thrown from a quasi-labelled argument are entraced (deep case) Error in `foo()`: foo Backtrace: - x - 1. +-testthat::expect_s3_class(f(), "foo") - 2. | \-testthat::quasi_label(enquo(object), arg = "object") - 3. | +-testthat:::labelled_value(...) - 4. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 5. \-f() - 6. \-g() - 7. +-testthat::expect_s3_class(foo(), "foo") - 8. | \-testthat::quasi_label(enquo(object), arg = "object") - 9. | +-testthat:::labelled_value(...) - 10. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 11. \-foo() + x + 1. +-testthat::expect_s3_class(f(), "foo") + 2. | \-testthat::quasi_label(enquo(object), arg = "object") + 3. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 4. \-f() + 5. \-g() + 6. +-testthat::expect_s3_class(foo(), "foo") + 7. | \-testthat::quasi_label(enquo(object), arg = "object") + 8. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 9. \-foo() Error ('reporters/backtraces.R:21:10'): errors thrown from a quasi-labelled argument are entraced (deep deep case) Error in `bar()`: foobar @@ -296,10 +293,9 @@ 2. \-g() 3. +-testthat::expect_s3_class(foo(), "foo") 4. | \-testthat::quasi_label(enquo(object), arg = "object") - 5. | +-testthat:::labelled_value(...) - 6. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 7. \-foo() - 8. \-bar() + 5. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 6. \-foo() + 7. \-bar() Error ('reporters/backtraces.R:32:16'): failed expect_error() prints a backtrace Error in `signaller()`: bar @@ -360,7 +356,7 @@ 26. \-f(x - 1) Failure ('reporters/backtraces.R:62:6'): (code run outside of `test_that()`) - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -372,7 +368,7 @@ 4. \-testthat::expect_true(FALSE) Failure ('reporters/backtraces.R:67:3'): nested expectations get backtraces - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -399,25 +395,22 @@ x 1. +-testthat::expect_s3_class(foo(), "foo") 2. | \-testthat::quasi_label(enquo(object), arg = "object") - 3. | +-testthat:::labelled_value(...) - 4. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 5. \-foo() + 3. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 4. \-foo() Error ('reporters/backtraces.R:13:10'): errors thrown from a quasi-labelled argument are entraced (deep case) Error in `foo()`: foo Backtrace: - x - 1. +-testthat::expect_s3_class(f(), "foo") - 2. | \-testthat::quasi_label(enquo(object), arg = "object") - 3. | +-testthat:::labelled_value(...) - 4. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 5. \-f() - 6. \-g() - 7. +-testthat::expect_s3_class(foo(), "foo") - 8. | \-testthat::quasi_label(enquo(object), arg = "object") - 9. | +-testthat:::labelled_value(...) - 10. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 11. \-foo() + x + 1. +-testthat::expect_s3_class(f(), "foo") + 2. | \-testthat::quasi_label(enquo(object), arg = "object") + 3. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 4. \-f() + 5. \-g() + 6. +-testthat::expect_s3_class(foo(), "foo") + 7. | \-testthat::quasi_label(enquo(object), arg = "object") + 8. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 9. \-foo() Error ('reporters/backtraces.R:21:10'): errors thrown from a quasi-labelled argument are entraced (deep deep case) Error in `bar()`: foobar @@ -427,10 +420,9 @@ 2. \-g() 3. +-testthat::expect_s3_class(foo(), "foo") 4. | \-testthat::quasi_label(enquo(object), arg = "object") - 5. | +-testthat:::labelled_value(...) - 6. | \-rlang::eval_bare(expr, quo_get_env(quo)) - 7. \-foo() - 8. \-bar() + 5. | \-rlang::eval_bare(expr, quo_get_env(quo)) + 6. \-foo() + 7. \-bar() Error ('reporters/backtraces.R:32:16'): failed expect_error() prints a backtrace Error in `signaller()`: bar @@ -484,7 +476,7 @@ 26. \-f(x - 1) Failure ('reporters/backtraces.R:62:6'): (code run outside of `test_that()`) - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -496,7 +488,7 @@ 4. \-testthat::expect_true(FALSE) Failure ('reporters/backtraces.R:67:3'): nested expectations get backtraces - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -542,13 +534,13 @@ [ FAIL 2 | WARN 0 | SKIP 0 | PASS 1 ] -- Failure ('reporters/tests.R:12:3'): Failure:1 ------------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- Failure ('reporters/tests.R:16:8'): Failure:2a ------------------------------ - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/reporter-rstudio.md b/tests/testthat/_snaps/reporter-rstudio.md index 4c96a13b9..09a1440e3 100644 --- a/tests/testthat/_snaps/reporter-rstudio.md +++ b/tests/testthat/_snaps/reporter-rstudio.md @@ -1,7 +1,7 @@ # reporter basics works - 'reporters/tests.R:12:3' [failure] Failure:1. FALSE (`actual`) is not equal to TRUE (`expected`). - 'reporters/tests.R:16:8' [failure] Failure:2a. FALSE (`actual`) is not equal to TRUE (`expected`). + 'reporters/tests.R:12:3' [failure] Failure:1. FALSE is not equal to TRUE. + 'reporters/tests.R:16:8' [failure] Failure:2a. FALSE is not equal to TRUE. 'reporters/tests.R:23:3' [error] Error:1. Error in `eval(code, test_env)`: stop 'reporters/tests.R:29:8' [error] errors get tracebacks. Error in `h()`: ! 'reporters/tests.R:37:3' [skip] explicit skips are reported. Reason: skip diff --git a/tests/testthat/_snaps/reporter-stop.md b/tests/testthat/_snaps/reporter-stop.md index c57c94761..4f3544b80 100644 --- a/tests/testthat/_snaps/reporter-stop.md +++ b/tests/testthat/_snaps/reporter-stop.md @@ -2,13 +2,13 @@ Test passed -- Failure ('reporters/tests.R:12:3'): Failure:1 ------------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- Failure ('reporters/tests.R:16:8'): Failure:2a ------------------------------ - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/reporter-summary.md b/tests/testthat/_snaps/reporter-summary.md index 30b0bc59b..d4234adf4 100644 --- a/tests/testthat/_snaps/reporter-summary.md +++ b/tests/testthat/_snaps/reporter-summary.md @@ -19,13 +19,13 @@ == Failed ====================================================================== -- 1. Failure ('reporters/tests.R:12:3'): Failure:1 ---------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- 2. Failure ('reporters/tests.R:16:8'): Failure:2a --------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -68,13 +68,13 @@ == Failed ====================================================================== -- 1. Failure ('reporters/tests.R:12:3'): Failure:1 ---------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- 2. Failure ('reporters/tests.R:16:8'): Failure:2a --------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE @@ -117,13 +117,13 @@ == Failed ====================================================================== -- 1. Failure ('reporters/tests.R:12:3'): Failure:1 ---------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE -- 2. Failure ('reporters/tests.R:16:8'): Failure:2a --------------------------- - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/reporter-tap.md b/tests/testthat/_snaps/reporter-tap.md index 3ae84629f..1eaa4a848 100644 --- a/tests/testthat/_snaps/reporter-tap.md +++ b/tests/testthat/_snaps/reporter-tap.md @@ -5,12 +5,12 @@ ok 1 Success # Context Failures not ok 2 Failure:1 - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE not ok 3 Failure:2a - FALSE (`actual`) is not equal to TRUE (`expected`). + FALSE is not equal to TRUE. `actual`: FALSE `expected`: TRUE diff --git a/tests/testthat/_snaps/reporter-teamcity.md b/tests/testthat/_snaps/reporter-teamcity.md index 0fbc5ce4c..f7239bf64 100644 --- a/tests/testthat/_snaps/reporter-teamcity.md +++ b/tests/testthat/_snaps/reporter-teamcity.md @@ -12,13 +12,13 @@ ##teamcity[testSuiteStarted name='Failures'] ##teamcity[testSuiteStarted name='Failure:1'] ##teamcity[testStarted name='expectation 1'] - ##teamcity[testFailed name='expectation 1' message='FALSE (`actual`) is not equal to TRUE (`expected`).' details='|n`actual`: FALSE|n`expected`: TRUE '] + ##teamcity[testFailed name='expectation 1' message='FALSE is not equal to TRUE.' details='|n`actual`: FALSE|n`expected`: TRUE '] ##teamcity[testFinished name='expectation 1'] ##teamcity[testSuiteFinished name='Failure:1'] ##teamcity[testSuiteStarted name='Failure:2a'] ##teamcity[testStarted name='expectation 1'] - ##teamcity[testFailed name='expectation 1' message='FALSE (`actual`) is not equal to TRUE (`expected`).' details='|n`actual`: FALSE|n`expected`: TRUE |nBacktrace:|n x|n 1. \-f()|n 2. \-testthat::expect_true(FALSE)'] + ##teamcity[testFailed name='expectation 1' message='FALSE is not equal to TRUE.' details='|n`actual`: FALSE|n`expected`: TRUE |nBacktrace:|n x|n 1. \-f()|n 2. \-testthat::expect_true(FALSE)'] ##teamcity[testFinished name='expectation 1'] ##teamcity[testSuiteFinished name='Failure:2a'] diff --git a/tests/testthat/test-expect-equality.R b/tests/testthat/test-expect-equality.R index 2176a0b4b..a21914e27 100644 --- a/tests/testthat/test-expect-equality.R +++ b/tests/testthat/test-expect-equality.R @@ -65,13 +65,14 @@ test_that("provide useful feedback on failure", { local_output_override() local_edition(3) - expect_snapshot_error(expect_identical(1, "a")) - expect_snapshot_error(expect_equal(1, "a")) + x <- 1 + expect_snapshot_failure(expect_identical(x, "a")) + expect_snapshot_failure(expect_equal(x, "a")) local_edition(2) withr::local_options(testthat.edition_ignore = TRUE) - expect_snapshot_error(expect_identical(1, "a")) - expect_snapshot_error(expect_equal(1, "a")) + expect_snapshot_failure(expect_identical(x, "a")) + expect_snapshot_failure(expect_equal(x, "a")) }) test_that("default labels use unquoting", { diff --git a/tests/testthat/test-expect-setequal.R b/tests/testthat/test-expect-setequal.R index 96c8ae569..8d6cdf91a 100644 --- a/tests/testthat/test-expect-setequal.R +++ b/tests/testthat/test-expect-setequal.R @@ -32,16 +32,32 @@ test_that("error for non-vectors", { test_that("useful message on failure", { expect_snapshot_failure(expect_setequal("actual", "expected")) - expect_snapshot_failure(expect_setequal(1:2, 2)) - expect_snapshot_failure(expect_setequal(2, 2:3)) - expect_snapshot_failure(expect_setequal(1:2, 2:3)) + x <- 1:2 + y <- 2 + expect_snapshot_failure(expect_setequal(x, y)) + + x <- 2 + y <- 2:3 + expect_snapshot_failure(expect_setequal(x, y)) + + x <- 1:2 + y <- 2:3 + expect_snapshot_failure(expect_setequal(x, y)) # doesn't repeat values - expect_snapshot_failure(expect_setequal(c("a", "a"), c("b", "b", "b"))) + x <- c("a", "a") + y <- c("b", "b", "b") + expect_snapshot_failure(expect_setequal(x, y)) + + # still looks good when expected is inlined + x <- c("a", "b", "c") + expect_snapshot_failure(expect_setequal(x, c("a", "b", "c", "d"))) }) test_that("truncates long vectors", { - expect_snapshot_failure(expect_setequal(1:2, 1:50)) + x <- 1:2 + y <- 1:50 + expect_snapshot_failure(expect_setequal(x, y)) }) # mapequal ---------------------------------------------------------------- diff --git a/tests/testthat/test-quasi-label.R b/tests/testthat/test-quasi-label.R index 2dab0f8b0..702be1445 100644 --- a/tests/testthat/test-quasi-label.R +++ b/tests/testthat/test-quasi-label.R @@ -1,3 +1,17 @@ +test_that("shows value iif simple", { + # symbols and calls shown + expect_equal(auto_label(quote(x), TRUE), "`x` (TRUE)") + expect_equal(auto_label(quote(f()), TRUE), "f() (TRUE)") + expect_equal(auto_label(quote(f()), NA_character_), "f() (NA_character_)") + # long arguments truncated + expect_equal(auto_label(call2("f", !!!letters), TRUE), "f(...) (TRUE)") + + df <- data.frame(x = 1:100) + expect_equal(auto_label(quote(f()), df), "f()") + expect_equal(auto_label(quote(f()), "x\ny"), "f()") + expect_equal(auto_label(quote(f()), strrep("x", 100)), "f()") +}) + test_that("atomic scalars deparsed to single values", { expect_equal(expr_label(NULL), "NULL") expect_equal(expr_label(TRUE), "TRUE")