Skip to content

Commit cec1949

Browse files
committed
Use doctest: add doctests for utility functions
1 parent a870ede commit cec1949

9 files changed

+68
-4
lines changed

R/utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -13,9 +13,12 @@
13
#' oo <- options(onetime.dir = tempdir(check = TRUE))
13
#' oo <- options(onetime.dir = tempdir(check = TRUE))
14
#' id <- sample(10000L, 1)
14
#' id <- sample(10000L, 1)
15
#'
15
#'
16+
#' @expect message("will")
16
#' onetime_message("will be shown", id = id)
17
#' onetime_message("will be shown", id = id)
18+
#' @expect silent()
17
#' onetime_message("won't be shown", id = id)
19
#' onetime_message("won't be shown", id = id)
18
#' onetime_reset(id = id)
20
#' onetime_reset(id = id)
21+
#' @expect message("will")
19
#' onetime_message("will be shown", id = id)
22
#' onetime_message("will be shown", id = id)
20
#'
23
#'
21
#' onetime_reset(id = id)
24
#' onetime_reset(id = id)
@@ -58,7 +61,9 @@ onetime_reset <- function (
58
#' oo <- options(onetime.dir = tempdir(check = TRUE))
61
#' oo <- options(onetime.dir = tempdir(check = TRUE))
59
#' id <- sample(10000L, 1)
62
#' id <- sample(10000L, 1)
60
#'
63
#'
64+
#' @expect true()
61
#' onetime_mark_as_done(id = id)
65
#' onetime_mark_as_done(id = id)
66+
#' @expect silent()
62
#' onetime_message("Won't be shown", id = id)
67
#' onetime_message("Won't be shown", id = id)
63
#'
68
#'
64
#' onetime_reset(id = id)
69
#' onetime_reset(id = id)
@@ -86,8 +91,10 @@ onetime_mark_as_done <- function (
86
#' oo <- options(onetime.dir = tempdir(check = TRUE))
91
#' oo <- options(onetime.dir = tempdir(check = TRUE))
87
#' id <- sample(10000L, 1)
92
#' id <- sample(10000L, 1)
88
#'
93
#'
94+
#' @expect false()
89
#' onetime_been_done(id = id)
95
#' onetime_been_done(id = id)
90
#' onetime_message("Creating an ID", id = id)
96
#' onetime_message("Creating an ID", id = id)
97+
#' @expect true()
91
#' onetime_been_done(id = id)
98
#' onetime_been_done(id = id)
92
#'
99
#'
93
#' onetime_reset(id = id)
100
#' onetime_reset(id = id)
@@ -129,8 +136,11 @@ onetime_been_done <- function (
129
#' @export
136
#' @export
130
#'
137
#'
131
#' @doctest
138
#' @doctest
139+
#'
140+
#' @expect match("my-folder$")
132
#' onetime_dir("my-folder")
141
#' onetime_dir("my-folder")
133
#'
142
#'
143+
#' @omit
134
#' oo <- options(onetime.dir = tempdir(check = TRUE))
144
#' oo <- options(onetime.dir = tempdir(check = TRUE))
135
#' onetime_dir("my-folder")
145
#' onetime_dir("my-folder")
136
#' options(oo)
146
#' options(oo)

man/onetime_been_done.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/onetime_dir.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/onetime_mark_as_done.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/onetime_reset.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by doctest: do not edit by hand
2+
# Please edit file in R/utils.R
3+
4+
test_that("Doctest: onetime_been_done", {
5+
# Created from @doctest for `onetime_been_done`
6+
# Source file: R/utils.R
7+
# Source line: 90
8+
oo <- options(onetime.dir = tempdir(check = TRUE))
9+
id <- sample(10000L, 1)
10+
expect_false(onetime_been_done(id = id))
11+
onetime_message("Creating an ID", id = id)
12+
expect_true(onetime_been_done(id = id))
13+
onetime_reset(id = id)
14+
options(oo)
15+
})
16+
Lines changed: 10 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Generated by doctest: do not edit by hand
2+
# Please edit file in R/utils.R
3+
4+
test_that("Doctest: onetime_dir", {
5+
# Created from @doctest for `onetime_dir`
6+
# Source file: R/utils.R
7+
# Source line: 138
8+
expect_match(onetime_dir("my-folder"), "my-folder$")
9+
})
10+
Lines changed: 15 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by doctest: do not edit by hand
2+
# Please edit file in R/utils.R
3+
4+
test_that("Doctest: onetime_mark_as_done", {
5+
# Created from @doctest for `onetime_mark_as_done`
6+
# Source file: R/utils.R
7+
# Source line: 60
8+
oo <- options(onetime.dir = tempdir(check = TRUE))
9+
id <- sample(10000L, 1)
10+
expect_true(onetime_mark_as_done(id = id))
11+
expect_silent(onetime_message("Won't be shown", id = id))
12+
onetime_reset(id = id)
13+
options(oo)
14+
})
15+
Lines changed: 17 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by doctest: do not edit by hand
2+
# Please edit file in R/utils.R
3+
4+
test_that("Doctest: onetime_reset", {
5+
# Created from @doctest for `onetime_reset`
6+
# Source file: R/utils.R
7+
# Source line: 12
8+
oo <- options(onetime.dir = tempdir(check = TRUE))
9+
id <- sample(10000L, 1)
10+
expect_message(onetime_message("will be shown", id = id), "will")
11+
expect_silent(onetime_message("won't be shown", id = id))
12+
onetime_reset(id = id)
13+
expect_message(onetime_message("will be shown", id = id), "will")
14+
onetime_reset(id = id)
15+
options(oo)
16+
})
17+

0 commit comments

Comments
 (0)