File tree Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -18,16 +18,31 @@ test_that("all ggproto methods start with `{` (#6459)", {
18
18
mget(ls(" package:ggplot2" ), asNamespace(" ggplot2" ), ifnotfound = list (NULL ))
19
19
)
20
20
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
+ }
30
31
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
+ }
32
44
45
+ failures <- lapply(ggprotos , report_no_bracket )
46
+ failures <- failures [lengths(failures ) > 0 ]
47
+ expect_equal(failures , list ())
33
48
})
You can’t perform that action at this time.
0 commit comments