Skip to content

Commit

Permalink
Merge branch 'travis'
Browse files Browse the repository at this point in the history
  • Loading branch information
robertzk committed Mar 1, 2015
2 parents 540e963 + 4fd9fde commit 064a944
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ before_install:
- "./travis-tool.sh bootstrap"
install:
- "./travis-tool.sh install_deps"
- "./travis-tool.sh install_r microbenchmark knitr testthat"
- "./travis-tool.sh install_r microbenchmark testthat"
- "./travis-tool.sh install_github jimhester/covr"
script: "./travis-tool.sh run_tests"
after_failure:
Expand Down
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ LazyData: true
Imports:
stringr
Suggests:
knitr,
microbenchmark,
testthat
Roxygen: list(wrap = FALSE)
6 changes: 4 additions & 2 deletions R/super.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ super <- function(...) {
# TODO: (RK) Error on anonymous function calls.
fn <- as.character(sys.call(-1)[[1]])

env <- parent.env(parent.frame(2))
env <- parent.frame(2)

first <- TRUE
while (!identical(env, emptyenv())) {
if (exists(fn, envir = env, inherits = FALSE)) {
super_fn <- get(fn, envir = env, inherits = FALSE)
if (is.function(super_fn)) {
return(do.call(fn, eval(substitute(alist(...))), envir = env))
if (first) { first <- FALSE }
else { return(do.call(fn, eval(substitute(alist(...))), envir = env)) }
}
}
env <- parent.env(env)
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-super.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,24 @@ test_that("it can call with different super arguments", {
expect_equal(calls, c(1L, 2L))
})

test_that("it can call without executing twice from a non-base call", {
calls <- integer(0)
function1 <- function(x) {
calls <<- c(calls, x)
}

function2 <- function() {
function1 <- function(y) {
calls <<- c(calls, y)
super(2)
}
local({
function1(1)
})
}
function2()

expect_equal(calls, c(1L, 2L))
})


0 comments on commit 064a944

Please sign in to comment.