|
1 |
| -library(withr) |
2 |
| - |
3 |
| -repo_input <- tempfile(pattern = "git2r-") |
4 |
| -repo <- fake_repo(repo_input) |
5 |
| - |
6 |
| -# Classic use |
7 |
| -with_dir(repo, { |
8 |
| - res <- git_down(author = "Cervan", |
9 |
| - pattern = c("Issue" = "#[[:digit:]]+"), |
10 |
| - open = FALSE |
11 |
| - ) |
12 |
| -}) |
13 |
| -lines <- readLines(file.path(dirname(res), "section-issue.html")) |
14 |
| -one_line_exists <- grep('<h2><span class="header-section-number">1.2</span> Issue: #1</h2>', |
15 |
| - lines, fixed = TRUE) |
16 |
| -sub_commit_1 <- grep('<h3><span class="header-section-number">1.2.1</span> commit: example: modification</h3>', |
17 |
| - lines, fixed = TRUE) |
18 |
| -sub_commit_2 <- grep('<h3><span class="header-section-number">1.2.2</span> commit: Add NEWS</h3>', |
19 |
| - lines, fixed = TRUE) |
20 |
| - |
21 |
| -test_that("git_down function",{ |
22 |
| - expect_match(res, regexp = ".html") |
23 |
| - expect_true(file.exists(file.path(dirname(res), "section-issue.html"))) |
24 |
| - expect_length(one_line_exists, 1) |
25 |
| - expect_length(sub_commit_1, 1) |
26 |
| - expect_length(sub_commit_2, 1) |
27 |
| -}) |
28 |
| - |
29 |
| -# clean dir |
30 |
| -unlink(dirname(res), recursive = TRUE) |
31 |
| - |
32 |
| -# Pattern without name and special characters cleaned |
33 |
| -with_dir(repo, { |
34 |
| - res <- git_down(author = "StatnMap", |
35 |
| - pattern = c("#[[:digit:]]+"), |
36 |
| - open = FALSE |
37 |
| - ) |
38 |
| -}) |
39 |
| - |
40 |
| -lines <- readLines(file.path(dirname(res), "section-digit.html")) |
41 |
| -one_line_exists <- grep('<h2><span class="header-section-number">1.2</span> <code>#--:digit:--+</code>: #1</h2>', |
42 |
| - lines, fixed = TRUE) |
43 |
| - |
44 |
| -test_that("git_down no name function",{ |
45 |
| - expect_match(res, regexp = ".html") |
46 |
| - expect_true(file.exists(file.path(dirname(res), "section-digit.html"))) |
47 |
| - expect_true(length(one_line_exists) == 1) |
48 |
| -}) |
49 |
| - |
50 |
| -# clean dir |
51 |
| -unlink(dirname(res), recursive = TRUE) |
52 |
| - |
53 |
| -# With multiple patterns ---- |
54 |
| -with_dir(repo, { |
55 |
| - res <- git_down(author = "Seb", |
56 |
| - pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"), |
57 |
| - open = FALSE |
58 |
| - ) |
59 |
| -}) |
60 |
| - |
61 |
| -test_that("git_down multiple pattern works", { |
62 |
| - expect_match(res, regexp = ".html") |
63 |
| - |
64 |
| - issues_file <- normalizePath(file.path(dirname(res), "section-issues.html")) |
65 |
| - tickets_file <- normalizePath(file.path(dirname(res), "section-tickets.html")) |
66 |
| - |
67 |
| - expect_true(file.exists(issues_file)) |
68 |
| - expect_true(file.exists(tickets_file)) |
69 |
| - |
70 |
| - lines <- readLines(tickets_file) |
71 |
| - one_line_ticket_exists <- grep('<h2><span class="header-section-number">1.2</span> Ticket: ticket1234</h2>', |
72 |
| - lines, fixed = TRUE) |
73 |
| - |
74 |
| - expect_true(length(one_line_ticket_exists) == 1) |
75 |
| - |
76 |
| - lines <- readLines(issues_file) |
77 |
| - one_line_exists <- grep('<h2><span class="header-section-number">2.2</span> Issue: #1</h2>', |
78 |
| - lines, fixed = TRUE) |
79 |
| - expect_true(length(one_line_exists) == 1) |
80 |
| -}) |
81 |
| - |
82 |
| -# clean dir |
83 |
| -unlink(dirname(res), recursive = TRUE) |
| 1 | +if (rmarkdown::pandoc_available("1.12.3")) { |
| 2 | + library(withr) |
84 | 3 |
|
85 |
| -# With table of correspondence |
86 |
| -pattern.table <- data.frame( |
87 |
| - number = c("#2", "#1", "#1000"), |
88 |
| - title = c("#2 A second issue to illustrate a blog post", |
89 |
| - "#1 An example of issue", |
90 |
| - "#1000 issue with no commit")) |
| 4 | + repo_input <- tempfile(pattern = "git2r-") |
| 5 | + repo <- fake_repo(repo_input) |
91 | 6 |
|
92 |
| -test_that("git_down with pattern table",{ |
| 7 | + # Classic use |
93 | 8 | with_dir(repo, {
|
94 | 9 | res <- git_down(author = "Cervan",
|
95 | 10 | pattern = c("Issue" = "#[[:digit:]]+"),
|
96 |
| - pattern.table = pattern.table, |
97 | 11 | open = FALSE
|
98 | 12 | )
|
| 13 | + }) |
| 14 | + lines <- readLines(file.path(dirname(res), "section-issue.html")) |
| 15 | + one_line_exists <- grep('<h2><span class="header-section-number">1.2</span> Issue: #1</h2>', |
| 16 | + lines, fixed = TRUE) |
| 17 | + sub_commit_1 <- grep('<h3><span class="header-section-number">1.2.1</span> commit: example: modification</h3>', |
| 18 | + lines, fixed = TRUE) |
| 19 | + sub_commit_2 <- grep('<h3><span class="header-section-number">1.2.2</span> commit: Add NEWS</h3>', |
| 20 | + lines, fixed = TRUE) |
| 21 | + |
| 22 | + test_that("git_down function",{ |
| 23 | + expect_match(res, regexp = ".html") |
| 24 | + expect_true(file.exists(file.path(dirname(res), "section-issue.html"))) |
| 25 | + expect_length(one_line_exists, 1) |
| 26 | + expect_length(sub_commit_1, 1) |
| 27 | + expect_length(sub_commit_2, 1) |
| 28 | + }) |
| 29 | + |
| 30 | + # clean dir |
| 31 | + unlink(dirname(res), recursive = TRUE) |
| 32 | + |
| 33 | + # Pattern without name and special characters cleaned |
| 34 | + with_dir(repo, { |
| 35 | + res <- git_down(author = "StatnMap", |
| 36 | + pattern = c("#[[:digit:]]+"), |
| 37 | + open = FALSE |
| 38 | + ) |
| 39 | + }) |
| 40 | + |
| 41 | + lines <- readLines(file.path(dirname(res), "section-digit.html")) |
| 42 | + one_line_exists <- grep('<h2><span class="header-section-number">1.2</span> <code>#--:digit:--+</code>: #1</h2>', |
| 43 | + lines, fixed = TRUE) |
| 44 | + |
| 45 | + test_that("git_down no name function",{ |
| 46 | + expect_match(res, regexp = ".html") |
| 47 | + expect_true(file.exists(file.path(dirname(res), "section-digit.html"))) |
| 48 | + expect_true(length(one_line_exists) == 1) |
| 49 | + }) |
| 50 | + |
| 51 | + # clean dir |
| 52 | + unlink(dirname(res), recursive = TRUE) |
| 53 | + |
| 54 | + # With multiple patterns ---- |
| 55 | + with_dir(repo, { |
| 56 | + res <- git_down(author = "Seb", |
| 57 | + pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"), |
| 58 | + open = FALSE |
| 59 | + ) |
| 60 | + }) |
| 61 | + |
| 62 | + test_that("git_down multiple pattern works", { |
99 | 63 | expect_match(res, regexp = ".html")
|
| 64 | + |
| 65 | + issues_file <- normalizePath(file.path(dirname(res), "section-issues.html")) |
| 66 | + tickets_file <- normalizePath(file.path(dirname(res), "section-tickets.html")) |
| 67 | + |
| 68 | + expect_true(file.exists(issues_file)) |
| 69 | + expect_true(file.exists(tickets_file)) |
| 70 | + |
| 71 | + lines <- readLines(tickets_file) |
| 72 | + one_line_ticket_exists <- grep('<h2><span class="header-section-number">1.2</span> Ticket: ticket1234</h2>', |
| 73 | + lines, fixed = TRUE) |
| 74 | + |
| 75 | + expect_true(length(one_line_ticket_exists) == 1) |
| 76 | + |
| 77 | + lines <- readLines(issues_file) |
| 78 | + one_line_exists <- grep('<h2><span class="header-section-number">2.2</span> Issue: #1</h2>', |
| 79 | + lines, fixed = TRUE) |
| 80 | + expect_true(length(one_line_exists) == 1) |
| 81 | + }) |
| 82 | + |
| 83 | + # clean dir |
| 84 | + unlink(dirname(res), recursive = TRUE) |
| 85 | + |
| 86 | + # With table of correspondence |
| 87 | + pattern.table <- data.frame( |
| 88 | + number = c("#2", "#1", "#1000"), |
| 89 | + title = c("#2 A second issue to illustrate a blog post", |
| 90 | + "#1 An example of issue", |
| 91 | + "#1000 issue with no commit")) |
| 92 | + |
| 93 | + test_that("git_down with pattern table",{ |
| 94 | + with_dir(repo, { |
| 95 | + res <- git_down(author = "Cervan", |
| 96 | + pattern = c("Issue" = "#[[:digit:]]+"), |
| 97 | + pattern.table = pattern.table, |
| 98 | + open = FALSE |
| 99 | + ) |
| 100 | + expect_match(res, regexp = ".html") |
| 101 | + }) |
100 | 102 | })
|
101 |
| -}) |
102 | 103 |
|
103 |
| -# clean dir |
104 |
| -unlink(dirname(res), recursive = TRUE) |
| 104 | + # clean dir |
| 105 | + unlink(dirname(res), recursive = TRUE) |
| 106 | +} |
0 commit comments