8 use Test::More tests => 15;
12 # indent should return a string indented four spaces times the argument
13 is( B::Terse::indent(2), ' ' x 8, 'indent with an argument' );
14 is( B::Terse::indent(), '', 'indent with no argument' );
16 # this should fail without a reference
17 eval { B::Terse::terse('scalar') };
18 like( $@, qr/not a reference/, 'terse() fed bad parameters' );
20 # now point it at a sub and see what happens
24 eval{ $sub = B::Terse::compile('', 'foo') };
25 is( $@, '', 'compile()' );
26 ok( defined &$sub, 'valid subref back from compile()' );
28 # and point it at a real sub and hope the returned ops look alright
29 my $out = tie *STDOUT, 'TieOut';
30 $sub = B::Terse::compile('', 'bar');
33 # now build some regexes that should match the dumped ops
34 my ($hex, $op) = ('\(0x[a-f0-9]+\)', '\s+\w+');
35 my %ops = map { $_ => qr/$_ $hex$op/ }
36 qw ( OP COP LOOP PMOP UNOP BINOP LOGOP LISTOP );
38 # split up the output lines into individual ops (terse is, well, terse!)
39 # use an array here so $_ is modifiable
40 my @lines = split(/\n+/, $out->read);
46 next unless exists $ops{$op};
47 like( $_, $ops{$op}, "$op " );
54 warn "# didn't find " . join(' ', keys %ops) if keys %ops;
57 # this tries to get at all tersified optypes in B::Terse
58 # if you add AV, NULL, PADOP, PVOP, or SPECIAL, add it to the regex above too
62 # OP SVOP COP IV here or in sub definition
71 # this is awful, but it gives a PMOP
72 my $boo = split('', $foo);
85 skip("- B::Terse won't grok RVs under ithreads yet", 1)
86 if $Config{useithreads};
87 # Schwern's example of finding an RV
88 my $path = join " ", map { qq["-I$_"] } @INC;
89 my $redir = $^O eq 'MacOS' ? '' : "2>&1";
90 my $items = qx{$^X $path "-MO=Terse" -le "print \\42" $redir};
91 like( $items, qr/RV $hex \\42/, 'RV' );
97 bless( \(my $out), $_[0] );
102 $$self .= join('', @_);
107 $$self .= sprintf(@_);
112 return substr($$self, 0, length($$self), '');