Commit | Line | Data |
2ed4f9ad |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More; |
5 | use Test::Fatal; |
6 | use Test::Requires 'Test::Output'; |
7 | |
8 | use Eval::Closure; |
9 | |
fa287851 |
10 | # XXX this whole test isn't very useful anymore, since we no longer do |
11 | # memoization. it would be nice to bring it back at some point though, if there |
12 | # was a way to do this without breaking the other tests |
13 | |
14 | plan skip_all => "disabling this test for now"; |
15 | |
2ed4f9ad |
16 | { |
68cb1ade |
17 | my $source = 'BEGIN { warn "foo\n" } sub { $foo * 2 }'; |
2ed4f9ad |
18 | |
19 | my $code; |
20 | my $bar = 15; |
21 | stderr_is { |
22 | $code = eval_closure( |
23 | source => $source, |
24 | environment => { |
25 | '$foo' => \$bar, |
26 | }, |
27 | ); |
28 | } "foo\n", "BEGIN was run"; |
29 | |
30 | is($code->(), 30, "got the right sub"); |
31 | |
32 | my $code2; |
33 | my $baz = 8; |
34 | stderr_is { |
35 | $code2 = eval_closure( |
36 | source => $source, |
37 | environment => { |
38 | '$foo' => \$baz, |
39 | }, |
40 | ); |
41 | } '', "BEGIN was not run twice"; |
42 | |
43 | is($code2->(), 16, "got the right sub"); |
44 | } |
45 | |
46 | { |
68cb1ade |
47 | my $source = 'BEGIN { warn "bar\n" } sub { $bar * 2 }'; |
2ed4f9ad |
48 | |
49 | my $code; |
50 | my $foo = 60; |
51 | stderr_is { |
52 | $code = eval_closure( |
53 | source => $source, |
54 | environment => { |
55 | '$bar' => \$foo, |
56 | }, |
57 | description => 'foo', |
58 | ); |
59 | } "bar\n", "BEGIN was run"; |
60 | |
61 | is($code->(), 120, "got the right sub"); |
62 | |
63 | my $code2; |
64 | my $baz = 23; |
68cb1ade |
65 | { local $TODO = "description breaks memoization"; |
2ed4f9ad |
66 | stderr_is { |
67 | $code2 = eval_closure( |
68 | source => $source, |
69 | environment => { |
70 | '$bar' => \$baz, |
71 | }, |
72 | description => 'baz', |
73 | ); |
74 | } '', "BEGIN was not run twice"; |
75 | } |
76 | |
77 | is($code2->(), 46, "got the right sub"); |
78 | } |
79 | |
80 | { |
68cb1ade |
81 | my $source = 'BEGIN { warn "baz\n" } sub { Carp::confess "baz" }'; |
2ed4f9ad |
82 | |
83 | my $code; |
84 | stderr_is { |
85 | $code = eval_closure( |
86 | source => $source, |
87 | description => 'first', |
88 | ); |
89 | } "baz\n", "BEGIN was run"; |
90 | |
91 | like(exception { $code->() }, qr/baz at first line 1/, |
92 | "got the right description"); |
93 | |
94 | my $code2; |
68cb1ade |
95 | { local $TODO = "description breaks memoization"; |
2ed4f9ad |
96 | stderr_is { |
97 | $code2 = eval_closure( |
98 | source => $source, |
99 | description => 'second', |
100 | ); |
101 | } '', "BEGIN was not run twice"; |
102 | } |
103 | |
104 | like(exception { $code2->() }, qr/baz at second line 1/, |
105 | "got the right description"); |
106 | } |
107 | |
108 | done_testing; |