forked from tidyverse/dbplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestthat.R
47 lines (38 loc) · 1.16 KB
/
testthat.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
expect_equal_tbl <- function(object, expected, ...,
info = NULL, label = NULL, expected.label = NULL) {
lab_act <- label %||% expr_label(substitute(object))
lab_exp <- expected.label %||% expr_label(substitute(expected))
ok <- dplyr::all_equal(collect(object), collect(expected), ...)
msg <- glue("
{lab_act} not equal to {lab_exp}.
{paste(ok, collapse = '\n')}
")
testthat::expect(isTRUE(ok), msg, info = info)
}
expect_equal_tbls <- function(results, ref = NULL, ...) {
stopifnot(is.list(results))
if (!is_named(results)) {
result_name <- expr_name(substitute(results))
names(results) <- paste0(result_name, "_", seq_along(results))
}
# If ref is NULL, use the first result
if (is.null(ref)) {
if (length(results) < 2) {
testthat::skip("Need at least two srcs to compare")
}
ref <- results[[1]]
ref_name <- names(results)[[1]]
rest <- results[-1]
} else {
rest <- results
ref_name <- "`ref`"
}
for (i in seq_along(rest)) {
expect_equal_tbl(
rest[[i]], ref, ...,
label = names(rest)[[i]],
expected.label = ref_name
)
}
invisible(TRUE)
}