3 # Copyright (C) 2010, Parrot Foundation.
7 pir::load_bytecode('ProfTest.pbc');
18 my $prof := ProfTest::PIRProfile.new($pir_code);
21 ok(1, "profile creation didn't explode");
23 #Does the profile have a version string?
24 my $matcher := ProfTest::Matcher.new(
28 ok( $matcher.matches($prof), "profile has a version number");
30 #Does the profile have a CLI invocation?
31 $matcher := ProfTest::Matcher.new(
35 ok( $matcher.matches($prof), "profile contains a CLI string");
37 #Does the profile have a 'say' op somewhere?
38 $matcher := ProfTest::Matcher.new(
42 ok( $matcher.matches($prof), "profile has a say op");
44 #Does the profile have expected timing values?
45 $matcher := ProfTest::Matcher.new(
49 ok( $matcher.matches($prof), "profile has canonical timing information");
51 #Does the matcher fail to find the non-existent 'lollercoaster' opcode?
52 $matcher := ProfTest::Matcher.new(
56 ok( !$matcher.matches($prof), "matcher didn't find non-existent opcode");
58 #Does the profile show a 'say' op inside the 'main' sub?
59 $matcher := ProfTest::Matcher.new(
65 ok( $matcher.matches($prof), "profile shows 'say' inside main sub");
82 $prof := ProfTest::PIRProfile.new($pir_code);
84 $matcher := ProfTest::Matcher.new(
85 cs(:ns('parrot;first'), :slurp_until('cs')),
86 cs(:ns('parrot;second'), :slurp_until('cs')),
87 cs(:ns('parrot;first')),
90 ok( $matcher.matches($prof), "profile properly reflects normal control flow (simple)");
112 $prof := ProfTest::PIRProfile.new($pir_code);
114 $matcher := ProfTest::Matcher.new(
115 cs(:ns('parrot;first'), :slurp_until('cs')),
116 cs(:ns('parrot;second'), :slurp_until('cs')),
117 cs(:ns('parrot;third'), :slurp_until('cs')),
118 cs(:ns('parrot;second'), :slurp_until('cs')),
119 cs(:ns('parrot;first')),
122 ok( $matcher.matches($prof), "profile properly reflects normal control flow (slightly less simple)");
125 #test: main calls foo, foo tailcalls bar, bar returns to main
145 $prof := ProfTest::PIRProfile.new($pir_code);
147 $matcher := ProfTest::Matcher.new(
148 cs(:ns('parrot;first'), :slurp_until('cs')),
149 cs(:ns('parrot;foo'), :slurp_until('cs')),
150 cs(:ns('parrot;bar'), :slurp_until('cs')),
151 cs(:ns('parrot;first')),
154 ok( $matcher.matches($prof), "profile properly reflects tailcall control flow");
157 #Does the profile show a 'say' op on line 2?
158 $matcher := ProfTest::Matcher.new(
159 op('say', :line('3')),
162 ok( $matcher.matches($prof), "profile shows say on the correct line");
171 $prof := ProfTest::NQPProfile.new($nqp_code);
173 $matcher := ProfTest::Matcher.new(
174 cs(:ns('parrot;main') ),
179 ok( $matcher.matches($prof), "profile shows 'say' inside nqp sub");
181 #convenience subs to avoid repetitive typing and visual noise
183 sub version(*@p, *%n) { ProfTest::Want::Version.new(|@p, |%n) }
184 sub cli(*@p, *%n) { ProfTest::Want::CLI.new(|@p, |%n) }
185 sub eor(*@p, *%n) { ProfTest::Want::EndOfRunloop.new(|@p, |%n) }
186 sub op(*@p, *%n) { ProfTest::Want::Op.new(|@p, |%n) }
187 sub cs(*@p, *%n) { ProfTest::Want::CS.new(|@p, |%n) }
188 sub any(*@p, *%n) { ProfTest::Want::Any.new(|@p, |%n) }
194 # vim: expandtab shiftwidth=4 ft=perl6