Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use doctest: add doctests for onetime_do() and onetime_only()
- Loading branch information
1 parent
cec1949
commit d3be66f
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
# Generated by doctest: do not edit by hand | |||
# Please edit file in R/onetime.R | |||
|
|||
test_that("Doctest: onetime_do", { | |||
# Created from @doctest for `onetime_do` | |||
# Source file: R/onetime.R | |||
# Source line: 39 | |||
oo <- options(onetime.dir = tempdir(check = TRUE)) | |||
id <- sample(10000L, 1L) | |||
for (n in 1:3) { | |||
expect_output(onetime_do(print("printed once"), id = id), regexp = if (n == | |||
1L) "once" else NA) | |||
} | |||
id2 <- sample(10000L, 1L) | |||
expiry <- as.difftime(1, units = "secs") | |||
onetime_do(print("Expires quickly, right?"), id = id2, expiry = expiry) | |||
Sys.sleep(2) | |||
expect_silent(onetime_do(print("This won't be shown..."), id = id2)) | |||
expect_output(onetime_do(print("... but this will"), id = id2, expiry = expiry), | |||
"but this will") | |||
onetime_reset(id = id) | |||
onetime_reset(id = id2) | |||
options(oo) | |||
}) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
# Generated by doctest: do not edit by hand | |||
# Please edit file in R/onetime.R | |||
|
|||
test_that("Doctest: onetime_only", { | |||
# Created from @doctest for `onetime_only` | |||
# Source file: R/onetime.R | |||
# Source line: 95 | |||
oo <- options(onetime.dir = tempdir(check = TRUE)) | |||
id <- sample(10000L, 1) | |||
sample_once <- onetime_only(sample, id = id) | |||
expect_length(sample_once(1:10), 10) | |||
expect_null(sample_once(1:10)) | |||
onetime_reset(id) | |||
options(oo) | |||
}) | |||
|