File: inline2test

package info (click to toggle)
libtest-inline-perl 2.214-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 596 kB
  • sloc: perl: 2,016; makefile: 2
file content (215 lines) | stat: -rw-r--r-- 4,801 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/perl
# PODNAME: inline2test
# ABSTRACT: The Test::Inline 2 Test Compiler

#pod =pod
#pod
#pod =head1 SYNOPIS
#pod
#pod   > inline2test ./inline2test.conf
#pod   
#pod   # In your inline2test.conf
#pod   input=lib
#pod   output=t
#pod   execute=0
#pod   verbose=1
#pod   readonly=1
#pod   header=inline2text.txt
#pod
#pod =head1 DESCRIPTION
#pod
#pod C<inline2test> is the L<Test::Inline> 2 test compiler.
#pod
#pod It's job is to scan through an arbitrary tree of Perl source code files,
#pod locate inline test sections, extract them, convert them to test scripts,
#pod and write them to an output path.
#pod
#pod =cut

use strict;
use File::Spec::Functions  ':ALL';
use Getopt::Long           ();
use Config::Tiny           ();
use Test::Inline           ();
use Test::Inline::IO::File ();

our $VERSION = '2.214';

# Predeclare things
sub stop ($);





#####################################################################
# Process Options, Input and Config

my $execute  = '';
my $changed  = '';
my $verbose  = '';
my $readonly = '';
my $rv = Getopt::Long::GetOptions(
	execute  => \$execute,
	changed  => \$changed,
	verbose  => \$verbose,
	readonly => \$readonly,
	);
exit(0) unless $rv;

# Get the config file
my $config    = shift @ARGV;
my $configdir = 1;
unless ( $config ) {
	# Use a default inline2test.conf in the current directory if it exists
	my $default = catfile( curdir(), 'inline2test.conf' );
	if ( -f $default ) {
		$config = curdir();
	} else {
		stop("You did not provide an config file name");
	}
}
if ( -d $config ) {
	# They point to a directory, not a file
	$configdir = $config;
	my $file = catfile( $config, 'inline2test.conf' );
	if ( -f $file ) {
		$config = $file;
	} else {
		stop("The directory $config does not contain an inline2test.conf file");
	}
}
my $Config = Config::Tiny->read($config) or stop("Failed to load config file");
my %args = %{$Config->{_}}               or stop("No config entries found");

# Add any forced options
$args{execute}  = 1 if $execute;
$args{changed}  = 1 if $changed;
$args{verbose}  = 1 if $verbose;
$args{readonly} = 1 if $readonly;

# Automatically use an inline2test.tpl file if it exists
if ( $configdir and ! $args{template} ) {
	my $file = catfile( $configdir, 'inline2test.tpl' );
	$args{template} = $file if -f $file;
}

# Create ContentHandler if needed
if ( $args{template} ) {
	# Convert to a proper contenthandler
	my $template = delete $args{template};
	$args{ContentHandler} = Test::Inline::Content::Simple->new( $template )
		or stop("Failed to create ContentHandler for $template");
}

# Create InputHandler
if ( $args{input} ) {
	# Convert to a proper inputhandler
	my $input = delete $args{input};
	$args{InputHandler} = Test::Inline::IO::File->new( $input )
		or stop("Failed to create InputHandle for $input");
}

# We need an output
unless ( $args{output} ) {
	stop "No output path specified";
}





#####################################################################
# Generate the Test Scripts

my $Inline = Test::Inline->new( %args )
	or stop "Error creating Test::Inline object";
defined $Inline->add_all or stop "Error during ->add_all()";
defined $Inline->save    or stop "Error while saving scripts";

exit(0) unless $args{execute};





#####################################################################
# Execute Scripts

my $schedule = $Inline->schedule;
unless ( defined $schedule ) {
	stop "Error getting schedule to execute scripts";
}
unless ( $schedule ) {
	stop "Nothing to execute";
}

eval "use ExtUtils::Command::MM;";
die $@ if $@;

@ARGV = map { catfile($args{output}, $_) } @$schedule;
test_harness(0);





#####################################################################
# Support Functions

sub stop ($) {
	print "$_[0]\n";
	exit(1);
}

__END__

=pod

=encoding UTF-8

=head1 NAME

inline2test - The Test::Inline 2 Test Compiler

=head1 VERSION

version 2.214

=head1 DESCRIPTION

C<inline2test> is the L<Test::Inline> 2 test compiler.

It's job is to scan through an arbitrary tree of Perl source code files,
locate inline test sections, extract them, convert them to test scripts,
and write them to an output path.

=head1 SYNOPIS

  > inline2test ./inline2test.conf
  
  # In your inline2test.conf
  input=lib
  output=t
  execute=0
  verbose=1
  readonly=1
  header=inline2text.txt

=head1 SUPPORT

Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Inline>
(or L<bug-Test-Inline@rt.cpan.org|mailto:bug-Test-Inline@rt.cpan.org>).

=head1 AUTHOR

Adam Kennedy <adamk@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2003 by Adam Kennedy.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut