Skip to content

Commit 95575ec

Browse files
authored
add tests (#329)
* add tests * lintr
1 parent dbf2194 commit 95575ec

57 files changed

Lines changed: 6865 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.lintr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ linters: linters_with_defaults(
33
cyclocomp_linter = NULL,
44
object_usage_linter = NULL
55
)
6+
exclusions: list(
7+
"inst/template_test.R"
8+
)

inst/create_tests.r

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This only creates the basis of the test, please edit manually if necessary.
2+
withr::with_tempfile("code", {
3+
for (ff in list.files("quarto/catalog", pattern = "index.qmd", full.names = TRUE, recursive = TRUE)) {
4+
function_name <- basename(dirname(ff))
5+
6+
knitr::purl(ff, code, documentation = 0)
7+
template_full <- readLines(code)
8+
9+
end <- grep("^tbl$", template_full)
10+
template_body <- template_full[4:(end - 1)]
11+
# add indentation at the start of each line
12+
template_body <- paste0(" ", template_body)
13+
template_body <- paste(template_body, collapse = "\n")
14+
15+
template_test <- readLines(fs::path_package("cardinal", "template_test.R"))
16+
res <- glue::glue(paste(template_test, collapse = "\n"),
17+
function_name = function_name,
18+
template_body = template_body,
19+
.open = "<<", .close = ">>"
20+
)
21+
22+
writeLines(res, file.path("tests", "testthat", paste0("test-", function_name, ".R")))
23+
}
24+
})

inst/template_test.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test_that("<<function_name>>() works", {
2+
3+
<<template_body>>
4+
5+
ard <- gtsummary::gather_ard(tbl)
6+
7+
expect_snapshot(as.data.frame(ard)[1:25, ])
8+
})

tests/testthat/_snaps/fda-table_02.md

Lines changed: 220 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/fda-table_03.md

Lines changed: 330 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# fda-table_04() works
2+
3+
Code
4+
as.data.frame(ard$tbl_summary)[1:25, ]
5+
Output
6+
group1 group1_level variable variable_level context stat_name
7+
1 TRT01A Placebo SAFFL TRUE tabulate_value n
8+
2 TRT01A Placebo SAFFL TRUE tabulate_value N
9+
3 TRT01A Placebo SAFFL TRUE tabulate_value p
10+
4 TRT01A Placebo ITTFL TRUE tabulate_value n
11+
5 TRT01A Placebo ITTFL TRUE tabulate_value N
12+
6 TRT01A Placebo ITTFL TRUE tabulate_value p
13+
7 TRT01A Placebo rand_fl TRUE tabulate_value n
14+
8 TRT01A Placebo rand_fl TRUE tabulate_value N
15+
9 TRT01A Placebo rand_fl TRUE tabulate_value p
16+
10 TRT01A Placebo prot_fl TRUE tabulate_value n
17+
11 TRT01A Placebo prot_fl TRUE tabulate_value N
18+
12 TRT01A Placebo prot_fl TRUE tabulate_value p
19+
13 TRT01A Xanomeline High Dose SAFFL TRUE tabulate_value n
20+
14 TRT01A Xanomeline High Dose SAFFL TRUE tabulate_value N
21+
15 TRT01A Xanomeline High Dose SAFFL TRUE tabulate_value p
22+
16 TRT01A Xanomeline High Dose ITTFL TRUE tabulate_value n
23+
17 TRT01A Xanomeline High Dose ITTFL TRUE tabulate_value N
24+
18 TRT01A Xanomeline High Dose ITTFL TRUE tabulate_value p
25+
19 TRT01A Xanomeline High Dose rand_fl TRUE tabulate_value n
26+
20 TRT01A Xanomeline High Dose rand_fl TRUE tabulate_value N
27+
21 TRT01A Xanomeline High Dose rand_fl TRUE tabulate_value p
28+
22 TRT01A Xanomeline High Dose prot_fl TRUE tabulate_value n
29+
23 TRT01A Xanomeline High Dose prot_fl TRUE tabulate_value N
30+
24 TRT01A Xanomeline High Dose prot_fl TRUE tabulate_value p
31+
25 TRT01A Xanomeline Low Dose SAFFL TRUE tabulate_value n
32+
stat_label stat
33+
1 n 86
34+
2 N 86
35+
3 % 1
36+
4 n 86
37+
5 N 86
38+
6 % 1
39+
7 n 86
40+
8 N 86
41+
9 % 1
42+
10 n 58
43+
11 N 86
44+
12 % 0.6744186
45+
13 n 72
46+
14 N 72
47+
15 % 1
48+
16 n 72
49+
17 N 72
50+
18 % 1
51+
19 n 72
52+
20 N 72
53+
21 % 1
54+
22 n 27
55+
23 N 72
56+
24 % 0.375
57+
25 n 96
58+
fmt_fun
59+
1 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
60+
2 0
61+
3 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
62+
4 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
63+
5 0
64+
6 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
65+
7 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
66+
8 0
67+
9 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
68+
10 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
69+
11 0
70+
12 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
71+
13 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
72+
14 0
73+
15 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
74+
16 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
75+
17 0
76+
18 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
77+
19 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
78+
20 0
79+
21 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
80+
22 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
81+
23 0
82+
24 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
83+
25 function (x) , style_number(x, digits = digits, big.mark = big.mark, decimal.mark = decimal.mark, , scale = scale, prefix = prefix, suffix = suffix, na = na, , ...)
84+
warning error gts_column
85+
1 NULL NULL stat_1
86+
2 NULL NULL stat_1
87+
3 NULL NULL stat_1
88+
4 NULL NULL stat_1
89+
5 NULL NULL stat_1
90+
6 NULL NULL stat_1
91+
7 NULL NULL stat_1
92+
8 NULL NULL stat_1
93+
9 NULL NULL stat_1
94+
10 NULL NULL stat_1
95+
11 NULL NULL stat_1
96+
12 NULL NULL stat_1
97+
13 NULL NULL stat_2
98+
14 NULL NULL stat_2
99+
15 NULL NULL stat_2
100+
16 NULL NULL stat_2
101+
17 NULL NULL stat_2
102+
18 NULL NULL stat_2
103+
19 NULL NULL stat_2
104+
20 NULL NULL stat_2
105+
21 NULL NULL stat_2
106+
22 NULL NULL stat_2
107+
23 NULL NULL stat_2
108+
24 NULL NULL stat_2
109+
25 NULL NULL stat_3
110+

0 commit comments

Comments
 (0)