Skip to content

Commit 701a0be

Browse files
committed
Automatically determine the argument name in quasi_label()
This removes one thing to explain about writing expectations. I also improved the error when the argument is missing by passing along the correct call.
1 parent 9c93b8f commit 701a0be

17 files changed

+64
-53
lines changed

R/expect-comparison.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,35 @@ expect_compare_ <- function(
5454
#' @export
5555
#' @rdname comparison-expectations
5656
expect_lt <- function(object, expected, label = NULL, expected.label = NULL) {
57-
act <- quasi_label(enquo(object), label, arg = "object")
58-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
57+
act <- quasi_label(enquo(object), label)
58+
exp <- quasi_label(enquo(expected), expected.label)
5959

6060
expect_compare_("<", act, exp)
6161
}
6262

6363
#' @export
6464
#' @rdname comparison-expectations
6565
expect_lte <- function(object, expected, label = NULL, expected.label = NULL) {
66-
act <- quasi_label(enquo(object), label, arg = "object")
67-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
66+
act <- quasi_label(enquo(object), label)
67+
exp <- quasi_label(enquo(expected), expected.label)
6868

6969
expect_compare_("<=", act, exp)
7070
}
7171

7272
#' @export
7373
#' @rdname comparison-expectations
7474
expect_gt <- function(object, expected, label = NULL, expected.label = NULL) {
75-
act <- quasi_label(enquo(object), label, arg = "object")
76-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
75+
act <- quasi_label(enquo(object), label)
76+
exp <- quasi_label(enquo(expected), expected.label)
7777

7878
expect_compare_(">", act, exp)
7979
}
8080

8181
#' @export
8282
#' @rdname comparison-expectations
8383
expect_gte <- function(object, expected, label = NULL, expected.label = NULL) {
84-
act <- quasi_label(enquo(object), label, arg = "object")
85-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
84+
act <- quasi_label(enquo(object), label)
85+
exp <- quasi_label(enquo(expected), expected.label)
8686

8787
expect_compare_(">=", act, exp)
8888
}

R/expect-constant.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ NULL
2929
#' @export
3030
#' @rdname logical-expectations
3131
expect_true <- function(object, info = NULL, label = NULL) {
32-
act <- quasi_label(enquo(object), label, arg = "object")
32+
act <- quasi_label(enquo(object), label)
3333
expect_waldo_constant_(act, TRUE, info = info, ignore_attr = TRUE)
3434
}
3535

3636
#' @export
3737
#' @rdname logical-expectations
3838
expect_false <- function(object, info = NULL, label = NULL) {
39-
act <- quasi_label(enquo(object), label, arg = "object")
39+
act <- quasi_label(enquo(object), label)
4040
expect_waldo_constant_(act, FALSE, info = info, ignore_attr = TRUE)
4141
}
4242

@@ -55,7 +55,7 @@ expect_false <- function(object, info = NULL, label = NULL) {
5555
#' expect_null(x)
5656
#' show_failure(expect_null(y))
5757
expect_null <- function(object, info = NULL, label = NULL) {
58-
act <- quasi_label(enquo(object), label, arg = "object")
58+
act <- quasi_label(enquo(object), label)
5959
expect_waldo_constant_(act, NULL, info = info)
6060
}
6161

R/expect-equality.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ expect_equal <- function(
6363
label = NULL,
6464
expected.label = NULL
6565
) {
66-
act <- quasi_label(enquo(object), label, arg = "object")
67-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
66+
act <- quasi_label(enquo(object), label)
67+
exp <- quasi_label(enquo(expected), expected.label)
6868

6969
if (edition_get() >= 3) {
7070
expect_waldo_equal_("equal", act, exp, info, ..., tolerance = tolerance)
@@ -93,8 +93,8 @@ expect_identical <- function(
9393
expected.label = NULL,
9494
...
9595
) {
96-
act <- quasi_label(enquo(object), label, arg = "object")
97-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
96+
act <- quasi_label(enquo(object), label)
97+
exp <- quasi_label(enquo(expected), expected.label)
9898

9999
if (edition_get() >= 3) {
100100
expect_waldo_equal_("identical", act, exp, info, ...)
@@ -180,8 +180,8 @@ expect_equivalent <- function(
180180
label = NULL,
181181
expected.label = NULL
182182
) {
183-
act <- quasi_label(enquo(object), label, arg = "object")
184-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
183+
act <- quasi_label(enquo(object), label)
184+
exp <- quasi_label(enquo(expected), expected.label)
185185

186186
edition_deprecate(
187187
3,

R/expect-inheritance.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NULL
4848
expect_type <- function(object, type) {
4949
stopifnot(is.character(type), length(type) == 1)
5050

51-
act <- quasi_label(enquo(object), arg = "object")
51+
act <- quasi_label(enquo(object))
5252
act_type <- typeof(act$val)
5353

5454
if (!identical(act_type, type)) {
@@ -69,7 +69,7 @@ expect_type <- function(object, type) {
6969
#' from `class`. If `TRUE`, checks that object has a class that's identical
7070
#' to `class`.
7171
expect_s3_class <- function(object, class, exact = FALSE) {
72-
act <- quasi_label(enquo(object), arg = "object")
72+
act <- quasi_label(enquo(object))
7373
act$class <- format_class(class(act$val))
7474
exp_lab <- format_class(class)
7575

@@ -112,7 +112,7 @@ expect_s7_class <- function(object, class) {
112112
stop_input_type(class, "an S7 class object")
113113
}
114114

115-
act <- quasi_label(enquo(object), arg = "object")
115+
act <- quasi_label(enquo(object))
116116

117117
if (!S7::S7_inherits(object)) {
118118
return(fail(sprintf("%s is not an S7 object", act$lab)))
@@ -136,7 +136,7 @@ expect_s7_class <- function(object, class) {
136136
#' @export
137137
#' @rdname inheritance-expectations
138138
expect_s4_class <- function(object, class) {
139-
act <- quasi_label(enquo(object), arg = "object")
139+
act <- quasi_label(enquo(object))
140140
act$class <- format_class(methods::is(act$val))
141141
exp_lab <- format_class(class)
142142

@@ -194,7 +194,7 @@ expect_is <- function(object, class, info = NULL, label = NULL) {
194194
"Use `expect_type()`, `expect_s3_class()`, or `expect_s4_class()` instead"
195195
)
196196

197-
act <- quasi_label(enquo(object), label, arg = "object")
197+
act <- quasi_label(enquo(object), label)
198198
act$class <- format_class(class(act$val))
199199
exp_lab <- format_class(class(class))
200200

R/expect-known.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ expect_known_value <- function(
164164
"Please use `expect_snapshot_value()` instead"
165165
)
166166

167-
act <- quasi_label(enquo(object), label, arg = "object")
167+
act <- quasi_label(enquo(object), label)
168168

169169
if (!file.exists(file)) {
170170
warning("Creating reference value", call. = FALSE)
@@ -214,7 +214,7 @@ expect_known_hash <- function(object, hash = NULL) {
214214
"Please use `expect_snapshot_value()` instead"
215215
)
216216

217-
act <- quasi_label(enquo(object), arg = "object")
217+
act <- quasi_label(enquo(object))
218218
act_hash <- digest::digest(act$val)
219219
if (!is.null(hash)) {
220220
act_hash <- substr(act_hash, 1, nchar(hash))

R/expect-length.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
expect_length <- function(object, n) {
1717
stopifnot(is.numeric(n), length(n) == 1)
1818

19-
act <- quasi_label(enquo(object), arg = "object")
19+
act <- quasi_label(enquo(object))
2020
act$n <- length(act$val)
2121

2222
if (act$n != n) {

R/expect-match.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ expect_match <- function(
3838
label = NULL
3939
) {
4040
# Capture here to avoid environment-related messiness
41-
act <- quasi_label(enquo(object), label, arg = "object")
41+
act <- quasi_label(enquo(object), label)
4242
stopifnot(is.character(regexp), length(regexp) == 1)
4343

4444
stopifnot(is.character(act$val))
@@ -73,7 +73,7 @@ expect_no_match <- function(
7373
label = NULL
7474
) {
7575
# Capture here to avoid environment-related messiness
76-
act <- quasi_label(enquo(object), label, arg = "object")
76+
act <- quasi_label(enquo(object), label)
7777
stopifnot(is.character(regexp), length(regexp) == 1)
7878

7979
stopifnot(is.character(act$val))

R/expect-named.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ expect_named <- function(
3232
info = NULL,
3333
label = NULL
3434
) {
35-
act <- quasi_label(enquo(object), label, arg = "object")
35+
act <- quasi_label(enquo(object), label)
3636
act$names <- names(act$val)
3737

3838
if (missing(expected)) {

R/expect-reference.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ expect_reference <- function(
2323
) {
2424
edition_deprecate(3, "expect_reference()")
2525

26-
act <- quasi_label(enquo(object), label, arg = "object")
27-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
26+
act <- quasi_label(enquo(object), label)
27+
exp <- quasi_label(enquo(expected), expected.label)
2828

2929
if (!is_reference(act$val, exp$val)) {
3030
msg <- sprintf("%s not a reference to %s.", act$lab, exp$lab)

R/expect-setequal.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#' show_failure(expect_mapequal(x, list(a = 1, b = "x")))
2525
#' show_failure(expect_mapequal(x, list(a = 1, b = 2, c = 3)))
2626
expect_setequal <- function(object, expected) {
27-
act <- quasi_label(enquo(object), arg = "object")
28-
exp <- quasi_label(enquo(expected), arg = "expected")
27+
act <- quasi_label(enquo(object))
28+
exp <- quasi_label(enquo(expected))
2929

3030
if (!is_vector(act$val) || !is_vector(exp$val)) {
3131
abort("`object` and `expected` must both be vectors")
@@ -76,8 +76,8 @@ is_vector <- function(x) is.list(x) || (is.atomic(x) && !is.null(x))
7676
#' @export
7777
#' @rdname expect_setequal
7878
expect_mapequal <- function(object, expected) {
79-
act <- quasi_label(enquo(object), arg = "object")
80-
exp <- quasi_label(enquo(expected), arg = "expected")
79+
act <- quasi_label(enquo(object))
80+
exp <- quasi_label(enquo(expected))
8181

8282
if (!is_vector(act$val) || !is_vector(exp$val)) {
8383
abort("`object` and `expected` must both be vectors")
@@ -126,8 +126,8 @@ check_names_ok <- function(x, label) {
126126
#' @export
127127
#' @rdname expect_setequal
128128
expect_contains <- function(object, expected) {
129-
act <- quasi_label(enquo(object), arg = "object")
130-
exp <- quasi_label(enquo(expected), arg = "expected")
129+
act <- quasi_label(enquo(object))
130+
exp <- quasi_label(enquo(expected))
131131

132132
if (!is_vector(act$val) || !is_vector(exp$val)) {
133133
abort("`object` and `expected` must both be vectors")
@@ -152,8 +152,8 @@ expect_contains <- function(object, expected) {
152152
#' @export
153153
#' @rdname expect_setequal
154154
expect_in <- function(object, expected) {
155-
act <- quasi_label(enquo(object), arg = "object")
156-
exp <- quasi_label(enquo(expected), arg = "expected")
155+
act <- quasi_label(enquo(object))
156+
exp <- quasi_label(enquo(expected))
157157

158158
if (!is_vector(act$val) || !is_vector(exp$val)) {
159159
abort("`object` and `expected` must both be vectors")

0 commit comments

Comments
 (0)