Skip to content

Commit 6f7c9a5

Browse files
committed
adding test for precommit-docopt
1 parent afe8879 commit 6f7c9a5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/testthat/test-docopt.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
test_that("custom docopt interface parses as expected", {
2+
args_variants <- list(
3+
"file a.R",
4+
c("file a.R", "file-B.R"),
5+
c("File A.R", "File c.R"),
6+
c("Another file with spaces.R", "--warn_only"),
7+
c("Another file with spaces.R", "Yet another file with spaces (YAFWS).R", "--warn_only"),
8+
c("--warn_only", "Another file with spaces.R"),
9+
c("--warn_only", "Another file with spaces.R", "Yet another file with spaces (YAFWS).R"),
10+
c("Another file with spaces.R", "--warn_only", "Yet another file with spaces (YAFWS).R")
11+
)
12+
13+
"Run lintr on R files during a precommit.
14+
Usage:
15+
cmdtest [--warn_only] <files>...
16+
Options:
17+
--warn_only Placeholder for test.
18+
" -> doc
19+
20+
for (args in args_variants) {
21+
new_args <- precommit_docopt(doc, args)
22+
23+
# to show failures in vanilla docopt, use this:
24+
# new_args <- docopt::docopt(doc, args)
25+
26+
expect_equal(length(new_args), 4)
27+
if ("--warn_only" %in% args) {
28+
expect_equal(length(new_args$files), length(args) - 1)
29+
expect_equal(length(new_args$`<files>`), length(args) - 1)
30+
expect_true(new_args$warn_only)
31+
expect_true(new_args$`--warn_only`)
32+
} else {
33+
expect_equal(length(new_args$files), length(args))
34+
expect_equal(length(new_args$`<files>`), length(args))
35+
expect_false(new_args$warn_only)
36+
expect_false(new_args$`--warn_only`)
37+
}
38+
}
39+
})

0 commit comments

Comments
 (0)