Skip to content

Commit 0cc2351

Browse files
committed
fix tests
1 parent cc15b95 commit 0cc2351

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

R/utils-get_code_dependency.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ get_code_dependency <- function(code, names, check_names = TRUE) {
3838
}))
3939

4040
if (!all(names %in% unique(symbols))) {
41-
warning("Object(s) not found in code: ", toString(setdiff(names, symbols)), call. = FALSE)
41+
warning("Object(s) not found in code: ", toString(setdiff(names, symbols)), ".", call. = FALSE)
4242
}
4343
}
4444

tests/testthat/test-qenv_extract.R

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
1-
testthat::test_that("`[.` returns empty qenv for names not in qenv", {
1+
testthat::test_that("`[.` warns and subsets to empty if all names not present in env nor code", {
22
data <- within(qenv(), {
3-
x <- 1
4-
a <- 2
3+
a <- 1
4+
b <- 2
55
})
66
testthat::expect_warning(
7-
testthat::expect_equal(data["y"], qenv()),
7+
testthat::expect_equal(data[c("y", "z")], qenv()),
8+
"Object\\(s\\) not found in code: y, z."
9+
)
10+
testthat::expect_warning(
11+
testthat::expect_equal(data[c("y", "z")], qenv()),
812
"None of 'names' exist in the environment of the 'qenv'. Returning empty 'qenv."
913
)
1014
})
1115

12-
testthat::test_that("`[.` returns limited qenv for some names not in qenv", {
16+
testthat::test_that("`[.` warns and subsets to empty if all names not present in env", {
1317
data <- within(qenv(), {
14-
x <- 1
15-
a <- 2
18+
a <- 1
19+
b <- 2
20+
c <- 3
21+
rm(b, c)
1622
})
1723
testthat::expect_warning(
18-
testthat::expect_equal(data[c("y", "a")], data["a"]),
19-
"Some elements of 'names' do not exist in the environment of the 'qenv'. Skipping those: y."
24+
testthat::expect_equal(data[c("b", "c")], qenv()),
25+
"None of 'names' exist in the environment of the 'qenv'. Returning empty 'qenv'."
2026
)
2127
})
2228

23-
testthat::test_that("`[.` limits code for some names not in code", {
29+
testthat::test_that("`[.` warns and subsets to existing if some names not present in env and code", {
2430
data <- within(qenv(), {
25-
x <- 1
26-
a <- 2
27-
rm(x)
31+
a <- 1
32+
b <- 2
2833
})
2934
testthat::expect_warning(
30-
testthat::expect_equal(data[c("a", "x")], data["a"]),
31-
"Some elements of 'names' do not exist in the environment of the 'qenv'. Skipping those: x."
35+
testthat::expect_equal(data[c("b", "c", "d")], data["b"]),
36+
"Some elements of 'names' do not exist in the environment of the 'qenv'. Skipping those: c, d."
37+
)
38+
testthat::expect_warning(
39+
testthat::expect_equal(data[c("b", "c", "d")], data["b"]),
40+
"Object\\(s\\) not found in code: c, d."
3241
)
3342
})
3443

35-
3644
testthat::test_that("`[.` subsets environment and code to specified object names", {
3745
q <- qenv()
3846
code <- c("x<-1", "a<-1;b<-2")
@@ -64,16 +72,3 @@ testthat::test_that("`[.` comments are preserved in the code and associated with
6472
c("x<-1 #comment\n", "a<-1;")
6573
)
6674
})
67-
68-
testthat::test_that("`[.` extract proper elements of @id, @warnings and @messages fiels", {
69-
q <- qenv()
70-
code <-
71-
c("x<-1 #comment", "message('tiny message')", "a<-1;b<-2;warning('small warning')")
72-
q <- eval_code(q, code)
73-
qs <- q[c("x", "a")]
74-
75-
testthat::expect_identical(get_code_attr(qs, "id"), get_code_attr(q, "id")[c(1, 3)])
76-
testthat::expect_identical(unlist(qs@code), unlist(q@code[c(1, 3)]))
77-
testthat::expect_null(get_code_attr(qs, "warning"))
78-
testthat::expect_null(get_code_attr(qs, "message"))
79-
})

0 commit comments

Comments
 (0)