Skip to content

Commit 735eabf

Browse files
committed
report potential test failures
1 parent f6c13b2 commit 735eabf

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

tests/testthat/test-ggproto.R

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@ test_that("all ggproto methods start with `{` (#6459)", {
1818
mget(ls("package:ggplot2"), asNamespace("ggplot2"), ifnotfound = list(NULL))
1919
)
2020

21-
method_nobrackets <- lapply(ggprotos, function(x) {
22-
Filter(
23-
function(m) inherits(x[[m]], "ggproto_method") && {
24-
b <- as.list(body(get(m, x)))
25-
length(b) == 0 || b[[1]] != quote(`{`)
26-
},
27-
ls(envir = x)
28-
)
29-
})
21+
lacks_brackets <- function(method) {
22+
if (!inherits(method, "ggproto_method")) {
23+
return(FALSE)
24+
}
25+
body <- as.list(body(environment(method)$f))
26+
if (length(body) == 0 || body[[1]] != quote(`{`)) {
27+
return(TRUE)
28+
}
29+
return(FALSE)
30+
}
3031

31-
expect_length(Filter(length, method_nobrackets), 0)
32+
report_no_bracket <- function(ggproto_class) {
33+
unlist(lapply(
34+
ls(envir = ggproto_class),
35+
function(method) {
36+
has_brackets <- !lacks_brackets(ggproto_class[[method]])
37+
if (has_brackets) {
38+
return(character())
39+
}
40+
return(method)
41+
}
42+
))
43+
}
3244

45+
failures <- lapply(ggprotos, report_no_bracket)
46+
failures <- failures[lengths(failures) > 0]
47+
expect_equal(failures, list())
3348
})

0 commit comments

Comments
 (0)