Skip to content

Commit 5e0d7f9

Browse files
authored
Merge pull request #18 from ThinkR-open/fix-markdown-time
Fix markdown and time tests
2 parents 2335ef3 + f1b9a33 commit 5e0d7f9

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [main, master]
88
schedule:
99
# * is a special character in YAML so you have to quote this string
10-
- cron: '59 23,11 * * 3'
10+
- cron: '01 00 * * 3'
1111

1212
name: R-CMD-check
1313

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
on:
44
push:
55
branches: [main, master]
6-
pull_request:
7-
branches: [main, master]
86
schedule:
97
# * is a special character in YAML so you have to quote this string
10-
- cron: '59 23,11 * * 3'
8+
- cron: '01 00 * * 3'
119

1210
name: test-coverage
1311

tests/testthat/test-get_info_files.R

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
time_before_date <- Sys.Date()
2-
time_before <- as.character(time_before_date)
1+
time_before <- Sys.time()
2+
Sys.sleep(1)
33

44
repo_pkg <- fake_repo(as.package = TRUE)
55
repo_no_pkg <- fake_repo()
@@ -10,27 +10,21 @@ infos <- get_info(files[grep("example", files)], repo = repo_pkg)
1010
infos_not_in_repo <- get_info(files[grep("my_mean", files)], repo = repo_pkg)
1111

1212
# if check started one day and finishes the other day
13-
time_after_date <- Sys.Date()
14-
time_after <- as.character(time_after_date)
13+
Sys.sleep(1)
14+
time_after <- Sys.time()
1515

1616
test_that("get_info works", {
1717
expect_true(infos$in_repository)
1818
expect_equal(infos$file, "example.txt")
1919

20-
expect_gte(as.Date(infos$last_modif), time_before_date)
21-
expect_lte(as.Date(infos$last_modif), time_after_date)
22-
expect_true(as.character(as.Date(infos$first_modif)) %in%
23-
c(setNames(time_before, "first"), setNames(time_after, "first")))
24-
expect_true(as.character(as.Date(infos$last_modif)) %in%
25-
c(setNames(time_before, "last"), setNames(time_after, "first")))
20+
expect_gte(infos$last_modif, time_before)
21+
expect_lte(infos$last_modif, time_after)
2622

2723
expect_false(infos_not_in_repo$in_repository)
2824
expect_equal(infos_not_in_repo$file, "R/my_mean.R")
2925
expect_true(is.na(infos_not_in_repo$first_modif))
30-
expect_gte(as.Date(infos_not_in_repo$last_modif), time_before_date)
31-
expect_lte(as.Date(infos_not_in_repo$last_modif), time_after_date)
32-
expect_true(as.character(as.Date(infos_not_in_repo$last_modif)) %in%
33-
c(setNames(time_before, "last"), setNames(time_after, "first")))
26+
expect_gte(infos_not_in_repo$last_modif, time_before)
27+
expect_lte(infos_not_in_repo$last_modif, time_after)
3428
})
3529

3630
# get_last_modif ----

tests/testthat/test-git_down.R

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ if (rmarkdown::pandoc_available("1.12.3")) {
1212
)
1313
})
1414
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)
15+
# like <h2><span>1.2</span> Issue: #1</h2>',
16+
one_line_exists <- grep('h2.+1[.]2.+Issue: #1.+h2', lines, fixed = FALSE)
17+
# like <h3><span>1.2.1</span> commit: example: modification</h3>',
18+
sub_commit_1 <- grep('h3.+1[.]2[.]1.+commit: example: modification.+h3',
19+
lines, fixed = FALSE)
20+
# like <h3><span>1.2.2</span> commit: Add NEWS</h3>',
21+
sub_commit_2 <- grep('h3.+1[.]2[.]2.+commit: Add NEWS.+h3',
22+
lines, fixed = FALSE)
2123

2224
test_that("git_down function",{
2325
expect_match(res, regexp = ".html")
@@ -39,8 +41,9 @@ if (rmarkdown::pandoc_available("1.12.3")) {
3941
})
4042

4143
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+
# like <h2><span>1.2</span> <code>#--:digit:--+</code>: #1</h2>',
45+
one_line_exists <- grep('h2.+1[.]2.+<code>#--:digit:--\\+</code>: #1.+h2',
46+
lines, fixed = FALSE)
4447

4548
test_that("git_down no name function",{
4649
expect_match(res, regexp = ".html")
@@ -69,14 +72,16 @@ if (rmarkdown::pandoc_available("1.12.3")) {
6972
expect_true(file.exists(tickets_file))
7073

7174
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)
75+
# like <h2><span>1.2</span> Ticket: ticket1234</h2>'
76+
one_line_ticket_exists <- grep('h2.*1.2.*Ticket: ticket1234.*h2',
77+
lines, fixed = FALSE)
7478

7579
expect_true(length(one_line_ticket_exists) == 1)
7680

7781
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)
82+
# like <h2><span>2.2</span> Issue: #1</h2>',
83+
one_line_exists <- grep('h2.+2[.]2.+Issue: #1.+h2',
84+
lines, fixed = FALSE)
8085
expect_true(length(one_line_exists) == 1)
8186
})
8287

0 commit comments

Comments
 (0)