From 208b4dea5ebdecc6e8b3bb13566d35d3a828887c Mon Sep 17 00:00:00 2001 From: timlinux Date: Sat, 8 Apr 2006 00:56:03 +0000 Subject: [PATCH] First draft at a little perl script to generate a test class with method stubs automatically git-svn-id: http://svn.osgeo.org/qgis/trunk@5220 c8812cc2-4d05-0410-92ff-de0c093fc19c --- tests/src/core/Makefile.am | 6 +- tests/src/core/test_builder.pl | 107 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) create mode 100755 tests/src/core/test_builder.pl diff --git a/tests/src/core/Makefile.am b/tests/src/core/Makefile.am index 185f782289e..7d1ba1f288c 100644 --- a/tests/src/core/Makefile.am +++ b/tests/src/core/Makefile.am @@ -24,6 +24,10 @@ GLOBALCXXFLAGS = $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(GDAL_CFLAGS) $(QT_CXXFLAGS) $(P %.moc.cpp: %.cpp $(MOC) -o $@ $< +BUILT_SOURCES = $(testqgsapplication_MOC) + +CLEANFILES = $(BUILT_SOURCES) + # # Specify the compilation files for each unit test now # @@ -33,6 +37,4 @@ testqgsapplication_SOURCES = testqgsapplication.cpp testqgsapplication_LDADD = $(GLOBALLDADD) testqgsapplication_CXXFLAGS = $(GLOBALCXXFLAGS) -BUILT_SOURCES = $(testqgsapplication_MOC) -CLEANFILES = $(BUILT_SOURCES) diff --git a/tests/src/core/test_builder.pl b/tests/src/core/test_builder.pl new file mode 100755 index 00000000000..6eb2e65d727 --- /dev/null +++ b/tests/src/core/test_builder.pl @@ -0,0 +1,107 @@ +#!/usr/bin/perl +use Cwd; + +##################################################### +# A script to automate creation of a new unit test +# Authors TSutton +# April 08, 2006 +##################################################### +# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ # + +#make sure we are in a the tests/src/core dir +$myDir = fastgetcwd; +print "\n\nChecking that we are in the /test/src/core/ directory...."; +if ($myDir =~ m/tests\/src\/core$/) +{ + print "yes\n"; +} +else +{ + print "no\n"; + print $myDir; + print "\nPlease relocate to the /test/src/core/ directory before attempting to run this script.\n"; + exit; +} +# get the needed information from the user +print "\n\nEnter the name of the class for which the test will be created.\n"; +print "Used mixed case notation.\n"; +print "e.g. QgsSymbol\n"; +$testClass =; +chop $testClass; +$testClassLowerCaseName = lc($testClass); #todo convert to lower case +print "Create the unit test? [y/n]: "; +$createIt = ; +chop $createIt; + +if(($createIt eq 'y') || ($createIt eq 'Y')) +{ + # + # its a go -- create the unit test and modify the build files + # + system("cp test_template.cpp test$testClassLowerCaseName.cpp"); + + # Substitute the class name in the file + system("perl -pi -e 's/\\\[testClassLowerCaseName\\\]/$testClassLowerCaseName/g' test$testClassLowerCaseName.cpp"); + system("perl -pi -e 's/\\\[testClassCamelCaseName\\\]/$testClass/g' test$testClassLowerCaseName.cpp"); + # + # TODO: write a parser to pull out method signatures from class bing tested and create a stub + # for each method in the generated test class to replace teh [TestMethods] placeholder + # + + # Add an entry to Makefile.am + open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am'; + open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod'; + # read through Makefile.am and write each line to Makefile.am.mod + while() + { + if(/^\s*bin_PROGRAMS =*/) + { + # add our application binary name to the next line + print MAKEFILEMOD "\\"; + print MAKEFILEMOD "\t\t$testClassLowerCaseName \n"; + } + else + { + print MAKEFILEMOD; + } + if(/^\s*BUILT_SOURCES =*/) + { + # add our application binary name to the next line + print MAKEFILEMOD "\\"; + print MAKEFILEMOD "\t\t${testClassLowerCaseName}_MOC \n"; + } + else + { + print MAKEFILEMOD; + } + } + #before closing the file add the lines for our new test class + print MAKEFILEMOD "test${testClassLowerCaseName}_MOC = test${testClassLowerCaseName}.moc.cpp" + print MAKEFILEMOD "test${testClassLowerCaseName}_SOURCES = ${testClassLowerCaseName}.cpp" + print MAKEFILEMOD "test${testClassLowerCaseName}_LDADD = $(GLOBALLDADD)" + print MAKEFILEMOD "test${testClassLowerCaseName}_CXXFLAGS = $(GLOBALCXXFLAGS)" + + # close the Makefile file handles + close MAKEFILEMOD; + close MAKEFILE; + + # save Makefile.am in case we die before done moving things around + system("mv Makefile.am Makefile.am.save"); + # move the new Makefile.am to where it belongs + system("mv Makefile.am.mod Makefile.am"); + # delete the original Makefile.am + unlink("Makefile.am.save"); + + } + +print << "EOP"; + +Your test unit has been created now as testClassLowerCaseName.cpp. + +EOP + +}else{ + # user cancelled + print "Test unit not created\n"; +} +