#!/usr/bin/perl use strict; use warnings; #Check command line arguments die "Incorrect number of arguments\n\tFormat : generalize_tests \n\n" if ( $#ARGV != 0 ); my $package = $ARGV[0]; my @bits = split "/", $package; my $datadir = ""; my $new_package = ""; for ( 0 .. scalar @bits - 2 ) { $datadir .= $bits[$_] . "/"; $new_package .= $bits[$_] . "::"; } $new_package .= $bits[scalar @bits - 1]; $new_package =~ s/\.pm//; print "NEW PACKAGE : $new_package\n"; chop $datadir; #make a directory to store the tests my $testdir = "t"; if ( ! -d "$datadir/$testdir" ) { system ("mkdir $datadir/$testdir"); } #get the list of subroutines my @files = glob("$datadir/data/*.type"); print "Creating tests for the following Subroutines\n\n"; my $f; foreach $f ( sort @files ) { if ( -s $f ) { $f =~ /$datadir\/data\/(\w+).type/; my $subroutine = $1; print "$subroutine "; open SUB, "<$f" or die "Could not open file for read2 : $!\n"; my @lines = ; close (SUB); my %hash; #Now create a hash of hashes of what each subroutine can take as inputs foreach my $l (@lines) { chomp $l; my @arr = split ',', $l; for ( 0 .. scalar @arr - 1) { ${$hash{$_}}{$arr[$_]} = 1; } } foreach my $h ( keys %hash ) { #print "[$h] : "; foreach my $k ( keys %{$hash{$h}} ) { # print "$k "; } #print "\n"; } #Now create tests based on the input parameters. $f =~ s/\/data\//\/t\//; $f =~ s/\.type/\.t/; open "TEST", ">$f" or die "Could not open file for write : $!\n"; print TEST <<__END__; use Test::More tests=> 1; use $new_package; my \$self = $new_package->new(); ok(\$self->$subroutine(), "Testing $subroutine with no args"); __END__ close (TEST); } } print "\n\n";