@@ -15,8 +15,24 @@ testthat::describe("get_output", {
1515 )
1616 )
1717 testthat :: expect_identical(get_outputs(q1 ), unname(as.list(q1 )))
18- testthat :: expect_reference(get_outputs(q1 )[[1 ]], q1 $ a )
19- testthat :: expect_reference(get_outputs(q1 )[[2 ]], q1 $ b )
18+ testthat :: expect_true(rlang :: is_reference(get_outputs(q1 )[[1 ]], q1 $ a ))
19+ testthat :: expect_true(rlang :: is_reference(get_outputs(q1 )[[2 ]], q1 $ b ))
20+ })
21+
22+ testthat :: it(" implicitly printed S4 object is returned asis in a list and identical to the one in the environment" , {
23+ q <- qenv()
24+ q1 <- eval_code(
25+ q ,
26+ expression(
27+ methods :: setClass ("NewS4Class ", slots = list(value = "numeric")),
28+ new_obj <- methods :: new(" NewS4Class" , value = 42 ),
29+ new_obj
30+ )
31+ )
32+ withr :: defer(removeClass(" NewS4Class" ))
33+ testthat :: expect_identical(get_outputs(q1 ), unname(as.list(q1 )))
34+ testthat :: expect_true(rlang :: is_reference(get_outputs(q1 )[[1 ]], q1 $ new_obj ))
35+ testthat :: expect_s4_class(get_outputs(q1 )[[1 ]], " NewS4Class" )
2036 })
2137
2238 testthat :: it(" implicitly printed list is returned asis even if its print is overridden" , {
@@ -57,12 +73,18 @@ testthat::describe("get_output", {
5773 testthat :: expect_identical(get_outputs(q1 ), list (" [1] \" test_print\"\n " ))
5874 })
5975
60- testthat :: it(" printed plots are returned as recordedplot in a list" , {
76+ testthat :: it(" printed plots are returned as recordedplot in a list (1) " , {
6177 q <- qenv()
6278 q1 <- eval_code(q , expression(a <- 1L , plot(a )))
6379 testthat :: expect_true(inherits(get_outputs(q1 )[[1 ]], " recordedplot" ))
6480 })
6581
82+ testthat :: it(" printed plots are returned as recordedplot in a list (2)" , {
83+ q <- qenv()
84+ q1 <- eval_code(q , expression(a <- seq_len(10L ), hist(a )))
85+ testthat :: expect_true(inherits(get_outputs(q1 )[[1 ]], " recordedplot" ))
86+ })
87+
6688 testthat :: it(" warnings are returned asis in a list" , {
6789 q <- qenv()
6890 q1 <- eval_code(q , expression(warning(" test" )))
@@ -77,8 +99,15 @@ testthat::describe("get_output", {
7799 expected <- simpleMessage(" test\n " , call = quote(message(" test" )))
78100 testthat :: expect_identical(get_outputs(q1 ), list (expected ))
79101 })
102+
80103 testthat :: it(" prints inside for are bundled together" , {
81104 q <- within(qenv(), for (i in 1 : 3 ) print(i ))
82105 testthat :: expect_identical(get_outputs(q )[[1 ]], " [1] 1\n [1] 2\n [1] 3\n " )
83106 })
107+
108+ testthat :: it(" intermediate plots are not kept" , {
109+ q <- qenv()
110+ q1 <- eval_code(q , expression(plot(1 : 10 ), title(" A title" )))
111+ testthat :: expect_length(get_outputs(q1 ), 1 )
112+ })
84113})
0 commit comments