11library(withr )
22
3+ # debug if problems with CRAN to retrieve outputs
4+ debug <- FALSE
5+
36repo_input <- tempfile(pattern = " git2r-" )
47repo <- fake_repo(repo_input )
58
@@ -13,13 +16,26 @@ with_dir(repo, {
1316lines <- readLines(file.path(dirname(res ), " section-issue.html" ))
1417one_line_exists <- grep(' <h2><span class="header-section-number">1.2</span> Issue: #1</h2>' ,
1518 lines , fixed = TRUE )
19+ sub_commit_1 <- grep(' <h3><span class="header-section-number">1.2.1</span> commit: example: modification</h3>' ,
20+ lines , fixed = TRUE )
21+ sub_commit_2 <- grep(' <h3><span class="header-section-number">1.2.2</span> commit: Add NEWS</h3>' ,
22+ lines , fixed = TRUE )
1623
1724test_that(" git_down function" ,{
1825 expect_match(res , regexp = " .html" )
1926 expect_true(file.exists(file.path(dirname(res ), " section-issue.html" )))
20- expect_true(length(one_line_exists ) == 1 )
27+ expect_length(one_line_exists , 1 )
28+ expect_length(sub_commit_1 , 1 )
29+ expect_length(sub_commit_2 , 1 )
2130})
2231
32+ # clean dir
33+ if (debug ) {
34+ dir.create(" res_one" )
35+ file.copy(dirname(res ), " res_one" , recursive = TRUE , overwrite = TRUE )
36+ }
37+ unlink(dirname(res ), recursive = TRUE )
38+
2339# Pattern without name and special characters cleaned
2440with_dir(repo , {
2541 res <- git_down(author = " StatnMap" ,
@@ -38,30 +54,99 @@ test_that("git_down no name function",{
3854 expect_true(length(one_line_exists ) == 1 )
3955})
4056
57+ # clean dir
58+ if (debug ) {
59+ dir.create(" res_two" )
60+ file.copy(dirname(res ), " res_two" , recursive = TRUE , overwrite = TRUE )
61+ }
62+ unlink(dirname(res ), recursive = TRUE )
63+
4164# With multiple patterns ----
4265
4366with_dir(repo , {
67+
4468 res <- git_down(author = " Seb" ,
4569 pattern = c(" Tickets" = " ticket[[:digit:]]+" , " Issues" = " #[[:digit:]]+" ),
4670 open = FALSE
4771 )
48- res <- normalizePath(res )
72+
73+
74+ # For Debugging with CRAN ----
75+ if (debug ) {
76+ res_files <- paste(list.files(dirname(res )), collapse = " , " )
77+
78+ # repo <- "."
79+
80+ res_commits <- nest_commits_by_pattern(
81+ repo ,
82+ pattern = c(" Issues" = " #[[:digit:]]+" , " Tickets" = " ticket[[:digit:]]+" ),
83+ silent = TRUE
84+ )
85+
86+ res_pattern <- purrr :: map_dfr(
87+ names(c(" Tickets" = " ticket[[:digit:]]+" , " Issues" = " #[[:digit:]]+" )),
88+ ~ each_pattern(res_commits , pattern.type = .x ))
89+
90+ res_content <- paste(c(paste0(" # Gitbook for " , " toto" , " {-} \n " ),
91+ paste0(" Done on: " , Sys.time(), " \n " ), " \n " , unlist(res_pattern $ text )),
92+ collapse = " \n\n " )
93+
94+ dir.create(normalizePath(file.path(repo , " gitdown-cran" ), mustWork = FALSE ), recursive = TRUE )
95+ file.copy(from = list.files(system.file(" booktemplate" , package = " gitdown" ), full.names = TRUE ),
96+ to = normalizePath(file.path(repo , " gitdown-cran" )), overwrite = TRUE )
97+
98+ gitdown ::: write_in(x = res_content , repo = repo , dir = " gitdown-cran" , rmd = " index.Rmd" )
99+ res_render <- rmarkdown :: render(file.path(repo , " gitdown-cran" , " index.Rmd" ))
100+ }
49101})
50- lines <- readLines(file.path(dirname(res ), " section-issues.html" ))
51- one_line_exists <- grep(' <h2><span class="header-section-number">2.2</span> Issue: #1</h2>' ,
52- lines , fixed = TRUE )
53- lines <- readLines(file.path(dirname(res ), " section-tickets.html" ))
54- one_line_ticket_exists <- grep(' <h2><span class="header-section-number">1.2</span> Ticket: ticket1234</h2>' ,
55- lines , fixed = TRUE )
102+
103+ # For Debugging with CRAN ----
104+ if (debug ) {
105+ dput(res_commits , file = " res_commits.txt" )
106+ dput(res_files , file = " res_files.txt" )
107+ dput(res_pattern , file = " res_pattern.txt" )
108+ dput(res_content , file = " res_content.txt" )
109+ file.copy(file.path(repo , " gitdown" , ' index.Rmd' ), " res_index.txt" , overwrite = TRUE )
110+ file.copy(file.path(repo , " gitdown-cran" , ' index.Rmd' ), " res_index_cran.txt" , overwrite = TRUE )
111+ file.copy(file.path(repo , " gitdown" , ' _bookdown.yml' ), " res_bookdown.txt" , overwrite = TRUE )
112+ file.copy(file.path(repo , " gitdown" , ' _output.yml' ), " res_output.txt" , overwrite = TRUE )
113+
114+
115+ dir.create(" res_three" )
116+ file.copy(dirname(res ), " res_three" , recursive = TRUE , overwrite = TRUE )
117+ }
56118
57119test_that(" git_down multiple pattern works" , {
58120 expect_match(res , regexp = " .html" )
59- expect_true(file.exists(file.path(dirname(res ), " section-issues.html" )))
60- expect_true(file.exists(file.path(dirname(res ), " section-tickets.html" )))
61- expect_true(length(one_line_exists ) == 1 )
121+
122+ issues_file <- normalizePath(file.path(dirname(res ), " section-issues.html" ))
123+ tickets_file <- normalizePath(file.path(dirname(res ), " section-tickets.html" ))
124+
125+ # For Debugging with CRAN ----
126+ if (debug ) {
127+ dput(dirname(res ), file = " res_dirname.txt" )
128+ dput(issues_file , file = " res_issues_file.txt" )
129+ dput(tickets_file , file = " res_tickets_file.txt" )
130+ }
131+
132+ expect_true(file.exists(issues_file ))
133+ expect_true(file.exists(tickets_file ))
134+
135+ lines <- readLines(tickets_file )
136+ one_line_ticket_exists <- grep(' <h2><span class="header-section-number">1.2</span> Ticket: ticket1234</h2>' ,
137+ lines , fixed = TRUE )
138+
62139 expect_true(length(one_line_ticket_exists ) == 1 )
140+
141+ lines <- readLines(issues_file )
142+ one_line_exists <- grep(' <h2><span class="header-section-number">2.2</span> Issue: #1</h2>' ,
143+ lines , fixed = TRUE )
144+ expect_true(length(one_line_exists ) == 1 )
63145})
64146
147+ # clean dir
148+ unlink(dirname(res ), recursive = TRUE )
149+
65150# With table of correspondence
66151pattern.table <- data.frame (
67152 number = c(" #2" , " #1" , " #1000" ),
@@ -79,3 +164,13 @@ test_that("git_down with pattern table",{
79164 expect_match(res , regexp = " .html" )
80165 })
81166})
167+
168+ if (debug ) {
169+ all_res_files <- list.files(pattern = ' ^res_' , full.names = TRUE )
170+ dir.create(" debug" )
171+ file.copy(all_res_files , " debug" , recursive = TRUE )
172+ unlink(all_res_files , recursive = TRUE )
173+ }
174+
175+ # clean dir
176+ unlink(dirname(res ), recursive = TRUE )
0 commit comments