Skip to content

Fix tests in use_evaluate branch #259

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

Merged
merged 2 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/utils-get_code_dependency.R
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ get_call_breaks <- function(code) {
}
))
call_breaks <- call_breaks[-nrow(call_breaks), , drop = FALSE] # breaks in between needed only
if (nrow(call_breaks) == 0L) {
call_breaks <- matrix(numeric(0), ncol = 2)
}
colnames(call_breaks) <- c("line", "col")
call_breaks
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-qenv_constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ testthat::test_that("constructor returns qenv", {
testthat::expect_identical(q@code, list())
})

testthat::describe("parent of qenv environment is the parent of .GlobalEnv", {
testthat::describe("grand parent of qenv environment is the parent of .GlobalEnv", {
testthat::it("via slot", {
q <- qenv()
testthat::expect_identical(parent.env([email protected]), parent.env(.GlobalEnv))
testthat::expect_identical(parent.env(parent.env([email protected])), parent.env(.GlobalEnv))
})

testthat::it("via qenv directly", {
q <- qenv()
testthat::expect_identical(parent.env(q), parent.env(.GlobalEnv))
testthat::expect_identical(parent.env(parent.env(q)), parent.env(.GlobalEnv))
})
})
33 changes: 1 addition & 32 deletions tests/testthat/test-qenv_eval_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,12 @@ testthat::test_that("comments fall into proper calls", {
testthat::expect_identical(get_code(q), code)
})

testthat::test_that("comments alone are pasted to the next/following call element", {
code <- c("x <- 5", "# comment", "y <- 6")
q <- eval_code(qenv(), code)
testthat::expect_identical(
as.character(q@code)[2],
paste(code[2:3], collapse = "\n")
)
testthat::expect_identical(
get_code(q),
paste(code, collapse = "\n")
)
})

testthat::test_that("comments at the end of src are added to the previous call element", {
code <- c("x <- 5", "# comment")
q <- eval_code(qenv(), code)
testthat::expect_identical(
as.character(q@code),
paste(code[1:2], collapse = "\n")
)
testthat::expect_identical(
get_code(q),
paste(code, collapse = "\n")
)
})

testthat::test_that("comments from the same line are associated with it's call", {
code <- c("x <- 5", " y <- 4 # comment", "z <- 5")
q <- eval_code(qenv(), code)
testthat::expect_identical(as.character(q@code)[2], code[2])
})

testthat::test_that("alone comments at the end of the source are considered as continuation of the last call", {
code <- c("x <- 5\n", "y <- 10\n# comment")
q <- eval_code(eval_code(qenv(), code[1]), code[2])
testthat::expect_identical(as.character(q@code)[2], code[2])
})

testthat::test_that("comments passed alone to eval_code that contain @linksto tag have detected dependency", {
code <- c("x <- 5", "# comment @linksto x")
q <- eval_code(eval_code(qenv(), code[1]), code[2])
Expand Down Expand Up @@ -201,3 +169,4 @@ testthat::test_that("plot output is stored as recordedplot in the 'outputs' attr
q <- eval_code(qenv(), "plot(1)")
testthat::expect_s3_class(attr(q@code[[1]], "outputs")[[1]], "recordedplot")
})

10 changes: 5 additions & 5 deletions tests/testthat/test-qenv_get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ testthat::test_that("detects occurrence of a function definition when a formal i
})

testthat::test_that("detects occurrence of a function definition with a @linksto usage", {
code <- c(
code <- trimws(c(
"
foo <- function() {
env <- parent.frame()
env$x <- 0
}",
"foo() # @linksto x",
"y <- x"
)
))
q <- eval_code(qenv(), code)
testthat::expect_identical(
get_code(q, names = "x"),
Expand All @@ -601,7 +601,7 @@ testthat::test_that("detects occurrence of a function definition with a @linksto
# for loop --------------------------------------------------------------------------------------------------------

testthat::test_that("objects in for loop are extracted if passed as one character", {
code <- "
code <- trimws("
some_other_dataset <- mtcars
original_dataset <- iris[, 1:4]
count <- 1
Expand All @@ -610,11 +610,11 @@ testthat::test_that("objects in for loop are extracted if passed as one characte
count <- count + 1
}
output <- rlang::list2(x = original_dataset)
"
")
q <- eval_code(qenv(), code)
testthat::expect_identical(
get_code(q, names = "output"),
gsub("\n some_other_dataset <- mtcars\n", "", code, fixed = TRUE)
gsub("some_other_dataset <- mtcars\n", "", code, fixed = TRUE)
)
})

Expand Down