-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline test files directly into tests #133
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ Imports: | |
methods | ||
Suggests: | ||
covr, | ||
ggplot2, | ||
ggplot2 (>= 3.3.6), | ||
lattice, | ||
rlang, | ||
testthat (>= 3.0.0), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# code errors if stop_on_error == 2L | ||
|
||
Code | ||
evaluate("stop(\"1\")", stop_on_error = 2L) | ||
Condition | ||
Error: | ||
! 1 | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
evaluate_ <- function(text, ...) { | ||
# Trim off leading/trailing new lines and dedent | ||
text <- gsub("^\n {4}", "", text) | ||
text <- gsub("\n {4}", "\n", text) | ||
text <- gsub("\n +$", "", text) | ||
|
||
evaluate(text, ...) | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is used in examples: Line 11 in b2a2689
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks! I'll inline them into the examples too. |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
test_that("all code run, even after error", { | ||
ev <- evaluate(file("error.R")) | ||
ev <- evaluate_('stop("1")\n2') | ||
expect_length(ev, 4) | ||
}) | ||
|
||
test_that("code aborts on error if stop_on_error == 1L", { | ||
ev <- evaluate(file("error.R"), stop_on_error = 1L) | ||
ev <- evaluate('stop("1")\n2', stop_on_error = 1L) | ||
expect_length(ev, 2) | ||
}) | ||
|
||
test_that("code errors if stop_on_error == 2L", { | ||
expect_error(evaluate(file("error.R"), stop_on_error = 2L), "1") | ||
expect_snapshot(evaluate('stop("1")', stop_on_error = 2L), error = TRUE) | ||
}) | ||
|
||
test_that("traceback useful if stop_on_error == 2L", { | ||
expect_error(evaluate(file("error-complex.R"), stop_on_error = 2L), "Error") | ||
expect_error(evaluate_(' | ||
f <- function() g() | ||
g <- function() h() | ||
h <- function() stop("Error") | ||
|
||
f() | ||
', stop_on_error = 2L), "Error") | ||
|
||
## Doesn't work because .Traceback not create when code run | ||
## inside try or tryCatch. Can't figure out how to work around. | ||
|
@@ -26,6 +32,12 @@ test_that("traceback useful if stop_on_error == 2L", { | |
}) | ||
|
||
test_that("capture messages in try() (#88)", { | ||
ev <- evaluate(file("try.R")) | ||
# TODO: figure out why this doesn't work interactively | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is not working for this exactly ? Out of curiosity I tried locally and it seemed to work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea 😬 I'll have to look again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah seems fine now so I'm not sure what the problem was. |
||
ev <- evaluate_(' | ||
g <- function() f("error") | ||
f <- function(x) stop(paste0("Obscure ", x)) | ||
|
||
try(g()) | ||
') | ||
expect_match(ev[[length(ev)]], "Obscure error") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this test is tested anymore. Historically, as the others, all those tests were before
testthat
structure, and insideinst/tests
.So probably not testing something we still need - I didn't find what
interweave
wasThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither! Maybe it's the original name of evaluate?