forked from r-lib/usethis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-description.R
86 lines (67 loc) 路 2.43 KB
/
test-description.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
# use_description_defaults() ----------------------------------------------
test_that("user's fields > usethis defaults", {
d <- use_description_defaults("pkg", fields = list(Title = "TEST1", URL = "TEST1"))
expect_equal(d$Title, "TEST1")
expect_equal(d$URL, "TEST1")
expect_equal(d$Version, "0.0.0.9000")
})
test_that("usethis options > usethis defaults", {
withr::local_options(list(
usethis.description = list(License = "TEST")
))
d <- use_description_defaults()
expect_equal(d$License, "TEST")
expect_equal(d$Version, "0.0.0.9000")
})
test_that("devtools options can be picked up", {
withr::local_options(list(
usethis.description = NULL,
devtools.desc = list(License = "TEST")
))
d <- use_description_defaults()
expect_equal(d$License, "TEST")
expect_equal(d$Version, "0.0.0.9000")
})
test_that("user's fields > options > defaults", {
withr::local_options(list(
usethis.description = list(License = "TEST1", Title = "TEST1")
))
d <- use_description_defaults("pkg", fields = list(Title = "TEST2"))
expect_equal(d$Title, "TEST2")
expect_equal(d$License, "TEST1")
expect_equal(d$Version, "0.0.0.9000")
})
test_that("automatically converts person object to text", {
d <- use_description_defaults("pkg", fields = list(`Authors@R` = person("H", "W")))
expect_equal(d$`Authors@R`, "person(given = \"H\",\n family = \"W\")")
})
test_that("can set package", {
d <- use_description_defaults(package = "TEST")
expect_equal(d$Package, "TEST")
})
# use_description ---------------------------------------------------------
test_that("creation succeeds even if options are broken", {
withr::local_options(list(usethis.description = list(
`Authors@R` = 'person('
)))
create_local_project()
expect_error(use_description(), NA)
})
test_that("default description is tidy", {
withr::local_options(list(usethis.description = NULL, devtools.desc = NULL))
create_local_package()
before <- readLines(proj_path("DESCRIPTION"))
use_tidy_description()
after <- readLines(proj_path("DESCRIPTION"))
expect_equal(before, after)
})
test_that("valid CRAN names checked", {
withr::local_options(list(usethis.description = NULL, devtools.desc = NULL))
create_local_package(dir = file_temp(pattern = "invalid_pkg_name"))
expect_error(use_description(check_name = FALSE), NA)
expect_error(
use_description(check_name = TRUE),
"is not a valid package name",
class = "usethis_error"
)
})