Skip to content

Commit 9d4e007

Browse files
Migrate to the 'testme' test structure
1 parent dae660a commit 9d4e007

File tree

75 files changed

+635
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+635
-117
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: progressr
2-
Version: 0.16.0-9014
2+
Version: 0.16.0-9015
33
Title: An Inclusive, Unifying API for Progress Updates
44
Description: A minimal, unifying API for scripts and packages to report progress updates from anywhere including when using parallel processing. The package is designed such that the developer can to focus on what progress should be reported on without having to worry about how to present it. The end user has full control of how, where, and when to render these progress updates, e.g. in the terminal using utils::txtProgressBar(), cli::cli_progress_bar(), in a graphical user interface using utils::winProgressBar(), tcltk::tkProgressBar() or shiny::withProgress(), via the speakers using beepr::beep(), or on a file system via the size of a file. Anyone can add additional, customized, progression handlers. The 'progressr' package uses R's condition framework for signaling progress updated. Because of this, progress can be reported from almost anywhere in R, e.g. from classical for and while loops, from map-reduce API:s like the lapply() family of functions, 'purrr', 'plyr', and 'foreach'. It will also work with parallel processing via the 'future' framework, e.g. future.apply::future_lapply(), furrr::future_map(), and 'foreach' with 'doFuture'. The package is compatible with Shiny applications.
55
Authors@R: c(person("Henrik", "Bengtsson",

R/testme.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## This runs 'testme' test inst/testme/test-<name>.R scripts
2+
## Don't edit - it was autogenerated by inst/testme/deploy.R
3+
testme <- function(name) {
4+
path <- system.file(package = 'progressr', 'testme', mustWork = TRUE)
5+
Sys.setenv(R_TESTME_PATH = path)
6+
Sys.setenv(R_TESTME_PACKAGE = 'progressr')
7+
Sys.setenv(R_TESTME_NAME = name)
8+
on.exit(Sys.unsetenv('R_TESTME_NAME'))
9+
source(file.path(path, 'run.R'))
10+
}
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
testme <- as.environment("testme")
2+
13
## Undo options
24
## (a) Reset
35
options(oopts0)
6+
47
## (b) Remove added
5-
added <- setdiff(names(options()), names(oopts0))
6-
opts <- vector("list", length = length(added))
7-
names(opts) <- added
8-
options(opts)
8+
local({
9+
added <- setdiff(names(options()), names(oopts0))
10+
opts <- vector("list", length = length(added))
11+
names(opts) <- added
12+
options(opts)
13+
})
14+
915
## (c) Assert that everything was undone
1016
if (!identical(options(), oopts0)) {
1117
message("Failed to undo options:")
@@ -23,11 +29,12 @@ if (!identical(options(), oopts0)) {
2329
value0 <- oopts0[[name]]
2430
value <- oopts[[name]]
2531
if (!identical(value, value0)) {
26-
utils::str(list(name = name, expected = value0, actual = value))
32+
if (testme[["debug"]]) {
33+
utils::str(list(name = name, expected = value0, actual = value))
34+
}
2735
}
2836
}
2937
}
30-
stopifnot(identical(options(), oopts0))
3138

3239

3340
## Undo system environment variables
@@ -53,11 +60,18 @@ if (!identical(Sys.getenv(), oenvs0)) {
5360
value0 <- unname(oenvs0[name])
5461
value <- unname(oenvs[name])
5562
if (!identical(value, value0)) {
56-
utils::str(list(name = name, expected = value0, actual = value))
63+
if (testme[["debug"]]) {
64+
utils::str(list(name = name, expected = value0, actual = value))
65+
}
5766
}
5867
}
5968
}
6069

6170

71+
## Assert undo was successful
72+
if (testme[["debug"]]) {
73+
stopifnot(identical(options(), oopts0))
74+
}
75+
6276
## Undo variables
63-
rm(list = c(setdiff(ls(), ovars)))
77+
rm(list = c(setdiff(ls(envir = globalenv()), ovars)), envir = globalenv())

inst/testme/_epilogue/090.gc.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Travis CI specific: Explicit garbage collection because it
2+
## looks like Travis CI might run out of memory during 'covr'
3+
## testing and we now have so many tests. /HB 2017-01-11
4+
if ("covr" %in% loadedNamespaces()) {
5+
res <- gc()
6+
testme <- as.environment("testme")
7+
if (testme[["debug"]]) print(res)
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
testme <- as.environment("testme")
2+
if (testme[["debug"]]) {
3+
info <- utils::sessionInfo()
4+
message("Session information:")
5+
print(info)
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Look for detritus files
2+
testme <- as.environment("testme")
3+
delta <- diff_connections(get_connections(), testme[["testme_connections"]])
4+
if (any(lengths(delta) > 0)) {
5+
message(sprintf("Detritus connections generated by test %s:", sQuote(testme[["name"]])))
6+
print(delta)
7+
}
8+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Look for detritus files
2+
testme <- as.environment("testme")
3+
path <- dirname(tempdir())
4+
5+
if (basename(path) == "working_dir") {
6+
files <- dir(pattern = "^Rscript", path = path, all.files = TRUE, full.names = TRUE)
7+
if (length(files) > 0L) {
8+
message(sprintf("Detritus 'Rscript*' files generated by test %s:", sQuote(testme[["name"]])))
9+
print(files)
10+
11+
## Remove detritus files produced by this test script, so that
12+
## other test scripts will not fail because of these files.
13+
unlink(files)
14+
15+
## Signal the problem
16+
msg <- sprintf("Detected 'Rscript*' files: [n=%d] %s", length(files), paste(sQuote(basename(files)), collapse = ", "))
17+
## Are detritus files files expected by design on MS Windows?
18+
## If so, produce a warning, otherwise an error
19+
if ("detritus-files" %in% testme[["tags"]] &&
20+
.Platform[["OS.type"]] == "windows") {
21+
warning(msg, immediate. = TRUE)
22+
} else {
23+
stop(msg)
24+
}
25+
}
26+
} else {
27+
message(sprintf("Skipping, because path appears not to be an 'R CMD check' folder: %s", sQuote(path)))
28+
}

inst/testme/_prologue/001.load.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testme <- as.environment("testme")
2+
loadNamespace(testme[["package"]])
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Record original state
2+
ovars <- ls(envir = globalenv())
3+
oenvs <- oenvs0 <- Sys.getenv()
4+
oopts0 <- options()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Private package functions
2+
`%||%` <- progressr:::`%||%`
3+
hpaste <- progressr:::hpaste
4+
mdebug <- progressr:::mdebug
5+
mprint <- progressr:::mprint
6+
mprintf <- progressr:::mprintf
7+
mstr <- progressr:::mstr
8+
query_r_cmd_check <- progressr:::query_r_cmd_check
9+
in_r_cmd_check <- progressr:::in_r_cmd_check
10+
stop_if_not <- progressr:::stop_if_not
11+
printf <- function(...) cat(sprintf(...))
12+
known_progression_handlers <- progressr:::known_progression_handlers

0 commit comments

Comments
 (0)