Skip to content

Commit 65db67c

Browse files
committed
add cmp_document family of test functions ; reorg t/lib modules
1 parent 3a1a06e commit 65db67c

File tree

10 files changed

+602
-206
lines changed

10 files changed

+602
-206
lines changed

t/05_lexer.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Compare a large number of specific constructs
44
# with the expected Lexer dumps.
55

6+
use lib 't/lib';
67
use strict;
78
BEGIN {
89
no warnings 'once';
@@ -23,7 +24,7 @@ use PPI::Dumper;
2324
use Test::More tests => 219;
2425
use Test::NoWarnings;
2526
use File::Spec::Functions ':ALL';
26-
use t::lib::PPI;
27+
use PPI::Test::Run;
2728

2829

2930

@@ -33,4 +34,4 @@ use t::lib::PPI;
3334
# Code/Dump Testing
3435
# ntests = 2 + 15 * nfiles
3536

36-
t::lib::PPI->run_testdir( catdir( 't', 'data', '05_lexer' ) );
37+
PPI::Test::Run->run_testdir( catdir( 't', 'data', '05_lexer' ) );

t/07_token.t

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Formal unit tests for specific PPI::Token classes
44

5+
use lib 't/lib';
56
use strict;
67
BEGIN {
78
no warnings 'once';
@@ -10,11 +11,11 @@ BEGIN {
1011
$PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER};
1112
}
1213

13-
# Execute the tests
1414
use Test::More tests => 447;
1515
use Test::NoWarnings;
1616
use File::Spec::Functions ':ALL';
17-
use t::lib::PPI;
17+
use List::MoreUtils ();
18+
use PPI::Test::Run;
1819
use PPI;
1920

2021

@@ -25,7 +26,7 @@ use PPI;
2526
# Code/Dump Testing
2627
# ntests = 2 + 12 * nfiles
2728

28-
t::lib::PPI->run_testdir( catdir( 't', 'data', '07_token' ) );
29+
PPI::Test::Run->run_testdir( catdir( 't', 'data', '07_token' ) );
2930

3031

3132

@@ -49,7 +50,7 @@ SCOPE: {
4950
'@::foo' => '@main::foo',
5051
'$foo::bar' => '$foo::bar',
5152
'$ foo\'bar' => '$foo::bar',
52-
);
53+
);
5354
while ( @symbols ) {
5455
my ($value, $canon) = ( shift(@symbols), shift(@symbols) );
5556
my $Symbol = PPI::Token::Symbol->new( $value );
@@ -155,10 +156,11 @@ foreach my $code ( '08', '09', '0778', '0779' ) {
155156
isa_ok($token, 'PPI::Token::Number::Octal');
156157
is("$token", $code, "tokenize bad octal '$code'");
157158
ok($token->{_error} && $token->{_error} =~ m/octal/i,
158-
'invalid octal number should trigger parse error');
159+
'invalid octal number should trigger parse error');
159160
is($token->literal, undef, "literal('$code') is undef");
160161
}
161162

163+
162164
BINARY: {
163165
my @tests = (
164166
# Good binary numbers
@@ -175,25 +177,26 @@ BINARY: {
175177
{ code => '0b012', error => 1, value => 0 },
176178
{ code => '0B012', error => 1, value => 0 },
177179
{ code => '0B0121', error => 1, value => 0 },
178-
);
180+
);
179181
foreach my $test ( @tests ) {
180182
my $code = $test->{code};
181183
my $T = PPI::Tokenizer->new( \$code );
182184
my $token = $T->get_token;
183185
isa_ok($token, 'PPI::Token::Number::Binary');
184-
if ( $test->{error} ) {
185-
ok($token->{_error} && $token->{_error} =~ m/binary/i,
186-
'invalid binary number should trigger parse error');
187-
is($token->literal, undef, "literal('$code') is undef");
188-
}
189-
else {
190-
ok(!$token->{_error}, "no error for '$code'");
191-
is($token->literal, $test->{value}, "literal('$code') is $test->{value}");
192-
}
193-
is($token->content, $code, "parsed everything");
186+
if ( $test->{error} ) {
187+
ok($token->{_error} && $token->{_error} =~ m/binary/i,
188+
'invalid binary number should trigger parse error');
189+
is($token->literal, undef, "literal('$code') is undef");
190+
}
191+
else {
192+
ok(!$token->{_error}, "no error for '$code'");
193+
is($token->literal, $test->{value}, "literal('$code') is $test->{value}");
194+
}
195+
is($token->content, $code, "parsed everything");
194196
}
195197
}
196198

199+
197200
HEX: {
198201
my @tests = (
199202
# Good hex numbers--entire thing goes in the token
@@ -233,6 +236,6 @@ HEX: {
233236
isa_ok($token, 'PPI::Token::Number::Hex');
234237
ok(!$token->{_error}, "no error for '$code' even on invalid digits");
235238
is($token->content, $test->{parsed}, "correctly parsed everything expected");
236-
is($token->literal, $test->{value}, "literal('$code') is $test->{value}");
239+
is($token->literal, $test->{value}, "literal('$code') is $test->{value}");
237240
}
238241
}

t/08_regression.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Some other regressions tests are included here for simplicity.
66

7+
use lib 't/lib';
78
use strict;
89
BEGIN {
910
no warnings 'once';
@@ -17,7 +18,7 @@ use Test::More tests => 933;
1718
use Test::NoWarnings;
1819
use File::Spec::Functions ':ALL';
1920
use Params::Util qw{_INSTANCE};
20-
use t::lib::PPI;
21+
use PPI::Test::Run;
2122
use PPI::Lexer;
2223
use PPI::Dumper;
2324

@@ -35,7 +36,7 @@ sub pause {
3536
# Code/Dump Testing
3637
# ntests = 2 + 14 * nfiles
3738

38-
t::lib::PPI->run_testdir(qw{ t data 08_regression });
39+
PPI::Test::Run->run_testdir(qw{ t data 08_regression });
3940

4041

4142

t/19_selftesting.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# Using PPI to analyse its own code at install-time? Fuck yeah! :)
77

8+
use lib 't/lib';
89
use strict;
910
BEGIN {
1011
no warnings 'once';
@@ -20,7 +21,7 @@ use File::Spec::Functions ':ALL';
2021
use Params::Util qw{_CLASS _ARRAY _INSTANCE _IDENTIFIER};
2122
use Class::Inspector;
2223
use PPI;
23-
use t::lib::PPI;
24+
use PPI::Test::Object;
2425

2526
use constant CI => 'Class::Inspector';
2627

t/25_increment.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# state between an empty document and the entire file to make sure
66
# all of them parse as legal documents and don't crash the parser.
77

8+
use lib 't/lib';
89
use strict;
910
BEGIN {
1011
no warnings 'once';
@@ -19,7 +20,7 @@ use File::Spec::Functions ':ALL';
1920
use Params::Util qw{_INSTANCE};
2021
use PPI::Lexer;
2122
use PPI::Dumper;
22-
use t::lib::PPI;
23+
use PPI::Test::Run;
2324

2425

2526

@@ -28,4 +29,4 @@ use t::lib::PPI;
2829
#####################################################################
2930
# Code/Dump Testing
3031

31-
t::lib::PPI->increment_testdir(qw{ t data 08_regression });
32+
PPI::Test::Run->increment_testdir(qw{ t data 08_regression });

t/26_bom.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/perl
22

3+
use lib 't/lib';
34
use strict;
45
BEGIN {
56
no warnings 'once';
@@ -11,7 +12,7 @@ BEGIN {
1112
# For each new item in t/data/08_regression add another 14 tests
1213
use Test::More tests => 21;
1314
use Test::NoWarnings;
14-
use t::lib::PPI;
15+
use PPI::Test::Run;
1516
use PPI;
1617

1718

@@ -22,4 +23,4 @@ use PPI;
2223
# Code/Dump Testing
2324
# ntests = 2 + 14 * nfiles
2425

25-
t::lib::PPI->run_testdir(qw{ t data 26_bom });
26+
PPI::Test::Run->run_testdir(qw{ t data 26_bom });

0 commit comments

Comments
 (0)