Skip to content

Commit

Permalink
solved subtle bugs in extension loader
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanderloo committed Aug 21, 2019
1 parent 0f4c417 commit 5592c36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Description: Provides a lightweight (zero-dependency) and easy to use
configurable output printing. Compare computed output with output stored
with the package. Run tests in parallel. Extensible by other packages.
Report side effects.
Version: 0.9.6.14
Version: 0.9.6.15
URL: https://github.com/markvanderloo/tinytest
BugReports: https://github.com/markvanderloo/tinytest/issues
Imports: parallel, utils
Expand Down
17 changes: 9 additions & 8 deletions pkg/R/expectations.R
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,15 @@ capture_se <- function(fun, env){

# internal function, to be called by run_test_file after local capture.
report_envvar <- function(env){
if ( isTRUE(env$sidefx[['envvar']]) ){
current <- Sys.getenv()
out <- envdiff(env$envvar, current)
env$envvar <- current
out
} else {
NULL
}
if ( !isTRUE(env$sidefx[['envvar']]) ) return(NULL)

old <- env$envvar
current <- Sys.getenv()
if (identical(old, current)) return(NULL)

out <- envdiff(env$envvar, current)
env$envvar <- current
out
}

# internal function, to be called by run_test_file after local capture.
Expand Down
22 changes: 10 additions & 12 deletions pkg/R/tinytest.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ output <- function(){


capture <- function(fun, env){
# avoid lazy eval when looping over functions as a variable
# e.g. when loading extensions.
force(fun)

function(...){
out <- fun(...)
if ( inherits(out, "tinytest") ){
Expand All @@ -77,8 +81,8 @@ capture <- function(fun, env){
# improve the call's format
if (!is.na(out) && env$lst - env$fst >=3)
attr(out,"call") <- match.call(fun)
env$add(out)
attr(out,"env") <- env
env$add(out)
attr(out,"env") <- env
}
out
}
Expand Down Expand Up @@ -242,23 +246,18 @@ add_locally_masked_functions <- function(envir, output){
## picked up by add_masked_extensions
library_loading_extensions <- function(envir, output){
function(...){
loaded <- .packages()
out <- library(...)
# there could be multiple pkgs loaded, curtesey of 'Depends'
pkgs <- setdiff(.packages(), loaded)
add_masked_extensions(pkgs, envir, output)
out <- base::library(...)
add_masked_extensions(out, envir, output)
envir$tinytest_runtime <- TRUE
invisible(out)
}
}

require_loading_extensions <- function(envir, output){
function(...){
loaded <- .packages()
out <- base::require(...)
# there could be multiple pkgs loaded, curtesey of 'Depends'
pkgs <- setdiff(.packages(), loaded)
add_masked_extensions(pkgs, envir, output)
add_masked_extensions(.packages(), envir, output)
envir$tinytest_runtime <- TRUE
invisible(out)
}
Expand All @@ -279,9 +278,8 @@ add_masked_extensions <- function(pkgs, envir, output){
, pkg, e$message)
warning(msg, call.=FALSE)
})

envir[[func]] <- capture(fun, output)
# run once to materialize the function
tryCatch(envir[[func]](), warning=function(w){}, error=function(e){})
}
}
}
Expand Down

0 comments on commit 5592c36

Please sign in to comment.