Skip to content

Commit 1a048b4

Browse files
committed
Be more explicit about returned values
1 parent 8294b85 commit 1a048b4

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

R/expect-comparison.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ expect_compare_ <- function(
4040
} else {
4141
pass()
4242
}
43-
44-
invisible(act$val)
4543
}
4644

4745
failure_compare <- function(act, exp, operator) {
@@ -83,6 +81,7 @@ expect_lt <- function(object, expected, label = NULL, expected.label = NULL) {
8381
exp <- quasi_label(enquo(expected), expected.label)
8482

8583
expect_compare_("<", act, exp)
84+
invisible(act$val)
8685
}
8786

8887
#' @export
@@ -92,6 +91,7 @@ expect_lte <- function(object, expected, label = NULL, expected.label = NULL) {
9291
exp <- quasi_label(enquo(expected), expected.label)
9392

9493
expect_compare_("<=", act, exp)
94+
invisible(act$val)
9595
}
9696

9797
#' @export
@@ -101,6 +101,7 @@ expect_gt <- function(object, expected, label = NULL, expected.label = NULL) {
101101
exp <- quasi_label(enquo(expected), expected.label)
102102

103103
expect_compare_(">", act, exp)
104+
invisible(act$val)
104105
}
105106

106107
#' @export
@@ -110,6 +111,7 @@ expect_gte <- function(object, expected, label = NULL, expected.label = NULL) {
110111
exp <- quasi_label(enquo(expected), expected.label)
111112

112113
expect_compare_(">=", act, exp)
114+
invisible(act$val)
113115
}
114116

115117

R/expect-constant.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ NULL
3131
expect_true <- function(object, info = NULL, label = NULL) {
3232
act <- quasi_label(enquo(object), label)
3333
exp <- labelled_value(TRUE, "TRUE")
34+
3435
expect_waldo_constant_(act, exp, info = info, ignore_attr = TRUE)
36+
invisible(act$val)
3537
}
3638

3739
#' @export
3840
#' @rdname logical-expectations
3941
expect_false <- function(object, info = NULL, label = NULL) {
4042
act <- quasi_label(enquo(object), label)
4143
exp <- labelled_value(FALSE, "FALSE")
44+
4245
expect_waldo_constant_(act, exp, info = info, ignore_attr = TRUE)
46+
invisible(act$val)
4347
}
4448

4549
#' Do you expect `NULL`?
@@ -59,7 +63,9 @@ expect_false <- function(object, info = NULL, label = NULL) {
5963
expect_null <- function(object, info = NULL, label = NULL) {
6064
act <- quasi_label(enquo(object), label)
6165
exp <- labelled_value(NULL, "NULL")
66+
6267
expect_waldo_constant_(act, exp, info = info)
68+
invisible(act$val)
6369
}
6470

6571
expect_waldo_constant_ <- function(
@@ -86,5 +92,4 @@ expect_waldo_constant_ <- function(
8692
} else {
8793
pass()
8894
}
89-
invisible(act$val)
9095
}

R/expect-equality.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ expect_equal <- function(
8686
)
8787
fail(msg, info = info)
8888
}
89-
invisible(act$val)
9089
}
90+
invisible(act$val)
9191
}
9292

9393

@@ -124,8 +124,8 @@ expect_identical <- function(
124124
)
125125
fail(msg, info = info)
126126
}
127-
invisible(act$val)
128127
}
128+
invisible(act$val)
129129
}
130130

131131
expect_waldo_equal_ <- function(
@@ -153,8 +153,6 @@ expect_waldo_equal_ <- function(
153153
)
154154
fail(msg, info = info, trace_env = trace_env)
155155
}
156-
157-
invisible(act$val)
158156
}
159157

160158
#' Is an object equal to the expected value, ignoring attributes?

R/expect-named.R

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,27 @@ expect_named <- function(
3838
act <- quasi_label(enquo(object), label)
3939

4040
if (missing(expected)) {
41-
return(expect_has_names_(act))
42-
}
41+
act_names <- names(act$val)
42+
if (is.null(act_names)) {
43+
msg <- sprintf("Expected %s to have names.", act$lab)
44+
fail(msg)
45+
} else {
46+
pass()
47+
}
48+
} else {
49+
exp <- quasi_label(enquo(expected), arg = "expected")
4350

44-
exp <- quasi_label(enquo(expected), arg = "expected")
51+
exp$val <- normalise_names(exp$val, ignore.order, ignore.case)
52+
act_names <- labelled_value(
53+
normalise_names(names(act$val), ignore.order, ignore.case),
54+
paste0("names of ", act$lab)
55+
)
4556

46-
exp$val <- normalise_names(exp$val, ignore.order, ignore.case)
47-
act_names <- labelled_value(
48-
normalise_names(names(act$val), ignore.order, ignore.case),
49-
paste0("names of ", act$lab)
50-
)
51-
if (ignore.order) {
52-
expect_setequal_(act_names, exp)
53-
} else {
54-
expect_waldo_equal_("equal", act_names, exp)
57+
if (ignore.order) {
58+
expect_setequal_(act_names, exp)
59+
} else {
60+
expect_waldo_equal_("equal", act_names, exp)
61+
}
5562
}
5663

5764
invisible(act$val)
@@ -71,14 +78,3 @@ normalise_names <- function(x, ignore.order = FALSE, ignore.case = FALSE) {
7178

7279
x
7380
}
74-
75-
expect_has_names_ <- function(act, trace_env = caller_env()) {
76-
act_names <- names(act$val)
77-
if (is.null(act_names)) {
78-
msg <- sprintf("Expected %s to have names.", act$lab)
79-
fail(msg, trace_env = trace_env)
80-
} else {
81-
pass()
82-
}
83-
invisible(act$val)
84-
}

R/expect-setequal.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ expect_mapequal <- function(object, expected) {
9090
exp <- quasi_label(enquo(expected))
9191

9292
expect_waldo_equal_("equal", act, exp, list_as_map = TRUE)
93+
invisible(act$val)
9394
}
9495

9596
#' @export

0 commit comments

Comments
 (0)