-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TESTS: add test for name clashing of globals in local() environments [#…
…608]
- Loading branch information
1 parent
968ec7f
commit 121566e
Showing
5 changed files
with
50 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
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
source("incl/start.R") | ||
library("listenv") | ||
oopts <- c(oopts, options( | ||
future.globals.resolve = TRUE, | ||
future.globals.onMissing = "error" | ||
)) | ||
|
||
okeep <- list() | ||
|
||
message("*** Globals inside local() environments ...") | ||
|
||
for (strategy in supportedStrategies()) { | ||
message(sprintf("- plan('%s') ...", strategy)) | ||
plan(strategy) | ||
|
||
## Closures with local globals of the same name | ||
g <- local({ a <- 1; function() a }) | ||
h <- local({ a <- 2; function() a }) | ||
truth <- h() + g() | ||
print(truth) | ||
|
||
## Fixed in future (>= 1.25.0-9013) with globals (>= 0.14.0.9004) | ||
## Previously, 'a' of h() would overwrite 'a' of g(), resulting | ||
## in g() == 2, rather than g() == 1. | ||
## https://github.com/HenrikBengtsson/future/issues/608 | ||
if (is.null(getOption("future.globals.keepWhere")) && packageVersion("globals") >= "0.14.0.9004") { | ||
okeep <- options(future.globals.keepWhere = TRUE) | ||
} | ||
f <- future(h() + g()) | ||
v <- value(f) | ||
print(v) | ||
|
||
if (!strategy %in% c("sequential", "multicore") || (packageVersion("globals") >= "0.14.0.9004") && getOption("future.globals.keepWhere", FALSE)) { | ||
stopifnot(identical(v, truth)) | ||
options(okeep) | ||
} else { | ||
stopifnot(identical(v, h() + h())) | ||
} | ||
} ## for (strategy ...) | ||
|
||
message("*** Globals inside local() environments ... DONE") | ||
|
||
source("incl/end.R") |