Ticket #1220: 00-ppix-editortools.t

File 00-ppix-editortools.t, 5.7 KB (added by bowtie, 4 years ago)

'spurious result' from abstract method?

Line 
1#!/usr/bin/eval perl
2
3use strict;
4use English '-no_match_vars';
5
6BEGIN {
7    $WARNING = 1;
8}
9use Test::More tests => 47;
10use Test::Exception;
11######
12# let's check our requirments.
13######
14use_ok('Carp');
15
16### you could do this but why?
17#
18#use Carp qw(croak);
19#eval( use_ok( 'PPI', '1.215' ) );
20#if ($EVAL_ERROR) { croak; }
21#
22### when you can just do this
23use_ok( 'PPI', '1.215' );
24use_ok('PPI::Find');
25use_ok( 'Class::XSAccessor', '1.02' );
26use_ok('File::Spec');
27use_ok('File::Basename');
28use_ok('File::Find');
29use_ok('File::Temp');
30use_ok( 'Test::More', '0.88' );
31
32#use_ok( 'Test::Most'); # craps out !!
33use_ok('Test::Differences');
34
35#use_ok( 'Test::NoWarnings', '0.084'); # craps out !!
36
37######
38# Testing PPIx::EditorTools
39######
40my $pet_obj;
41require PPIx::EditorTools;
42$pet_obj = new_ok('PPIx::EditorTools');
43
44my @subs =
45    qw( new code ppi process_doc find_unmatched_brace get_all_variable_declarations element_depth find_token_at_location find_variable_declaration );
46use_ok( 'PPIx::EditorTools', @subs );
47
48foreach my $subs (@subs) {
49    can_ok( 'PPIx::EditorTools', $subs );
50}
51
52#TODO need more pkg tests
53use PPIx::EditorTools;
54my $space = q{ }; # space
55my $empty = q{};  # empty string
56my $one   = q{1};
57
58#######
59# Testing PPIx::EditorTools->process_doc()
60#######
61# Check that something died - we do not care why
62dies_ok { PPIx::EditorTools->process_doc() } 'expecting PPIx::EditorTools->process_doc() to die';
63
64# check code to ppi
65my @test_files = (
66    { filename => 't/outline/Foo.pm', },
67    { filename => 't/outline/file1.pl', },
68    { filename => 't/outline/file2.pl', },
69    { filename => 't/outline/Mooclass.pm', },
70    { filename => 't/outline/Moorole.pm', },
71    { filename => 't/outline/Moofirst.pm', },
72);
73my $obj = PPIx::EditorTools->new();
74$obj->ppi(undef);
75$obj->code(undef);
76my $code;
77foreach my $file (@test_files) {
78##my $code;
79    if ( $file->{filename} ) {
80        open my $file_handle, '<', $file->{filename} or die;
81        local $INPUT_RECORD_SEPARATOR = undef;
82        $code = <$file_handle>;
83    }
84    ok( $obj->process_doc( code => $code ),
85        "process_doc(code) from $file->{filename}"
86    );
87}
88
89## check ppi source
90my %ppi = (
91    'attributes' => [
92        {   'line' => 7,
93            'name' => 'balance',
94        },
95        {   'line' => 13,
96            'name' => 'overdraft',
97        },
98        {   'line' => 23,
99            'name' => 'name',
100        },
101        {   'line' => 25,
102            'name' => 'account',
103        },
104    ],
105    'line'    => 3,
106    'methods' => [
107        {   'line' => 27,
108            'name' => '_build_overdraft',
109        },
110    ],
111    'modules' => [
112        {   'line' => 1,
113            'name' => 'MooseX::Declare',
114        },
115    ],
116    'name'     => 'Moofirst',
117    'pragmata' => [
118        {   'line' => 5,
119            'name' => 'version',
120        },
121    ],
122);
123
124$obj->ppi('PPI::Document');
125$obj->code(undef);
126ok( $obj->process_doc(%ppi), 'process_doc(ppi)' );
127## check neither ppi or code fails
128$obj->ppi(undef);
129$obj->code(undef);
130my %case = ( one => 'ppi', two => 'code', three => 'PPI::Document', );
131throws_ok { $obj->process_doc(%case) } '/arguments ppi or code required/', 'arguments ppi or code required';
132
133########
134# Testing PPIx::EditorTools->find_unmatched_brace()
135########
136dies_ok { PPIx::EditorTools->find_unmatched_brace() } 'expecting PPIx::EditorTools->find_unmatched_brace() to die';
137
138TODO:
139{
140    local $TODO = "PPIx::EditorTools->find_unmatched_brace() is untesable at it allwas returns \'\'";
141
142    $code = 'sub foo {\n1;\n}\n} # <--- This is an unmatched brace';
143    $obj->ppi('PPI::Statement::UnmatchedBrace');
144    is( $obj->find_unmatched_brace( code => $code ),
145        $one, "should have return $one"
146    );
147}
148
149$code = 'sub foo {\n1;\n}\n#} # <--- This is not an unmatched brace';
150$obj->ppi('PPI::Structure');
151is( $obj->find_unmatched_brace( code => $code ), $empty, 'spurious result' );
152
153$code = $space;
154$obj->ppi(undef);
155is( $obj->find_unmatched_brace( code => $code ), $empty, 'spurious result' );
156
157########
158# Testing PPIx::EditorTools->get_all_variable_declarations()
159########
160dies_ok { PPIx::EditorTools->get_all_variable_declarations() }
161'expecting PPIx::EditorTools->get_all_variable_declarations() to die';
162
163# additional tests located in t/08-getallvariabledeclarations.t
164
165########
166# Testing PPIx::EditorTools->element_depth()
167########
168#TODO add more tests
169dies_ok { PPIx::EditorTools->element_depth() } 'expecting PPIx::EditorTools->element_depth() to die';
170
171########
172# Testing PPIx::EditorTools->find_token_at_location()
173########
174#TODO add more tests
175dies_ok { PPIx::EditorTools->find_token_at_location() } 'expecting PPIx::EditorTools->find_token_at_location() to die';
176
177########
178# Testing PPIx::EditorTools->find_variable_declaration()
179########
180#TODO add more tests
181#dies_ok { PPIx::EditorTools->find_variable_declaration() } 'expecting PPIx::EditorTools->find_variable_declaration() to die';
182
183######
184# let's check our lib's are here.
185######
186my $test_object;
187require PPIx::EditorTools::FindUnmatchedBrace;
188$test_object = new_ok('PPIx::EditorTools::FindUnmatchedBrace');
189
190require PPIx::EditorTools::FindVariableDeclaration;
191$test_object = new_ok('PPIx::EditorTools::FindVariableDeclaration');
192
193require PPIx::EditorTools::IntroduceTemporaryVariable;
194$test_object = new_ok('PPIx::EditorTools::IntroduceTemporaryVariable');
195
196require PPIx::EditorTools::RenamePackage;
197$test_object = new_ok('PPIx::EditorTools::RenamePackage');
198
199require PPIx::EditorTools::RenamePackageFromPath;
200$test_object = new_ok('PPIx::EditorTools::RenamePackageFromPath');
201
202require PPIx::EditorTools::RenameVariable;
203$test_object = new_ok('PPIx::EditorTools::RenameVariable');
204
205require PPIx::EditorTools::FindUnmatchedBrace;
206$test_object = new_ok('PPIx::EditorTools::FindUnmatchedBrace');
207
208require PPIx::EditorTools::Outline;
209$test_object = new_ok('PPIx::EditorTools::Outline');
210
211require PPIx::EditorTools::Lexer;
212$test_object = new_ok('PPIx::EditorTools::Lexer');
213
214require PPIx::EditorTools::ReturnObject;
215$test_object = new_ok('PPIx::EditorTools::ReturnObject');
216
217done_testing()