11 require_ok("B::Concise");
13 $out = runperl(switches => ["-MO=Concise"], prog => '$a', stderr => 1);
15 # If either of the next two tests fail, it probably means you need to
16 # fix the section labeled 'fragile kludge' in Concise.pm
18 ($op_base) = ($out =~ /^(\d+)\s*<0>\s*enter/m);
20 is($op_base, 1, "Smallest OP sequence number");
22 ($op_base_p1, $cop_base)
23 = ($out =~ /^(\d+)\s*<;>\s*nextstate\(main (-?\d+) /m);
25 is($op_base_p1, 2, "Second-smallest OP sequence number");
27 is($cop_base, 1, "Smallest COP sequence number");
29 # test that with -exec B::Concise navigates past logops (bug #18175)
32 switches => ["-MO=Concise,-exec"],
33 prog => q{$a//=$b && print q/foo/},
37 like($out, qr/print/, "'-exec' option output has print opcode");
39 ######## API tests v.60
41 use Config; # used for perlio check
42 B::Concise->import(qw(set_style set_style_standard add_callback
43 add_style walk_output));
45 ## walk_output argument checking
47 # test that walk_output accepts a HANDLE arg
48 foreach my $foo (\*STDOUT, \*STDERR) {
49 eval { walk_output($foo) };
50 is ($@, '', "walk_output() accepts STD* " . ref $foo);
53 # test that walk_output rejects non-HANDLE args
54 foreach my $foo (undef, 0, "string",[], {}) {
55 eval { walk_output($foo) };
56 isnt ($@, '', "walk_output() rejects arg '$foo'");
57 $@=''; # clear the fail for next test
60 { # any object that can print should be ok for walk_output
62 sub new { my $foo = bless {} };
63 sub print { CORE::print @_ }
65 my $foo = new Hugo; # suggested this API fix
66 eval { walk_output($foo) };
67 is ($@, '', "walk_output() accepts obj that can print");
69 # now test a ref to scalar
70 eval { walk_output(\my $junk) };
71 is ($@, '', "walk_output() accepts ref-to-sprintf target");
74 eval { walk_output(\$junk) };
75 is ($@, '', "walk_output() accepts ref-to-non-empty-scalar");
80 eval { add_style ('junk_B' => @stylespec) };
81 like ($@, 'expecting 3 style-format args',
82 "add_style rejects insufficient args");
84 @stylespec = (0,0,0); # right length, invalid values
86 eval { add_style ('junk' => @stylespec) };
87 is ($@, '', "add_style accepts: stylename => 3-arg-array");
90 eval { add_style (junk => @stylespec) };
91 like ($@, qr/style 'junk' already exists, choose a new name/,
92 "add_style correctly disallows re-adding same style-name" );
94 # test new arg-checks on set_style
96 eval { set_style (@stylespec) };
97 is ($@, '', "set_style accepts 3 style-format args");
99 @stylespec = (); # bad style
101 eval { set_style (@stylespec) };
102 like ($@, qr/expecting 3 style-format args/,
103 "set_style rejects bad style-format args");
106 #### for content with doc'd options
108 set_style_standard('concise'); # MUST CALL b4 output needed
109 my $func = sub{ $a = $b+42 };
112 -basic -exec -tree -compact -loose -vt -ascii -main
113 -base10 -bigendian -littleendian
115 foreach $opt (@options) {
116 walk_output(\my $out);
117 my $treegen = B::Concise::compile($opt, $func);
120 isnt($out, '', "got output with option $opt");
123 ## test output control via walk_output
125 my $treegen = B::Concise::compile('-basic', $func); # reused
127 { # test output into a package global string (sprintf-ish)
129 walk_output(\$thing);
131 ok($thing, "walk_output to our SCALAR, output seen");
134 { # test output to GLOB, using perlio feature directly
135 skip 1, "no perlio on this build" unless $Config{useperlio};
136 open (my $fh, '>', \my $buf);
139 ok($buf, "walk_output to GLOB, output seen");
142 ## Test B::Concise::compile error checking
144 # call compile on non-CODE ref items
145 foreach my $ref ([], {}) {
147 walk_output(\my $out);
148 eval { B::Concise::compile('-basic', $ref)->() };
149 like ($@, qr/^err: not a coderef: $typ/,
150 "compile detects $typ-ref where expecting subref");
151 # is($out,'', "no output when errd"); # announcement prints
154 # test against a bogus autovivified subref.
155 # in debugger, it should look like:
157 # -> &CODE(0x84840cc) in ???
159 eval { B::Concise::compile('-basic', \&nosuchfunc)->() };
160 like ($@, qr/^err: coderef has no START/,
161 "compile detects CODE-ref w/o actual code");
163 foreach my $opt (qw( -concise -exec )) {
164 eval { B::Concise::compile($opt,'non_existent_function')->() };
165 like ($@, qr/unknown function \(main::non_existent_function\)/,
166 "'$opt' reports non-existent-function properly");