Skip to content

Commit

Permalink
Refactored tests, ensure that we perform multi-line match.
Browse files Browse the repository at this point in the history
  • Loading branch information
xxfelixxx committed Feb 12, 2018
1 parent 8dc0de0 commit 9fc0246
Showing 1 changed file with 49 additions and 11 deletions.
60 changes: 49 additions & 11 deletions t/devel-scope.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,67 @@ ok($bad_env =~ m|Invalid Devel::Scope env variable|s, "Caught invalid environmen
or diag("Got: $bad_env");

my $level0 = run_fixture(0);
ok($level0 =~ m|0:Main-Block|, "Got 0:Main-Block") or diag("Got: $level0");
ok($level0 !~ m|1:Main-Block|, "Did not get 1:Main-Block") or diag("Got: $level0");
match_all( $level0, qw(
0:Main-Block
));
match_none($level0, qw(
1:Main-Block
));

my $level1 = run_fixture(1);
ok($level1 =~ m|0:Main-Block|, "Got 0:Main-Block") or diag("Got:\n $level1");
ok($level1 =~ m|1:Main-Block|, "Got 1:Main-Block") or diag("Got:\n $level1");
ok($level1 =~ m|1:Foo-Block|, "Got 1:Foo-Begin") or diag("Got:\n $level1");
ok($level1 =~ m|1:Foo-Block|, "Got 1:Foo-Block") or diag("Got:\n $level1");
ok($level1 =~ m|1:Foo-Block|, "Got 1:Foo-End") or diag("Got:\n $level1");
ok($level1 !~ m|2:Main-Block|, "Did not get 2:Main-Block") or diag("Got:\n $level1");
ok($level1 !~ m| 2:|, "Did not get any 2:") or diag("Got:\n $level1");
match_all( $level1, qw(
0:Main-Block
1:Main-Block
1:Foo-Begin
1:Foo-Block
1:Foo-End
));
match_none($level1, qw(
2:Main-Block
2:
));

my $level2 = run_fixture(2);
ok($level2 !~ m| 3:|, "Did not get any 3:") or diag("Got:\n $level2");
match_none($level2, qw(
3:
));

my $level3 = run_fixture(3);
ok($level3 !~ m| 4:|, "Did not get any 4:") or diag("Got:\n $level3");
match_none($level3, qw(
4:
));

my $level5 = run_fixture(5);
pass("All output:\n$level5");

done_testing();

sub _match {
my ($sense, $txt, @strings) = @_;

for my $string (@strings) {
my $re = qr|\Q$string\E|s; # Multi-line match of literal string
if ($sense) {
# Match
ok( $txt =~ $re, "Got $string") or diag("Got:\n$txt");
} else {
# Do not match
ok( $txt !~ $re, "Did not get $string") or diag("Got:\n$txt"); }
}
}

sub match_all {
my ($txt, @strings) = @_;

_match(1,$txt,@strings);
}

sub match_none {
my ($txt, @strings) = @_;

_match(0,$txt,@strings);
}

sub run_fixture {
my ($scope_depth) = @_;
local %ENV = %ENV;
Expand Down

0 comments on commit 9fc0246

Please sign in to comment.