|
From: Geisschaes <gei...@us...> - 2005-04-26 15:52:09
|
Update of /cvsroot/macattrick/macattrick/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3616 Added Files: objcunit2unitkit.pl Log Message: first version of objcunit2unitkit.pl added --- NEW FILE: objcunit2unitkit.pl --- #!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Pod::Usage; use File::Basename; my $inputdir = shift @ARGV; my $outputdir = shift @ARGV; die "output directory must be different from input directory. \n backup your files!" if $inputdir eq $outputdir; my @m_files = <$inputdir/*.m>; my @h_files = <$inputdir/*.h>; my @problems = (); foreach (@h_files) { process_header_file($_); } foreach (@m_files) { process_implementation_file($_); } print "\n\n\n-----------------------------------------\n"; if(@problems == 0) { print "NO PROBLEMS DETECTED-----------------------------------------\n"; } else { print "PLEASE REPAIR MANUALLY THE FOLLOWING PROBLEMS:\n-----------------------------------------\n"; foreach(@problems) { print "$_\n"; } print "\n" } sub process_implementation_file { my ($implementation_file) = @_; my $basename = basename $implementation_file; print "\n-----------------------------------------\nMIGRATING Implementation: $basename\n-----------------------------------------\n"; my $target_file = "$outputdir/$basename"; open IN, $implementation_file or die "could not read from $implementation_file"; open OUT, ">$target_file" or die "could not write to $target_file"; my $line = ""; while(<IN>) { chomp; if(s/message:(.*)\];\s*$/\];/) { pl($line, "message: $1 removed"); } if(/assertTrue:/) { if(s/^(.*)\[self\s+assertTrue:(.*)\]\s*;\s*$/${1}UKTrue($2);/) { pl($line, "assertTrue: replaced with UKTrue"); } else {wrong($basename, $line, $_);} } elsif(/assertFalse:/) { if(s/^(.*)\[self\s+assertFalse:(.*)\]\s*;\s*$/${1}UKTrue($2);/) { pl($line, "assertFalse: replaced with UKFalse"); } else {wrong($basename, $line, $_);} } elsif(/assertNil:/) { if(s/^(.*)\[self\s+assertNil:(.*)\]\s*;\s*$/${1}UKNil($2);/) { pl($line, "assertNil: replaced with UKNil"); } else {wrong($basename, $line, $_);} } elsif(/assertNotNil:/) { if(s/^(.*)\[self\s+assertNotNil:(.*)\]\s*;\s*$/${1}UKNotNil($2);/) { pl($line, "assertNotNil: replaced with UKNotNil"); } else {wrong($basename, $line, $_);} } elsif(/assertInt:/) { if(s/^(.*)\[self\s+assertInt:(.*)equals:(.*)\s*\]\s*;\s*$/${1}UKIntsEqual($2,$3);/) { pl($line, "assertInt:equals: replaced with UKIntsEqual"); } else {wrong($basename, $line, $_);} } elsif(/assertFloat:/) { if(s/^(.*)\[self\s+assertFloat:(.*)equals:(.*)\s*precision:(.*)\]\s*;\s*$/${1}UKFloatsEqual($2,$3,$4);/) { pl($line, "assertFloat:equals:precision: replaced with UKFloatsEqual"); } else {wrong($basename, $line, $_);} } elsif(/assertString:/) { if(s/^(.*)\[self\s+assertString:(.*)equals:(.*)\s*\]\s*;\s*$/${1}UKStringsEqual($2,$3);/) { pl($line, "assertString:equals replaced with UKStringsEqual"); } else {wrong($basename, $line, $_);} } elsif(/assert:/) { if(s/^(.*)\[self\s+assert:(.*)equals:(.*)\s*\]\s*;\s*$/${1}UKObjectsEqual($2,$3);/) { pl($line, "assert:equals replaced with UKObjectsEqual"); } elsif(s/^(.*)\[self\s+assert:(.*)same:(.*)\s*\]\s*;\s*$/${1}UKObjectsSame($2,$3);/) { pl($line, "assert:same replaced with UKObjectsSame"); } else {wrong($basename, $line, $_);} } elsif(/assert/) { wrong($basename, $line, $_); } elsif(/setUp/) { wrong($basename, $line, $_); } print OUT "$_\n"; $line++; } } sub wrong { my ($filename, $linenr, $linetext) = @_; push @problems, "$filename line $linenr: $linetext"; print "some problems on line $linenr $linetext\n"; } sub pl { my ($line, $text) = @_; print "line $line: $text\n"; } sub process_header_file { my ($header_file) = @_; my $basename = basename $header_file; print "\n-----------------------------------------\nMIGRATING Header: $basename\n-----------------------------------------\n"; my $target_file = "$outputdir/$basename"; open IN, $header_file or die "could not read from $header_file"; open OUT, ">$target_file" or die "could not write to $target_file"; my $line = 1; while(<IN>) { if(s/^(.*)import\s+<ObjcUnit\/ObjcUnit.h>(.*)$/${1}import <UnitKit\/UnitKit.h>$2/) { pl($line, "import statement replaced"); } if(s/^(.*):\s*TestCase(.*)$/${1}: NSObject <UKTest>$2/) { pl($line, "super class TestCase changed to NSObject <UKTest>") } if(s/^(.*):\s*TestSuite(.*)$/${1}: NSObject$2/) { pl($line, "super class TestSuite changed to NSObject. This file can probably be removed."); } $line++; print OUT $_; } } __END__ =head1 NAME objcunit2unitkit.pl - migrate unit test of objcunit to unitkit =head1 SYNOPSIS objcunit2unitkit.pl inputdir outputdir =head1 OPTIONS =over 8 =item B<-h, -help> Print a brief help message and exits. =item B<-m, --man> Prints the manual page and exits. =back =head1 REQUIRES File::Basename, Getopt::Long, Pod::Usage =head1 AUTHOR Roman Bertolami 2005, gei...@us... =cut |