Skip to content

Commit b82f5c2

Browse files
each hook gets own hook test file
1 parent 9bc452a commit b82f5c2

15 files changed

+818
-868
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
run_test("codemeta-description-update",
2+
file_name = c("codemeta.json"),
3+
suffix = "",
4+
std_err = "No `DESCRIPTION` found in repository.",
5+
std_out = NULL,
6+
)
7+
8+
run_test("codemeta-description-update",
9+
file_name = c("DESCRIPTION"),
10+
suffix = "",
11+
std_err = "No `codemeta.json` found in repository.",
12+
std_out = NULL,
13+
)
14+
15+
16+
# outdated
17+
run_test("codemeta-description-update",
18+
file_name = c("DESCRIPTION", "codemeta.json"),
19+
suffix = "",
20+
std_err = "out of date",
21+
std_out = NULL,
22+
file_transformer = function(files) {
23+
if (length(files) > 1) {
24+
# transformer is called once on all files and once per file
25+
content_2 <- readLines(files[1])
26+
Sys.sleep(2)
27+
writeLines(content_2, files[1])
28+
}
29+
files
30+
}
31+
)
32+
33+
# succeed
34+
run_test("codemeta-description-update",
35+
file_name = c("DESCRIPTION", "codemeta.json"),
36+
suffix = "",
37+
file_transformer = function(files) {
38+
if (length(files) > 1) {
39+
# transformer is called once on all files and once per file
40+
content_2 <- readLines(files[2])
41+
Sys.sleep(2)
42+
writeLines(content_2, files[2])
43+
}
44+
files
45+
}
46+
)
47+
48+
# succeed in correct root
49+
run_test("codemeta-description-update",
50+
file_name = c(
51+
"rpkg/DESCRIPTION" = "DESCRIPTION",
52+
"rpkg/codemeta.json" = "codemeta.json"
53+
),
54+
cmd_args = "--root=rpkg",
55+
suffix = "",
56+
file_transformer = function(files) {
57+
if (length(files) > 1) {
58+
# transformer is called once on all files and once per file
59+
content_2 <- readLines(files[2])
60+
Sys.sleep(2)
61+
writeLines(content_2, files[2])
62+
}
63+
files
64+
}
65+
)
66+
67+
# # fail in wrong root
68+
run_test("codemeta-description-update",
69+
file_name = c(
70+
"rpkg/DESCRIPTION" = "DESCRIPTION",
71+
"rpkg/codemeta.json" = "codemeta.json",
72+
"rpkg2/codemeta.json" = "README.md"
73+
),
74+
cmd_args = "--root=rpkg2",
75+
std_err = "No `DESCRIPTION` found in repository.",
76+
suffix = "",
77+
file_transformer = function(files) {
78+
if (length(files) > 1) {
79+
# transformer is called once on all files and once per file
80+
content_2 <- readLines(files[2])
81+
Sys.sleep(2)
82+
writeLines(content_2, files[2])
83+
}
84+
files
85+
}
86+
)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# succeed (call to library that is in description)
2+
run_test("deps-in-desc",
3+
suffix = "-success.R", std_err = NULL,
4+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
5+
)
6+
7+
# fail (call to library that is not in description)
8+
run_test("deps-in-desc",
9+
suffix = "-fail.R", std_err = "Dependency check failed",
10+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
11+
)
12+
13+
# in sub directory with wrong root
14+
run_test("deps-in-desc",
15+
suffix = "-fail.R", std_err = "Could not find R package",
16+
file_transformer = function(files) {
17+
fs::path_abs(fs::file_move(files, "rpkg"))
18+
},
19+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
20+
)
21+
22+
# in sub directory with correct root
23+
run_test("deps-in-desc",
24+
cmd_args = "--root=rpkg",
25+
suffix = "-fail.R", std_err = "Dependency check failed",
26+
file_transformer = function(files) {
27+
fs::path_abs(fs::file_move(files, "rpkg"))
28+
},
29+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
30+
)
31+
32+
# in sub directory with correct root
33+
run_test("deps-in-desc",
34+
cmd_args = "--root=rpkg",
35+
suffix = "-success.R", std_err = NULL,
36+
file_transformer = function(files) {
37+
fs::path_abs(fs::file_move(files, "rpkg"))
38+
},
39+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
40+
)
41+
42+
# with :::
43+
run_test("deps-in-desc",
44+
"deps-in-desc-dot3",
45+
suffix = "-fail.R", std_err = "Dependency check failed",
46+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
47+
)
48+
49+
run_test("deps-in-desc",
50+
"deps-in-desc-dot3",
51+
suffix = "-success.R", std_err = NULL,
52+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
53+
)
54+
55+
run_test("deps-in-desc",
56+
"deps-in-desc-dot3",
57+
suffix = "-fail.R", std_err = NULL,
58+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")),
59+
cmd_args = "--allow_private_imports"
60+
)
61+
62+
# Rmd
63+
run_test("deps-in-desc",
64+
"deps-in-desc",
65+
suffix = "-fail.Rmd", std_err = "Dependency check failed",
66+
std_out = "deps-in-desc-fail.Rmd`: ttyzp",
67+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
68+
)
69+
70+
run_test("deps-in-desc",
71+
"deps-in-desc",
72+
suffix = "-success.Rmd", std_err = NULL,
73+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
74+
)
75+
76+
# README.Rmd is excluded
77+
run_test("deps-in-desc",
78+
"README.Rmd",
79+
suffix = "", std_err = NULL,
80+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf"))
81+
)
82+
83+
84+
85+
# Rnw
86+
run_test("deps-in-desc",
87+
"deps-in-desc",
88+
suffix = "-fail.Rnw", std_err = "Dependency check failed",
89+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
90+
)
91+
92+
run_test("deps-in-desc",
93+
"deps-in-desc",
94+
suffix = "-success.Rnw", std_err = NULL,
95+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
96+
)
97+
98+
# Rprofile
99+
# because .Rprofile is executed on startup, this must be an installed
100+
# package (to not give an error staight away) not listed in
101+
# test_path("in/DESCRIPTION")
102+
if (Sys.getenv("GITHUB_WORKFLOW") != "Hook tests") {
103+
# seems like .Rprofile with renv activation does not get executed when
104+
# argument to Rscript contains Rprofile ?! Skip this
105+
expect_true(rlang::is_installed("R.cache"))
106+
run_test("deps-in-desc",
107+
"Rprofile",
108+
suffix = "", std_err = "Dependency check failed",
109+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")),
110+
file_transformer = function(files) {
111+
writeLines("R.cache::findCache", files)
112+
fs::file_move(
113+
files,
114+
fs::path(fs::path_dir(files), paste0(".", fs::path_file(files)))
115+
)
116+
}
117+
)
118+
119+
run_test("deps-in-desc",
120+
"Rprofile",
121+
suffix = "", std_err = NULL,
122+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")),
123+
file_transformer = function(files) {
124+
writeLines("utils::head", files)
125+
fs::file_move(
126+
files,
127+
fs::path(fs::path_dir(files), paste0(".", fs::path_file(files)))
128+
)
129+
}
130+
)
131+
}

tests/testthat/test-hook-lintr.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# success
2+
run_test("lintr",
3+
suffix = "-success.R",
4+
std_err = NULL
5+
)
6+
7+
# failure
8+
run_test("lintr", suffix = "-fail.R", std_err = "not lint free")
9+
10+
# warning
11+
run_test(
12+
"lintr",
13+
suffix = "-fail.R", cmd_args = "--warn_only", std_err = NULL
14+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# success
2+
run_test(
3+
"no-browser-statement",
4+
suffix = "-success.R",
5+
std_err = NULL
6+
)
7+
8+
# failure
9+
run_test(
10+
"no-browser-statement",
11+
suffix = "-fail.R",
12+
std_err = "contains a `browser()` statement."
13+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# success
2+
run_test(
3+
"no-debug-statement",
4+
suffix = "-success.R",
5+
std_err = NULL
6+
)
7+
8+
# failure
9+
run_test(
10+
"no-debug-statement",
11+
suffix = "-fail.R",
12+
std_err = "contains a `debug()` or `debugonce()` statement."
13+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# success
2+
run_test(
3+
"no-print-statement",
4+
suffix = "-success.R",
5+
std_err = NULL
6+
)
7+
8+
# failure
9+
run_test(
10+
"no-print-statement",
11+
suffix = "-fail.R",
12+
std_err = "contains a `print()` statement."
13+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
run_test("parsable-R",
2+
suffix = "-success.R",
3+
std_err = NULL
4+
)
5+
6+
run_test("parsable-R",
7+
suffix = "-success.Rmd",
8+
std_err = NULL
9+
)
10+
11+
# failure
12+
run_test("parsable-R", suffix = "-fail.R", std_out = "Full context", std_err = "1 1")
13+
14+
run_test(
15+
"parsable-R",
16+
suffix = "-fail.Rmd",
17+
std_out = "parsable-R-fail.Rmd",
18+
std_err = "1 1"
19+
)

tests/testthat/test-hook-pkgdown.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# success index
2+
run_test("pkgdown",
3+
file_name = c(
4+
"man/autoudpate.Rd" = "autoupdate.Rd",
5+
"_pkgdown.yml" = "_pkgdown-index.yml",
6+
"DESCRIPTION" = "DESCRIPTION"
7+
),
8+
suffix = "", std_err = NULL
9+
)
10+
11+
# failed index
12+
run_test("pkgdown",
13+
file_name = c(
14+
"man/flie-true.Rd" = "flie-true.Rd",
15+
"_pkgdown.yml" = "_pkgdown-index.yml",
16+
"DESCRIPTION" = "DESCRIPTION"
17+
),
18+
suffix = "",
19+
std_err = "topic must be a known"
20+
)
21+
22+
# failed articles
23+
run_test("pkgdown",
24+
file_name = c(
25+
"vignettes/pkgdown.Rmd" = "pkgdown.Rmd",
26+
"_pkgdown.yml" = "_pkgdown-articles.yml",
27+
"DESCRIPTION" = "DESCRIPTION"
28+
),
29+
suffix = "",
30+
std_err = "why-use-hooks"
31+
)
32+
33+
# success index and article
34+
run_test("pkgdown",
35+
file_name = c(
36+
"man/autoudpate.Rd" = "autoupdate.Rd",
37+
"vignettes/pkgdown.Rmd" = "pkgdown.Rmd",
38+
"_pkgdown.yml" = "_pkgdown-index-articles.yml",
39+
"DESCRIPTION" = "DESCRIPTION"
40+
),
41+
suffix = "",
42+
std_err = NULL
43+
)

0 commit comments

Comments
 (0)