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