@@ -5,10 +5,34 @@ testthat::describe("get_output", {
55 testthat :: expect_identical(get_outputs(q1 ), list ())
66 })
77
8- testthat :: it(" implicitly printed objects are returned asis in a list" , {
8+ testthat :: it(" implicitly printed objects are returned asis in a list and are identical to ones in the environment " , {
99 q <- qenv()
10- q1 <- eval_code(q , expression(a <- 1L , a , b <- 2L , b ))
11- testthat :: expect_identical(get_outputs(q1 ), list (1L , 2L ))
10+ q1 <- eval_code(
11+ q ,
12+ expression(
13+ a <- 1L , a ,
14+ b <- structure(list (aa = list (aaa = " aaa" )), class = " class_to_break" ), b
15+ )
16+ )
17+ 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 )
20+ })
21+
22+ testthat :: it(" implicitly printed list is returned asis even if its print is overridden" , {
23+ q <- qenv()
24+ q1 <- eval_code(
25+ q ,
26+ expression(
27+ print.test_class <- function (x , ... ) {
28+ print(" test_print" )
29+ invisible (NULL )
30+ },
31+ b <- structure(list (" test" ), class = " test_class" ),
32+ b
33+ )
34+ )
35+ testthat :: expect_identical(get_outputs(q1 ), list (q1 $ b ))
1236 })
1337
1438 testthat :: it(" explicitly printed objects are returned as console-output-string in a list" , {
@@ -17,6 +41,22 @@ testthat::describe("get_output", {
1741 testthat :: expect_identical(get_outputs(q1 ), list (" [1] 1\n " , " [1] 2\n " ))
1842 })
1943
44+ testthat :: it(" explicitly printed object uses newly registered print method and returned as console-output-string" , {
45+ q <- qenv()
46+ q1 <- eval_code(
47+ q ,
48+ expression(
49+ print.test_class <- function (x , ... ) {
50+ print(" test_print" )
51+ invisible (NULL )
52+ },
53+ b <- structure(list (" test" ), class = " test_class" ),
54+ print(b )
55+ )
56+ )
57+ testthat :: expect_identical(get_outputs(q1 ), list (" [1] \" test_print\"\n " ))
58+ })
59+
2060 testthat :: it(" printed plots are returned as recordedplot in a list" , {
2161 q <- qenv()
2262 q1 <- eval_code(q , expression(a <- 1L , plot(a )))
0 commit comments