Skip to content

Commit

Permalink
Test of new eval-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mailund committed Feb 28, 2018
1 parent 079392d commit 26d59da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/loop-transformation.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# we would otherwise get a complaint that `escape` is not defined. Everywhere
# when we actually call a `escape` function, it is a continuation from calls to
# `callCC`.
escape <- function(x) x
escape <- function(x) x # nocov

## Test for possibility of transformation #########################################

Expand Down Expand Up @@ -48,7 +48,7 @@ can_call_be_transformed <- function(call_name, call_arguments,
"are tail-recursive, so such expressions are not analysed and left alone in ",
"transformations."
),
call = expr
call = rlang::expr(eval(!!! call_arguments))
)
warning(msg)
return(TRUE) # get out, and hope the user knows what he is doing...
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-loop-transformation.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,22 @@ test_that("we can handle `with` expressions", {
expect_equal(f(x), transformed_f(x))
}
})

test_that("we warn about eval expressions, but leave them alone", {
# a valid tail-recurive function
f <- function(x) if (x < 0) x else eval(quote(f(-1)))
# an invalid tail-recursive function
g <- function(x) if (x < 0) x else eval(quote(g(-1) + g(-2)))

expect_warning(
can_loop_transform(f),
"This function contains an eval-expression.*"
)
expect_warning(
can_loop_transform(g),
"This function contains an eval-expression.*"
)

# I'm not sure how to easilly check that eval-expressions are
# left alone, though...
})

0 comments on commit 26d59da

Please sign in to comment.