Skip to content

Commit 8587ca7

Browse files
authored
Fix tests in use_evaluate branch (#259)
targets: #258
1 parent 208db3b commit 8587ca7

File tree

4 files changed

+12
-40
lines changed

4 files changed

+12
-40
lines changed

R/utils-get_code_dependency.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ get_call_breaks <- function(code) {
521521
}
522522
))
523523
call_breaks <- call_breaks[-nrow(call_breaks), , drop = FALSE] # breaks in between needed only
524+
if (nrow(call_breaks) == 0L) {
525+
call_breaks <- matrix(numeric(0), ncol = 2)
526+
}
524527
colnames(call_breaks) <- c("line", "col")
525528
call_breaks
526529
}

tests/testthat/test-qenv_constructor.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ testthat::test_that("constructor returns qenv", {
5454
testthat::expect_identical(q@code, list())
5555
})
5656

57-
testthat::describe("parent of qenv environment is the parent of .GlobalEnv", {
57+
testthat::describe("grand parent of qenv environment is the parent of .GlobalEnv", {
5858
testthat::it("via slot", {
5959
q <- qenv()
60-
testthat::expect_identical(parent.env(q@.xData), parent.env(.GlobalEnv))
60+
testthat::expect_identical(parent.env(parent.env(q@.xData)), parent.env(.GlobalEnv))
6161
})
6262

6363
testthat::it("via qenv directly", {
6464
q <- qenv()
65-
testthat::expect_identical(parent.env(q), parent.env(.GlobalEnv))
65+
testthat::expect_identical(parent.env(parent.env(q)), parent.env(.GlobalEnv))
6666
})
6767
})

tests/testthat/test-qenv_eval_code.R

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -136,44 +136,12 @@ testthat::test_that("comments fall into proper calls", {
136136
testthat::expect_identical(get_code(q), code)
137137
})
138138

139-
testthat::test_that("comments alone are pasted to the next/following call element", {
140-
code <- c("x <- 5", "# comment", "y <- 6")
141-
q <- eval_code(qenv(), code)
142-
testthat::expect_identical(
143-
as.character(q@code)[2],
144-
paste(code[2:3], collapse = "\n")
145-
)
146-
testthat::expect_identical(
147-
get_code(q),
148-
paste(code, collapse = "\n")
149-
)
150-
})
151-
152-
testthat::test_that("comments at the end of src are added to the previous call element", {
153-
code <- c("x <- 5", "# comment")
154-
q <- eval_code(qenv(), code)
155-
testthat::expect_identical(
156-
as.character(q@code),
157-
paste(code[1:2], collapse = "\n")
158-
)
159-
testthat::expect_identical(
160-
get_code(q),
161-
paste(code, collapse = "\n")
162-
)
163-
})
164-
165139
testthat::test_that("comments from the same line are associated with it's call", {
166140
code <- c("x <- 5", " y <- 4 # comment", "z <- 5")
167141
q <- eval_code(qenv(), code)
168142
testthat::expect_identical(as.character(q@code)[2], code[2])
169143
})
170144

171-
testthat::test_that("alone comments at the end of the source are considered as continuation of the last call", {
172-
code <- c("x <- 5\n", "y <- 10\n# comment")
173-
q <- eval_code(eval_code(qenv(), code[1]), code[2])
174-
testthat::expect_identical(as.character(q@code)[2], code[2])
175-
})
176-
177145
testthat::test_that("comments passed alone to eval_code that contain @linksto tag have detected dependency", {
178146
code <- c("x <- 5", "# comment @linksto x")
179147
q <- eval_code(eval_code(qenv(), code[1]), code[2])
@@ -201,3 +169,4 @@ testthat::test_that("plot output is stored as recordedplot in the 'outputs' attr
201169
q <- eval_code(qenv(), "plot(1)")
202170
testthat::expect_s3_class(attr(q@code[[1]], "outputs")[[1]], "recordedplot")
203171
})
172+

tests/testthat/test-qenv_get_code.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,15 @@ testthat::test_that("detects occurrence of a function definition when a formal i
581581
})
582582

583583
testthat::test_that("detects occurrence of a function definition with a @linksto usage", {
584-
code <- c(
584+
code <- trimws(c(
585585
"
586586
foo <- function() {
587587
env <- parent.frame()
588588
env$x <- 0
589589
}",
590590
"foo() # @linksto x",
591591
"y <- x"
592-
)
592+
))
593593
q <- eval_code(qenv(), code)
594594
testthat::expect_identical(
595595
get_code(q, names = "x"),
@@ -601,7 +601,7 @@ testthat::test_that("detects occurrence of a function definition with a @linksto
601601
# for loop --------------------------------------------------------------------------------------------------------
602602

603603
testthat::test_that("objects in for loop are extracted if passed as one character", {
604-
code <- "
604+
code <- trimws("
605605
some_other_dataset <- mtcars
606606
original_dataset <- iris[, 1:4]
607607
count <- 1
@@ -610,11 +610,11 @@ testthat::test_that("objects in for loop are extracted if passed as one characte
610610
count <- count + 1
611611
}
612612
output <- rlang::list2(x = original_dataset)
613-
"
613+
")
614614
q <- eval_code(qenv(), code)
615615
testthat::expect_identical(
616616
get_code(q, names = "output"),
617-
gsub("\n some_other_dataset <- mtcars\n", "", code, fixed = TRUE)
617+
gsub("some_other_dataset <- mtcars\n", "", code, fixed = TRUE)
618618
)
619619
})
620620

0 commit comments

Comments
 (0)