[ID 19990821.001] [PATCH] perl5.005_60 cygwin port
[p5sagit/p5-mst-13.2.git] / t / lib / dprof.t
CommitLineData
95667ae4 1#!perl
583a019e 2
95667ae4 3BEGIN {
4 chdir( 't' ) if -d 't';
5 unshift @INC, '../lib';
6}
583a019e 7
8use Benchmark qw( timediff timestr );
9use Getopt::Std 'getopts';
10use Config '%Config';
11getopts('vI:p:');
12
13# -v Verbose
14# -I Add to @INC
15# -p Name of perl binary
16
95667ae4 17@tests = @ARGV ? @ARGV : sort <lib/dprof/*_t lib/dprof/*_v>; # glob-sort, for OS/2
583a019e 18
19$path_sep = $Config{path_sep} || ':';
583a019e 20$perl5lib = $opt_I || join( $path_sep, @INC );
21$perl = $opt_p || $^X;
22
23if( $opt_v ){
24 print "tests: @tests\n";
25 print "perl: $perl\n";
26 print "perl5lib: $perl5lib\n";
27}
28if( $perl =~ m|^\./| ){
29 # turn ./perl into ../perl, because of chdir(t) above.
30 $perl = ".$perl";
31}
32if( ! -f $perl ){ die "Where's Perl?" }
33
34sub profile {
35 my $test = shift;
36 my @results;
37 local $ENV{PERL5LIB} = $perl5lib;
38 my $opt_d = '-d:DProf';
39
40 my $t_start = new Benchmark;
41 open( R, "$perl $opt_d $test |" ) || warn "$0: Can't run. $!\n";
42 @results = <R>;
43 close R;
44 my $t_total = timediff( new Benchmark, $t_start );
45
46 if( $opt_v ){
47 print "\n";
48 print @results
49 }
50
51 print timestr( $t_total, 'nop' ), "\n";
52}
53
54
55sub verify {
56 my $test = shift;
57
95667ae4 58 system $perl, '-I../lib', '-I./lib/dprof', $test,
59 $opt_v?'-v':'', '-p', $perl;
583a019e 60}
61
62
63$| = 1;
95667ae4 64print "1..18\n";
583a019e 65while( @tests ){
66 $test = shift @tests;
95667ae4 67 if( $test =~ /_t$/i ){
68 print "# $test" . '.' x (20 - length $test);
583a019e 69 profile $test;
70 }
71 else{
72 verify $test;
73 }
74}
9394203c 75
76unlink("tmon.out");