0: A more flexible version of the test.pl script
1:
2: #!/usr/bin/perl -w
3:
4: use strict;
5: use DirHandle;
6: use Test::Harness;
7: use Getopt::Long;
8: use Pod::Usage;
9:
10: my $verbose = 0;
11: my $simple = 0;
12: my $man = 0;
13: my $help = 0;
14: my $testdir = 't';
15: my @tests = ();
16:
17: GetOptions(
18: 'help|?' => \$help,
19: "man" => \$man,
20: "testdir=s" => \$testdir,
21: "verbose" => \$verbose,
22: "simple" => \$simple,
23: );
24:
25: pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
26: pod2usage(1) if ($help and (! $simple));
27:
28: print "Looking for tests in test dir: $testdir\n" if ($verbose);
29:
30: if (scalar @ARGV) {
31: foreach my $file (@ARGV) {
32: print "Found test: $file\n" if ($verbose);
33: &append(\$file, \@tests, \$testdir);
34: }
35: } else {
36: opendir(DH, $testdir) or die "Couldn't open $testdir for reading: $!";
37: while(defined (my $file = readdir(DH)) ) {
38: next unless $file =~ /\.[t]$/i;
39: &append(\$file, \@tests, \$testdir);
40: }
41: }
42:
43: if ($simple) {
44: foreach my $test (@tests) {
45: print "\nRunning: $test\n\n";
46: system("perl $test");
47: }
48: } else {
49: runtests(@tests);
50: }
51:
52: exit;
53:
54: sub append {
55: my $file = shift;
56: my $tests = shift;
57: my $testdir = shift;
58:
59: my $filename = "$$testdir/$$file";
60: push(@$tests, $filename);
61:
62: return 1;
63: }
64:
65: __END__
66:
67: =head1 NAME
68:
69: test.pl - Runs tests
70:
71: =head1 SYNOPSIS
72:
73: test.pl [options] -- [testfiles]
74:
75: =head1 OPTIONS
76:
77: =over 8
78:
79: =item B<-verbose>
80:
81: More information will be displayed during processing.
82: This might not be necessary due to the verbosity of the
83: actual test data.
84:
85: =item B<-testdir>
86:
87: This is the test directory in which test.pl will look
88: for test files (files ending on .t. If not given t/ will
89: be assumed.
90:
91: =item B<-simple>
92:
93: The simple flag sets test.pl to run Test::Simple script to
94: be run so their own information is displayed
95: (normally suppressed by Test::Harness).
96:
97: Test::Simple scripts do also work under Test::Harness.
98:
99: =item B<-help>
100:
101: Prints a brief help message and exits.
102:
103: =item B<-man>
104:
105: Prints the manual page and exits.
106:
107: =back
108:
109: =head1 DESCRIPTION
110:
111: B<This program> will read the given input file(s) and run
112: any tests in these.
113:
114: So write your normal test files using Test or Test::Simple.
115: This script gives you a more flexible interface to testing
116: during development. You can tell the script what directory
117: your tests are in (-testdir).
118:
119: You can specify whether you want to have Test::Simple
120: output (I need to takes this with Michael Schwern at some
121: point). Or you can specify which test files you want
122: processed by listing them after the options (--).
123:
124: So all you need to do is follow the normal Perl test
125: writing conventions and then abuse this tool.
126:
127: =head1 AUTHOR
128:
129: jonasbn <jonasbn@wanadoo.dk>
130:
131: =head1 BUGS
132:
133: No known bugs.
134:
135: =head1 SEE ALSO
136:
137: =over 8
138:
139: =item Test::Simple
140:
141: =item Test::Harness
142:
143: =back
144:
145: =head1 COPYRIGHT
146:
147: Copyright (c) 2001 Jonas B. Nielsen. All rights
148: reserved. This program is free software; you can
149: redistribute it and/or modify it under the same
150: terms as Perl itself.
151:
152: =cut In reply to A spiked version of test.pl by jonasbn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |