|
| 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