Skip to content

Commit cb84f26

Browse files
committed
Refactor tests
1 parent 3ee161f commit cb84f26

11 files changed

Lines changed: 92 additions & 227 deletions

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- The JOSS paper is now linked as an external pkgdown article instead of being
44
rebuilt as a package vignette.
55
- `cff_gha_update()` now uses `path` when updating `.Rbuildignore`.
6+
- `cff_write()` now formats the `inst/CITATION` update message correctly.
67

78
# cffr 1.4.1
89

R/cff_write.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ auto_r_citation <- function(
188188

189189
# Otherwise update `inst/CITATION`.
190190
if (verbose) {
191-
cli::cat_rule("Updating {.file inst/CITATION}", col = "cyan", line = 2)
191+
cli::cat_rule(
192+
cli::format_inline("Updating {.file inst/CITATION}"),
193+
col = "cyan",
194+
line = 2
195+
)
192196
}
193197
cffobj <- cff_read(outfile)
194198
fpath <- "./inst/CITATION"

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
},
235235
"isPartOf": "https://ropensci.org",
236236
"keywords": ["attribution", "citation", "credit", "citation-files", "cff", "metadata", "citation-file-format", "cran", "r", "r-package", "ropensci", "rstats", "r-cran"],
237-
"fileSize": "986.856KB",
237+
"fileSize": "983.123KB",
238238
"citation": [
239239
{
240240
"@type": "ScholarlyArticle",

tests/testthat/_snaps/cff_write.md

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
given-names: Marc
7878
email: marcbasic@gmail.com
7979

80-
# Test in mock package
80+
# cff_write creates and updates inst/CITATION in a mock package
8181

8282
Code
8383
auto_cit1
@@ -113,103 +113,3 @@
113113
version = {1.0.0},
114114
}
115115

116-
---
117-
118-
Code
119-
cffobj
120-
Output
121-
cff-version: 1.2.0
122-
message: 'To cite package "manyurls" in publications use:'
123-
type: software
124-
license: GPL-3.0-only
125-
title: 'manyurls: A lot of urls'
126-
version: 1.0.0
127-
doi: 10.1111/2041-210X.12469
128-
identifiers:
129-
- type: url
130-
value: https://r-forge.r-project.org/projects/test/
131-
- type: url
132-
value: http://google.ru
133-
- type: url
134-
value: https://gitlab.com/r-packages/behaviorchange
135-
abstract: This package has many urls. Specifically, 1 Bug Reports and 6 URLs. Expected
136-
is to have 1 repository-code, 1 url and 3 URLs, since there is 1 duplicate and 1
137-
invalid url.
138-
authors:
139-
- family-names: Basic
140-
given-names: Marc
141-
email: marcbasic@gmail.com
142-
preferred-citation:
143-
type: article
144-
title: 'RNeXML: A Package for Reading and Writing Richly Annotated Phylogenetic,
145-
Character, and Trait Data in R'
146-
authors:
147-
- family-names: Boettiger
148-
given-names: Carl
149-
- family-names: Chamberlain
150-
given-names: Scott
151-
- family-names: Vos
152-
given-names: Rutger
153-
- family-names: Lapp
154-
given-names: Hilmar
155-
journal: Methods in Ecology and Evolution
156-
year: '2016'
157-
volume: '7'
158-
doi: 10.1111/2041-210X.12469
159-
start: '352'
160-
end: '357'
161-
repository-code: https://github.com/test/package
162-
url: https://test.github.io/package/
163-
contact:
164-
- family-names: Basic
165-
given-names: Marc
166-
email: marcbasic@gmail.com
167-
references:
168-
- type: book
169-
title: 'ggplot2: Elegant Graphics for Data Analysis'
170-
authors:
171-
- family-names: Wickham
172-
given-names: Hadley
173-
publisher:
174-
name: Springer-Verlag New York
175-
year: '2016'
176-
isbn: 978-3-319-24277-4
177-
url: https://ggplot2.tidyverse.org
178-
179-
---
180-
181-
Code
182-
toBibtex(cit)
183-
Output
184-
@Article{,
185-
title = {{RNeXML}: {A} Package for Reading and Writing Richly Annotated Phylogenetic, Character, and Trait Data in {R}},
186-
journal = {Methods in Ecology and Evolution},
187-
author = {Carl Boettiger and Scott Chamberlain and Rutger Vos and Hilmar Lapp},
188-
year = {2016},
189-
volume = {7},
190-
pages = {352--357},
191-
doi = {10.1111/2041-210X.12469},
192-
}
193-
194-
@Book{,
195-
author = {Hadley Wickham},
196-
title = {ggplot2: Elegant Graphics for Data Analysis},
197-
publisher = {Springer-Verlag New York},
198-
year = {2016},
199-
isbn = {978-3-319-24277-4},
200-
url = {https://ggplot2.tidyverse.org},
201-
}
202-
203-
---
204-
205-
Code
206-
toBibtex(a_bib)
207-
Output
208-
@Misc{basic,
209-
title = {manyurls: A lot of urls},
210-
author = {Marc Basic},
211-
url = {https://test.github.io/package/},
212-
abstract = {This package has many urls. Specifically, 1 Bug Reports and 6 URLs. Expected is to have 1 repository-code, 1 url and 3 URLs, since there is 1 duplicate and 1 invalid url.},
213-
version = {1.0.0},
214-
}
215-
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
local_mock_package <- function(
2+
description = "DESCRIPTION_basic",
3+
rbuildignore = FALSE,
4+
local_dir = TRUE,
5+
.local_envir = parent.frame()
6+
) {
7+
path <- withr::local_tempdir(
8+
pattern = "mock-pack-",
9+
.local_envir = .local_envir
10+
)
11+
desc_src <- system.file("examples", description, package = "cffr")
12+
desc_dst <- file.path(path, "DESCRIPTION")
13+
14+
if (!nzchar(desc_src)) {
15+
stop("Can't find example DESCRIPTION file: ", description, call. = FALSE)
16+
}
17+
if (!file.copy(desc_src, desc_dst) || !file.exists(desc_dst)) {
18+
stop("Can't create mock package DESCRIPTION.", call. = FALSE)
19+
}
20+
21+
if (isTRUE(rbuildignore)) {
22+
rbuildignore_path <- file.path(path, ".Rbuildignore")
23+
if (!file.create(rbuildignore_path, showWarnings = FALSE)) {
24+
stop("Can't create mock package .Rbuildignore.", call. = FALSE)
25+
}
26+
}
27+
28+
if (isTRUE(local_dir)) {
29+
withr::local_dir(path, .local_envir = .local_envir)
30+
}
31+
32+
path
33+
}

tests/testthat/test-as_bibentry.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,7 @@ test_that("as_bibentry default", {
6969
test_that("as_bibentry NULL", {
7070
skip_on_cran()
7171

72-
new_dir <- withr::local_tempdir(pattern = "mock-pack-")
73-
withr::local_dir(new_dir)
74-
75-
# Move files
76-
file.copy(
77-
system.file("examples/DESCRIPTION_basic", package = "cffr"),
78-
to = "DESCRIPTION"
79-
)
72+
local_mock_package()
8073

8174
# Get bibentry
8275
a_bib <- as_bibentry()

tests/testthat/test-as_cff_person.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ test_that("No valid emails", {
146146

147147
p2 <- as_cff_person(pp2)
148148

149-
expect_equal(p, as_cff_person(person(given = "John", family = "Doe")))
149+
expect_equal(p, p2)
150150
})
151151

152152
test_that("Can extract comments from format", {

tests/testthat/test-cff_create.R

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ test_that("Test installed packages", {
1111
test_that("Test indev", {
1212
skip_on_cran()
1313

14-
new_dir <- withr::local_tempdir(pattern = "mock-pack-")
15-
withr::local_dir(new_dir)
16-
17-
# Move files
18-
file.copy(
19-
system.file("examples/DESCRIPTION_basic", package = "cffr"),
20-
to = "DESCRIPTION"
21-
)
14+
local_mock_package()
2215

2316
a_cff <- cff_create()
2417

@@ -145,20 +138,6 @@ test_that("Default roles on write", {
145138
expect_identical(cf, cf2)
146139
})
147140

148-
test_that("Add new roles", {
149-
p <- system.file("examples/DESCRIPTION_no_URL", package = "cffr")
150-
151-
cf <- cff_create(p, dependencies = FALSE)
152-
cf2 <- cff_create(
153-
p,
154-
authors_roles = c("aut", "cre", "ctb"),
155-
dependencies = FALSE
156-
)
157-
158-
expect_gt(length(cf2$authors), length(cf$authors))
159-
expect_true(cff_validate(cf2, verbose = FALSE))
160-
})
161-
162141
test_that("Add new roles on write", {
163142
p <- system.file("examples/DESCRIPTION_no_URL", package = "cffr")
164143

tests/testthat/test-cff_gha_update.R

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
test_that("cff_gha_update installs a workflow in the requested package", {
22
skip_on_cran()
33

4-
new_dir <- withr::local_tempdir(pattern = "mock-pack-")
5-
6-
# Move files
7-
file.copy(
8-
system.file("examples/DESCRIPTION_many_urls", package = "cffr"),
9-
to = file.path(new_dir, "DESCRIPTION")
4+
new_dir <- local_mock_package(
5+
description = "DESCRIPTION_many_urls",
6+
rbuildignore = TRUE,
7+
local_dir = FALSE
108
)
11-
12-
# Create Rbuildignore
139
rbuildignore <- file.path(new_dir, ".Rbuildignore")
14-
file.create(rbuildignore, showWarnings = FALSE)
1510
expect_true(file_exist_abort(rbuildignore))
1611

1712
# Add action

0 commit comments

Comments
 (0)