Debian Codegraph @

script/inline2test

raw
1 #!/usr/bin/perl
2 # PODNAME: inline2test
3 # ABSTRACT: The Test::Inline 2 Test Compiler
4
5 #pod =pod
6 #pod
7 #pod =head1 SYNOPIS
8 #pod
9 #pod > inline2test ./inline2test.conf
10 #pod
11 #pod # In your inline2test.conf
12 #pod input=lib
13 #pod output=t
14 #pod execute=0
15 #pod verbose=1
16 #pod readonly=1
17 #pod header=inline2text.txt
18 #pod
19 #pod =head1 DESCRIPTION
20 #pod
21 #pod C<inline2test> is the L<Test::Inline> 2 test compiler.
22 #pod
23 #pod It's job is to scan through an arbitrary tree of Perl source code files,
24 #pod locate inline test sections, extract them, convert them to test scripts,
25 #pod and write them to an output path.
26 #pod
27 #pod =cut
28
29 use strict;
30 use File::Spec::Functions ':ALL';
31 use Getopt::Long ();
32 use Config::Tiny ();
33 use Test::Inline ();
34 use Test::Inline::IO::File ();
35
36 our $VERSION = '2.214';
37
38 # Predeclare things
39 sub stop ($);
40
41
42
43
44
45 #####################################################################
46 # Process Options, Input and Config
47
48 my $execute = '';
49 my $changed = '';
50 my $verbose = '';
51 my $readonly = '';
52 my $rv = Getopt::Long::GetOptions(
53 execute => \$execute,
54 changed => \$changed,
55 verbose => \$verbose,
56 readonly => \$readonly,
57 );
58 exit(0) unless $rv;
59
60 # Get the config file
61 my $config = shift @ARGV;
62 my $configdir = 1;
63 unless ( $config ) {
64 # Use a default inline2test.conf in the current directory if it exists
65 my $default = catfile( curdir(), 'inline2test.conf' );
66 if ( -f $default ) {
67 $config = curdir();
68 } else {
69 stop("You did not provide an config file name");
70 }
71 }
72 if ( -d $config ) {
73 # They point to a directory, not a file
74 $configdir = $config;
75 my $file = catfile( $config, 'inline2test.conf' );
76 if ( -f $file ) {
77 $config = $file;
78 } else {
79 stop("The directory $config does not contain an inline2test.conf file");
80 }
81 }
82 my $Config = Config::Tiny->read($config) or stop("Failed to load config file");
83 my %args = %{$Config->{_}} or stop("No config entries found");
84
85 # Add any forced options
86 $args{execute} = 1 if $execute;
87 $args{changed} = 1 if $changed;
88 $args{verbose} = 1 if $verbose;
89 $args{readonly} = 1 if $readonly;
90
91 # Automatically use an inline2test.tpl file if it exists
92 if ( $configdir and ! $args{template} ) {
93 my $file = catfile( $configdir, 'inline2test.tpl' );
94 $args{template} = $file if -f $file;
95 }
96
97 # Create ContentHandler if needed
98 if ( $args{template} ) {
99 # Convert to a proper contenthandler
100 my $template = delete $args{template};
101 $args{ContentHandler} = Test::Inline::Content::Simple->new( $template )
102 or stop("Failed to create ContentHandler for $template");
103 }
104
105 # Create InputHandler
106 if ( $args{input} ) {
107 # Convert to a proper inputhandler
108 my $input = delete $args{input};
109 $args{InputHandler} = Test::Inline::IO::File->new( $input )
110 or stop("Failed to create InputHandle for $input");
111 }
112
113 # We need an output
114 unless ( $args{output} ) {
115 stop "No output path specified";
116 }
117
118
119
120
121
122 #####################################################################
123 # Generate the Test Scripts
124
125 my $Inline = Test::Inline->new( %args )
126 or stop "Error creating Test::Inline object";
127 defined $Inline->add_all or stop "Error during ->add_all()";
128 defined $Inline->save or stop "Error while saving scripts";
129
130 exit(0) unless $args{execute};
131
132
133
134
135
136 #####################################################################
137 # Execute Scripts
138
139 my $schedule = $Inline->schedule;
140 unless ( defined $schedule ) {
141 stop "Error getting schedule to execute scripts";
142 }
143 unless ( $schedule ) {
144 stop "Nothing to execute";
145 }
146
147 eval "use ExtUtils::Command::MM;";
148 die $@ if $@;
149
150 @ARGV = map { catfile($args{output}, $_) } @$schedule;
151 test_harness(0);
152
153
154
155
156
157 #####################################################################
158 # Support Functions
159
160 sub stop ($) {
161 print "$_[0]\n";
162 exit(1);
163 }
164
165 __END__
166
167 =pod
168
169 =encoding UTF-8
170
171 =head1 NAME
172
173 inline2test - The Test::Inline 2 Test Compiler
174
175 =head1 VERSION
176
177 version 2.214
178
179 =head1 DESCRIPTION
180
181 C<inline2test> is the L<Test::Inline> 2 test compiler.
182
183 It's job is to scan through an arbitrary tree of Perl source code files,
184 locate inline test sections, extract them, convert them to test scripts,
185 and write them to an output path.
186
187 =head1 SYNOPIS
188
189 > inline2test ./inline2test.conf
190
191 # In your inline2test.conf
192 input=lib
193 output=t
194 execute=0
195 verbose=1
196 readonly=1
197 header=inline2text.txt
198
199 =head1 SUPPORT
200
201 Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Inline>
202 (or L<[email protected]|mailto:[email protected]>).
203
204 =head1 AUTHOR
205
206 Adam Kennedy <[email protected]>
207
208 =head1 COPYRIGHT AND LICENSE
209
210 This software is copyright (c) 2003 by Adam Kennedy.
211
212 This is free software; you can redistribute it and/or modify it under
213 the same terms as the Perl 5 programming language system itself.
214
215 =cut