Skip to content

Commit ce8a224

Browse files
committed
Don't include values in message
1 parent 788b375 commit ce8a224

27 files changed

+409
-128
lines changed

R/expect-invisible.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ expect_invisible <- function(call, label = NULL) {
2525
vis <- withVisible(call)
2626

2727
if (!identical(vis$visible, FALSE)) {
28-
msg <- sprintf(
29-
"Expected %s to return invisibly.\nActually returned visibly.",
30-
lab
28+
msg <- c(
29+
sprintf("Expected %s to return invisibly.", lab),
30+
"Actually returned visibly."
3131
)
3232
return(fail(msg))
3333
}
@@ -41,9 +41,9 @@ expect_visible <- function(call, label = NULL) {
4141
vis <- withVisible(call)
4242

4343
if (!identical(vis$visible, TRUE)) {
44-
msg <- sprintf(
45-
"Expected %s to return visibly.\nActually returned invisibly.",
46-
lab
44+
msg <- c(
45+
sprintf("Expected %s to return visibly.", lab),
46+
"Actually returned invisibly."
4747
)
4848
return(fail(msg))
4949
}

R/expect-match.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ expect_match_ <- function(
106106
info = NULL,
107107
label = NULL,
108108
negate = FALSE,
109-
title = "Text",
109+
title = "text",
110110
trace_env = caller_env()
111111
) {
112112
matches <- grepl(regexp, act$val, perl = perl, fixed = fixed, ...)
@@ -119,27 +119,27 @@ expect_match_ <- function(
119119

120120
text <- encodeString(act$val)
121121
if (length(act$val) == 1) {
122-
values <- paste0(title, ': "', text, '"')
123122
which <- ""
123+
values <- text
124124
} else {
125125
bullet <- ifelse(
126126
condition,
127127
cli::col_green(cli::symbol$tick),
128128
cli::col_red(cli::symbol$cross)
129129
)
130-
values <- paste0(title, ":\n", paste0(bullet, " ", text, collapse = "\n"))
131-
which <- if (all) "Every element of " else "Some element of "
130+
values <- paste0(bullet, " ", text, collapse = "\n")
131+
which <- if (all) "every element of " else "some element of "
132132
}
133-
match <- if (negate) "matches" else "does not match"
133+
match <- if (negate) "not to match" else "to match"
134134

135-
msg <- sprintf(
136-
"%s%s %s %s %s.\n%s",
135+
exp_msg <- sprintf(
136+
"Expected %s%s %s %s %s.",
137137
which,
138138
act$lab,
139139
match,
140140
if (fixed) "string" else "regexp",
141-
encodeString(regexp, quote = '"'),
142-
values
141+
encodeString(regexp, quote = '"')
143142
)
144-
return(fail(msg, info = info, trace_env = trace_env))
143+
act_msg <- c(paste0("Actual ", title, ':'), text)
144+
return(fail(c(exp_msg, act_msg), info = info, trace_env = trace_env))
145145
}

R/quasi-label.R

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ quasi_label <- function(quo, label = NULL, arg = NULL) {
5353

5454
expr <- quo_get_expr(quo)
5555
value <- eval_bare(expr, quo_get_env(quo))
56-
label <- label %||% auto_label(expr, value)
56+
label <- label %||% expr_label(expr)
5757

5858
labelled_value(value, label)
5959
}
@@ -76,34 +76,6 @@ quasi_capture <- function(.quo, .label, .capture, ...) {
7676
act
7777
}
7878

79-
auto_label <- function(expr, value) {
80-
if (is.call(expr) || is.name(expr)) {
81-
label <- expr_label(expr)
82-
if (can_inline(value)) {
83-
paste0(label, " (", as_label(value), ")")
84-
} else {
85-
label
86-
}
87-
} else {
88-
expr_label(expr)
89-
}
90-
}
91-
92-
can_inline <- function(x) {
93-
if (!is_syntactic_literal(x)) {
94-
return(FALSE)
95-
}
96-
if (!is.null(dim(x)) || !is.null(attributes(x))) {
97-
return(FALSE)
98-
}
99-
100-
if (is.character(x)) {
101-
is.na(x) || (!grepl("\n", x) && nchar(x) < 100)
102-
} else {
103-
TRUE
104-
}
105-
}
106-
10779
expr_label <- function(x) {
10880
if (is_syntactic_literal(x)) {
10981
deparse1(x)
@@ -128,7 +100,7 @@ expr_label <- function(x) {
128100
x <- call2(x[[1]], quote(expr = ...))
129101
}
130102
}
131-
deparse1(x)
103+
paste0("`", deparse1(x), "`")
132104
} else {
133105
# Any other object that's been inlined in
134106
x <- deparse(x)

tests/testthat/_snaps/expect-comparison.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@
1212

1313
# useful output when numbers are very small
1414

15-
Expected 1.1 * x (1.1e-05) <= `x` (1e-05).
15+
Expected `1.1 * x` <= `x`.
1616
Actual 0.0000110 > 0.0000100
1717
Difference 0.0000010 > 0
1818

1919
---
2020

21-
Expected `x` (1e-05) > 1.1 * x (1.1e-05).
21+
Expected `x` > `1.1 * x`.
2222
Actual 0.0000100 <= 0.0000110
2323
Difference -0.0000010 <= 0
2424

2525
# useful output when difference is zero
2626

27-
Expected `x` (100) < 100.
27+
Expected `x` < 100.
2828
Actual 100.0 >= 100.0
2929
Difference 0.0 >= 0
3030

3131
# useful output when differnce is large
3232

33-
Expected `x` (100) < 0.001.
33+
Expected `x` < 0.001.
3434
Actual 100.000 >= 0.001
3535
Difference 99.999 >= 0
3636

tests/testthat/_snaps/expect-constant.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
`actual` is an S3 object of class <data.frame>, a list
1313
`expected` is a logical vector (FALSE)
1414

15+
# additional info returned in message
16+
17+
Expected FALSE to be equal to TRUE.
18+
19+
`actual`: FALSE
20+
`expected`: TRUE
21+
NOPE
22+
23+
---
24+
25+
Expected TRUE to be equal to FALSE.
26+
27+
`actual`: TRUE
28+
`expected`: FALSE
29+
YUP
30+
1531
# expect_null works
1632

1733
Expected `df` to be equal to FALSE.

tests/testthat/_snaps/expect-equality.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,40 @@
3939

4040
# can control numeric tolerance
4141

42-
Expected `x1` (1) to equal `x2` (1.000001).
42+
Expected `x1` to equal `x2`.
4343
Actual:
4444
1/1 mismatches
4545
[1] 1 - 1 == -1e-06
4646

4747
---
4848

49-
Expected `x1` (1) to be equal to `x2` (1.000001).
49+
Expected `x1` to be equal to `x2`.
5050

5151
`actual`: 1.0000000
5252
`expected`: 1.0000010
5353

5454
# provide useful feedback on failure
5555

56-
Expected `x` (1) to be identical to "a".
56+
Expected `x` to be identical to "a".
5757

5858
`actual` is a double vector (1)
5959
`expected` is a character vector ('a')
6060

6161
---
6262

63-
Expected `x` (1) to be equal to "a".
63+
Expected `x` to be equal to "a".
6464

6565
`actual` is a double vector (1)
6666
`expected` is a character vector ('a')
6767

6868
---
6969

70-
Expected `x` (1) to be identical to "a".
70+
Expected `x` to be identical to "a".
7171
Types not compatible: double is not character
7272

7373
---
7474

75-
Expected `x` (1) to equal "a".
75+
Expected `x` to equal "a".
7676
Actual:
7777
Types not compatible: double is not character
7878

@@ -100,15 +100,12 @@
100100
# useful message if objects equal but not identical
101101

102102
Expected `f` to be identical to `g`.
103-
Names: 1 string mismatch
104-
Length mismatch: comparison on first 1 components
105-
Component 1: Modes of target, current: function, numeric
106-
Component 1: target, current do not match when deparsed
107-
Component 1: 'current' is not an environment
103+
names for target but not for current
104+
Length mismatch: comparison on first 0 components
108105

109106
# attributes for object (#452)
110107

111-
Expected `oops` (structure(0, oops = "oops")) to equal 0.
108+
Expected `oops` to equal 0.
112109
Actual:
113110
Attributes: < Modes: list, NULL >
114111
Attributes: < Lengths: 1, 0 >

tests/testthat/_snaps/expect-inheritance.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
# expect_is checks class
1515

16-
Expected factor("a") to inherit from `'character'`.
16+
Expected `factor("a")` to inherit from `'character'`.
1717
Actual inheritance: `'factor'`
1818

1919
# expect_s3/s4_class fails if appropriate type
2020

21-
Expected `x1` (1) to be an S3 object.
21+
Expected `x1` to be an S3 object.
2222
Actually is a base object.
2323

2424
---
@@ -33,15 +33,15 @@
3333

3434
# expect_s[34]_class can check not S3/S4
3535

36-
Expected factor() to not be an S3 object.
36+
Expected `factor()` to not be an S3 object.
3737

3838
---
3939

40-
Expected A() to not be an S4 object.
40+
Expected `A()` to not be an S4 object.
4141

4242
# test_s4_class respects class hierarchy
4343

44-
Expected C() to inherit from 'D'.
44+
Expected `C()` to inherit from 'D'.
4545
Actual class: 'C'/'A'/'B'/'list'/'vector'
4646

4747
# expect_s3_class validates its inputs
@@ -82,7 +82,7 @@
8282

8383
# expect_r6_class generates useful failures
8484

85-
Expected `x` (1) to be an R6 object.
85+
Expected `x` to be an R6 object.
8686
Actually is a base object.
8787

8888
# expect_r6_class validates its inputs
@@ -95,12 +95,12 @@
9595

9696
# can check with actual class
9797

98-
Expected Foo() to inherit from <Bar>.
98+
Expected `Foo()` to inherit from <Bar>.
9999
Actual class: <Foo>
100100

101101
---
102102

103-
Expected Baz() to inherit from <Bar>.
103+
Expected `Baz()` to inherit from <Bar>.
104104
Actual class: <Baz>/<Foo>
105105

106106
# expect_s7_class validates its inputs

tests/testthat/_snaps/expect-invisible.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
# basic principles of visibility hold
2+
3+
Expected `x` to return invisibly.
4+
Actually returned visibly.
5+
6+
---
7+
8+
Expected `x <- 1` to return visibly.
9+
Actually returned invisibly.
10+
111
# generates useful failure messages
212

3-
Expected invisible(1) to return visibly.
13+
Expected `invisible(1)` to return visibly.
414
Actually returned invisibly.
515

616
---
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ignores incomplete last line
2+
3+
Results have changed from known value recorded in '/tmp/RtmppktJm1/file13b4b50b67fc'.
4+
5+
`old`: "Hi!"
6+
`new`: "Hi!" ""
7+
8+
---
9+
10+
Results have changed from known value recorded in '/tmp/RtmppktJm1/file13b4b50b67fc'.
11+
12+
`old`: "Hi!" ""
13+
`new`: "oops"
14+
15+
# updates by default
16+
17+
Results have changed from known value recorded in '/tmp/RtmppktJm1/file13b4b249dd6d5'.
18+
19+
`old`: "Hi!"
20+
`new`: "oops"
21+
22+
---
23+
24+
Results have changed from known value recorded in '/tmp/RtmppktJm1/file13b4b249dd6d5'.
25+
26+
`old`: "Hi!"
27+
`new`: "oops"
28+
29+
# Warning for non-UTF-8 reference files
30+
31+
Results have changed from known value recorded in '/tmp/RtmppktJm1/file13b4b3b0e2961'.
32+
33+
`old`: "éáíöü"
34+
`new`:
35+
36+
# correctly matches to a file
37+
38+
`x` has changed from known value recorded in 'one.rds'.
39+
1/1 mismatches
40+
[1] 2 - 1 == 1
41+
42+
# equal_to_ref does not overwrite existing
43+
44+
`ref_obj2` has changed from known value recorded in '/tmp/RtmppktJm1/file13b4b10c668bf.rds'.
45+
3/3 mismatches (average diff: 1)
46+
[1] 2 - 1 == 1
47+
[2] 3 - 2 == 1
48+
[3] 4 - 3 == 1
49+
50+
---
51+
52+
`ref_obj2` has changed from known value recorded in '/tmp/RtmppktJm1/file13b4b10c668bf.rds'.
53+
3/3 mismatches (average diff: 1)
54+
[1] 2 - 1 == 1
55+
[2] 3 - 2 == 1
56+
[3] 4 - 3 == 1
57+
58+
# only succeeds if hash is correct
59+
60+
Expected value to hash to c08951d2c3.
61+
Actual hash: c08951d2c2
62+

0 commit comments

Comments
 (0)