-
Notifications
You must be signed in to change notification settings - Fork 285
/
test-tidyverse.R
90 lines (78 loc) · 2.6 KB
/
test-tidyverse.R
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
test_that("use_tidy_description() alphabetises dependencies and remotes", {
pkg <- create_local_package()
use_package("usethis")
use_package("desc")
use_package("withr", "Suggests")
use_package("gh", "Suggests")
desc::desc_set_remotes(c("r-lib/styler", "jimhester/lintr"))
use_tidy_description()
desc <- read_utf8(proj_path("DESCRIPTION"))
expect_gt(grep("usethis", desc), grep("desc", desc))
expect_gt(grep("withr", desc), grep("gh", desc))
expect_gt(grep("r\\-lib\\/styler", desc), grep("jimhester\\/lintr", desc))
})
test_that("use_tidy_dependencies() isn't overly informative", {
skip_if_offline("github.com")
create_local_package(fs::path_temp("tidydeps"))
use_package_doc()
withr::local_options(usethis.quiet = FALSE)
expect_snapshot(use_tidy_dependencies())
})
test_that("use_tidy_GITHUB-STUFF() adds and Rbuildignores files", {
local_interactive(FALSE)
create_local_package()
use_git()
with_mock(
target_repo_spec = function(...) "OWNER/REPO", {
use_tidy_contributing()
use_tidy_support()
}
)
use_tidy_issue_template()
use_tidy_coc()
expect_proj_file(".github/CONTRIBUTING.md")
expect_proj_file(".github/ISSUE_TEMPLATE/issue_template.md")
expect_proj_file(".github/SUPPORT.md")
expect_proj_file(".github/CODE_OF_CONDUCT.md")
expect_true(is_build_ignored("^\\.github$"))
})
test_that("use_tidy_github() adds and Rbuildignores files", {
local_interactive(FALSE)
create_local_package()
use_git()
with_mock(
target_repo_spec = function(...) "OWNER/REPO",
{
use_tidy_github()
}
)
expect_proj_file(".github/CONTRIBUTING.md")
expect_proj_file(".github/ISSUE_TEMPLATE/issue_template.md")
expect_proj_file(".github/SUPPORT.md")
expect_proj_file(".github/CODE_OF_CONDUCT.md")
expect_true(is_build_ignored("^\\.github$"))
})
test_that("styling the package works", {
skip_if(getRversion() < 3.2)
skip_if_no_git_user()
skip_if_not_installed("styler")
pkg <- create_local_package()
use_r("bad_style")
path_to_bad_style <- proj_path("R/bad_style.R")
write_utf8(path_to_bad_style, "a++2\n")
capture_output(use_tidy_style())
expect_identical(read_utf8(path_to_bad_style), "a + +2")
file_delete(path_to_bad_style)
})
test_that("styling of non-packages works", {
skip_if(getRversion() < 3.2)
skip_if_no_git_user()
skip_if_not_installed("styler")
proj <- create_local_project()
path_to_bad_style <- proj_path("R/bad_style.R")
use_r("bad_style")
write_utf8(path_to_bad_style, "a++22\n")
capture_output(use_tidy_style())
expect_identical(read_utf8(path_to_bad_style), "a + +22")
file_delete(path_to_bad_style)
})