-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtest-setup.R
More file actions
121 lines (111 loc) · 3.37 KB
/
Copy pathtest-setup.R
File metadata and controls
121 lines (111 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
test_that("snippet generation works for roxygen", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
usethis::use_package("R", "Depends", "3.6.0")
expect_error(
out <- capture_output(snippet_generate("additional-deps-roxygenize")),
NA,
)
expect_equal(out, "")
usethis::use_package("styler")
expect_error(
out <- capture_output(snippet_generate("additional-deps-roxygenize")),
NA,
)
expect_match(
out, " - id: roxygenize\n.* - styler\n$",
)
desc::desc_set("Remotes", "r-lib/styler")
expect_warning(
out <- capture_output(snippet_generate("additional-deps-roxygenize")),
"you have remote dependencies "
)
expect_match(
out, " - id: roxygenize\n.* - styler\n$",
)
})
test_that("snippet generation works for lintr", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
usethis::use_package("R", "Depends", "3.6.0")
expect_error(
out <- capture_output(snippet_generate("additional-deps-lintr")),
NA,
)
expect_equal(out, paste0(
" - id: lintr\n",
" # lintr requires loading pkg -> add dependencies (incl. Suggests) from DESCRIPTION\n",
" args: [--load_package]\n",
" additional_dependencies:\n",
" - testthat\n",
""
))
usethis::use_package("styler")
expect_error(
out <- capture_output(snippet_generate("additional-deps-lintr")),
NA,
)
expect_match(
out, " - id: lintr\n.* - styler\n$",
)
desc::desc_set("Remotes", "r-lib/styler")
expect_warning(
out <- capture_output(snippet_generate("additional-deps-roxygenize")),
"you have remote dependencies "
)
expect_match(
out, " - id: roxygenize\n.* - styler\n$",
)
})
test_that("snippet generation only includes hard dependencies", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE,
install_hooks = FALSE, open = FALSE
)
usethis::use_package("styler")
usethis::use_package("lintr", type = "Suggest")
expect_warning(
out <- capture_output(snippet_generate("additional-deps-roxygenize")),
NA
)
expect_match(
out, " - id: roxygenize\n.* - styler\n$",
)
})
test_that("GitHub Action CI setup works", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
use_precommit_config(
root = getwd(),
open = FALSE, verbose = FALSE
)
expect_error(use_ci("stuff", root = getwd()), "must be one of")
use_ci("gha", root = getwd())
expect_true(file_exists(".github/workflows/pre-commit.yaml"))
})
test_that("Pre-commit CI GitHub Action template is parsable", {
expect_error(
yaml::read_yaml(system.file("pre-commit-gha.yaml", package = "precommit")),
NA
)
})
test_that("Pre-commit CI setup works", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
use_precommit_config(
root = getwd(),
open = FALSE, verbose = FALSE
)
use_ci(root = getwd(), open = FALSE)
expect_false(file_exists(".github/workflows/pre-commit.yaml"))
})
test_that("Pre-commit CI setup works", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
expect_error(use_ci(root = getwd(), open = FALSE), "o `.pre-commit-config.yaml`")
})