Skip to content

Commit 7fbed98

Browse files
committed
Snapshot tests
1 parent a08d0b1 commit 7fbed98

File tree

4 files changed

+103
-24
lines changed

4 files changed

+103
-24
lines changed

tests/testthat/_snaps/criterion.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Formatting
2+
3+
Code
4+
format(is_r_package)
5+
Output
6+
[1] "Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `"
7+
8+
---
9+
10+
Code
11+
is_r_package
12+
Output
13+
Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `
14+
15+
---
16+
17+
Code
18+
is_vcs_root
19+
Output
20+
Root criterion: one of
21+
- contains a directory `.git`
22+
- contains a file `.git` with contents matching `^gitdir: `
23+
- contains a directory `.svn`
24+
25+
---
26+
27+
Code
28+
criteria
29+
Output
30+
$is_rstudio_project
31+
Root criterion: contains a file matching `[.]Rproj$` with contents matching `^Version: ` in the first line
32+
33+
$is_r_package
34+
Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `
35+
36+
$is_remake_project
37+
Root criterion: contains a file `remake.yml`
38+
39+
$is_projectile_project
40+
Root criterion: contains a file `.projectile`
41+
42+
$is_git_root
43+
Root criterion: one of
44+
- contains a directory `.git`
45+
- contains a file `.git` with contents matching `^gitdir: `
46+
47+
$is_svn_root
48+
Root criterion: contains a directory `.svn`
49+
50+
$is_vcs_root
51+
Root criterion: one of
52+
- contains a directory `.git`
53+
- contains a file `.git` with contents matching `^gitdir: `
54+
- contains a directory `.svn`
55+
56+
$is_testthat
57+
Root criterion: directory name is `testthat` (also look in subdirectories: `tests/testthat`, `testthat`)
58+
59+
$from_wd
60+
Root criterion: from current working directory
61+
62+
attr(,"class")
63+
[1] "root_criteria"
64+
65+
---
66+
67+
Code
68+
str(criteria)
69+
Output
70+
List of 9
71+
$ is_rstudio_project : chr "Root criterion: contains a file matching `[.]Rproj$` with contents matching `^Version: ` in the first line"
72+
$ is_r_package : chr "Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `"
73+
$ is_remake_project : chr "Root criterion: contains a file `remake.yml`"
74+
$ is_projectile_project: chr "Root criterion: contains a file `.projectile`"
75+
$ is_git_root : chr [1:3] "Root criterion: one of" "- contains a directory `.git`" "- contains a file `.git` with contents matching `^gitdir: `"
76+
$ is_svn_root : chr "Root criterion: contains a directory `.svn`"
77+
$ is_vcs_root : chr [1:4] "Root criterion: one of" "- contains a directory `.git`" "- contains a file `.git` with contents matching `^gitdir: `" "- contains a directory `.svn`"
78+
$ is_testthat : chr "Root criterion: directory name is `testthat` (also look in subdirectories: `tests/testthat`, `testthat`)"
79+
$ from_wd : chr "Root criterion: from current working directory"
80+
81+
# Combining criteria
82+
83+
Code
84+
comb_crit
85+
Output
86+
Root criterion: one of
87+
- contains a file `DESCRIPTION` with contents matching `^Package: `
88+
- contains a file matching `[.]Rproj$` with contents matching `^Version: ` in the first line
89+

tests/testthat/_snaps/testthat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# is_testthat
2+
3+
Code
4+
is_testthat
5+
Output
6+
Root criterion: directory name is `testthat` (also look in subdirectories: `tests/testthat`, `testthat`)
7+

tests/testthat/test-criterion.R

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,19 @@ test_that("Absolute paths are returned", {
6060
})
6161

6262
test_that("Formatting", {
63-
expect_match(
64-
paste(format(is_r_package), collapse = "\n"),
65-
"^Root criterion: .*DESCRIPTION"
66-
)
67-
expect_output(print(is_r_package), "^Root criterion: .*DESCRIPTION")
68-
expect_output(print(is_vcs_root), "^Root criterion: one of\n- .*[.]git.*\n- .*[.]svn")
69-
})
70-
71-
test_that("Formatting criteria", {
72-
expect_output(
73-
str(criteria),
74-
"^List of "
75-
)
63+
expect_snapshot(format(is_r_package))
64+
expect_snapshot(is_r_package)
65+
expect_snapshot(is_vcs_root)
66+
expect_snapshot(criteria)
67+
expect_snapshot(str(criteria))
7668
})
7769

7870
test_that("Combining criteria", {
79-
skip_on_cran()
80-
8171
comb_crit <- is_r_package | is_rstudio_project
8272

8373
expect_true(is_root_criterion(comb_crit))
8474

85-
expect_match(paste0(format(comb_crit), collapse = "\n"), "\n- .*\n- ")
75+
expect_snapshot(comb_crit)
8676

8777
expect_equal(
8878
find_root(comb_crit, "hierarchy"),

tests/testthat/test-testthat.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
test_that("is_testthat", {
2-
expect_match(
3-
paste(format(is_testthat), collapse = "\n"),
4-
"^.*directory name is `testthat` .* subdirectories.*`tests/testthat`.*`testthat`.*$"
5-
)
6-
expect_match(
7-
paste(format(is_testthat), collapse = "\n"),
8-
"directory name is `testthat` .* subdirectories.*`tests/testthat`.*`testthat`.*"
9-
)
2+
expect_snapshot(is_testthat)
103

114
testthat_path <- normalizePath("package/tests/testthat", winslash = "/")
125
expect_equal(is_testthat$find_file(path = "package"), testthat_path)

0 commit comments

Comments
 (0)