|
| 1 | +#!/usr/bin/perl |
| 2 | +use Cwd; |
| 3 | + |
| 4 | +##################################################### |
| 5 | +# A script to automate creation of a new unit test |
| 6 | +# Authors TSutton |
| 7 | +# April 08, 2006 |
| 8 | +##################################################### |
| 9 | +# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ # |
| 10 | + |
| 11 | +#make sure we are in a the tests/src/core dir |
| 12 | +$myDir = fastgetcwd; |
| 13 | +print "\n\nChecking that we are in the <qgis dir>/test/src/core/ directory...."; |
| 14 | +if ($myDir =~ m/tests\/src\/core$/) |
| 15 | +{ |
| 16 | + print "yes\n"; |
| 17 | +} |
| 18 | +else |
| 19 | +{ |
| 20 | + print "no\n"; |
| 21 | + print $myDir; |
| 22 | + print "\nPlease relocate to the /test/src/core/ directory before attempting to run this script.\n"; |
| 23 | + exit; |
| 24 | +} |
| 25 | +# get the needed information from the user |
| 26 | +print "\n\nEnter the name of the class for which the test will be created.\n"; |
| 27 | +print "Used mixed case notation.\n"; |
| 28 | +print "e.g. QgsSymbol\n"; |
| 29 | +$testClass =<STDIN>; |
| 30 | +chop $testClass; |
| 31 | +$testClassLowerCaseName = lc($testClass); #todo convert to lower case |
| 32 | +print "Create the unit test? [y/n]: "; |
| 33 | +$createIt = <STDIN>; |
| 34 | +chop $createIt; |
| 35 | + |
| 36 | +if(($createIt eq 'y') || ($createIt eq 'Y')) |
| 37 | +{ |
| 38 | + # |
| 39 | + # its a go -- create the unit test and modify the build files |
| 40 | + # |
| 41 | + system("cp test_template.cpp test$testClassLowerCaseName.cpp"); |
| 42 | + |
| 43 | + # Substitute the class name in the file |
| 44 | + system("perl -pi -e 's/\\\[testClassLowerCaseName\\\]/$testClassLowerCaseName/g' test$testClassLowerCaseName.cpp"); |
| 45 | + system("perl -pi -e 's/\\\[testClassCamelCaseName\\\]/$testClass/g' test$testClassLowerCaseName.cpp"); |
| 46 | + # |
| 47 | + # TODO: write a parser to pull out method signatures from class bing tested and create a stub |
| 48 | + # for each method in the generated test class to replace teh [TestMethods] placeholder |
| 49 | + # |
| 50 | + |
| 51 | + # Add an entry to Makefile.am |
| 52 | + open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am'; |
| 53 | + open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod'; |
| 54 | + # read through Makefile.am and write each line to Makefile.am.mod |
| 55 | + while(<MAKEFILE>) |
| 56 | + { |
| 57 | + if(/^\s*bin_PROGRAMS =*/) |
| 58 | + { |
| 59 | + # add our application binary name to the next line |
| 60 | + print MAKEFILEMOD "\\"; |
| 61 | + print MAKEFILEMOD "\t\t$testClassLowerCaseName \n"; |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + print MAKEFILEMOD; |
| 66 | + } |
| 67 | + if(/^\s*BUILT_SOURCES =*/) |
| 68 | + { |
| 69 | + # add our application binary name to the next line |
| 70 | + print MAKEFILEMOD "\\"; |
| 71 | + print MAKEFILEMOD "\t\t${testClassLowerCaseName}_MOC \n"; |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + print MAKEFILEMOD; |
| 76 | + } |
| 77 | + } |
| 78 | + #before closing the file add the lines for our new test class |
| 79 | + print MAKEFILEMOD "test${testClassLowerCaseName}_MOC = test${testClassLowerCaseName}.moc.cpp" |
| 80 | + print MAKEFILEMOD "test${testClassLowerCaseName}_SOURCES = ${testClassLowerCaseName}.cpp" |
| 81 | + print MAKEFILEMOD "test${testClassLowerCaseName}_LDADD = $(GLOBALLDADD)" |
| 82 | + print MAKEFILEMOD "test${testClassLowerCaseName}_CXXFLAGS = $(GLOBALCXXFLAGS)" |
| 83 | + |
| 84 | + # close the Makefile file handles |
| 85 | + close MAKEFILEMOD; |
| 86 | + close MAKEFILE; |
| 87 | + |
| 88 | + # save Makefile.am in case we die before done moving things around |
| 89 | + system("mv Makefile.am Makefile.am.save"); |
| 90 | + # move the new Makefile.am to where it belongs |
| 91 | + system("mv Makefile.am.mod Makefile.am"); |
| 92 | + # delete the original Makefile.am |
| 93 | + unlink("Makefile.am.save"); |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | +print << "EOP"; |
| 98 | +
|
| 99 | +Your test unit has been created now as testClassLowerCaseName.cpp. |
| 100 | +
|
| 101 | +EOP |
| 102 | + |
| 103 | +}else{ |
| 104 | + # user cancelled |
| 105 | + print "Test unit not created\n"; |
| 106 | +} |
| 107 | + |
0 commit comments