Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Fix up tests for change in all.equal behavior
Browse files Browse the repository at this point in the history
R-devel (will be R 3.2.0) has a change in behavior of all.equal for environments.
This change fixes the tests for this new behavior.
  • Loading branch information
wch committed Sep 18, 2014
1 parent aaaf579 commit 70336bf
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/testthat/test-ggvis.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
context("ggvis")

test_that("plot the same regardless of order data/props added", {
# Recursively crawl a list and replace any environments with a special
# environment. This is a workaround for a change in behavior in R 3.2.0
# for all.equal when given two environments.
blank_envs <- function(x) {
replacement_env <- new.env(parent = emptyenv())

x[] <- lapply(x, function(val) {
if (is.environment(val)) replacement_env
else if (is.list(val)) blank_envs(val)
else val
})

x
}

df <- data.frame(x = 1:10, y = 10:1)
plots <- list(
df %>% ggvis(~x, ~y) %>% layer_points(),
Expand All @@ -9,12 +24,17 @@ test_that("plot the same regardless of order data/props added", {
ggvis() %>% add_data(df) %>% add_props(~x, ~y) %>% layer_points(),
ggvis() %>% add_data(df) %>% add_props(~x) %>% layer_points(y = ~y)
)
plots <- blank_envs(plots)

marks <- lapply(plots, function(x) x$marks[[1]])
props <- lapply(marks, "[[", "props")
data <- lapply(marks, function(x) x$data())

for (i in seq_along(marks)) {
expect_equal(props[[i]][c("x.update", "y.update")], props(~x, ~y))
expect_equal(
props[[i]][c("x.update", "y.update")],
blank_envs(props(~x, ~y))
)
expect_equal(data[[i]], df)
}
})

0 comments on commit 70336bf

Please sign in to comment.