Skip to content

Commit 13b4586

Browse files
author
timlinux
committed
Add stubs for methods from class being tested automatically
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5234 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e347705 commit 13b4586

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tests/src/core/test_builder.pl

+22-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@
2929
$testClass =<STDIN>;
3030
chop $testClass;
3131
$testClassLowerCaseName = lc($testClass); #todo convert to lower case
32+
print "Stubs will be created for the following methods:\n";
33+
open CPPFILE, "<../../../src/core/$testClassLowerCaseName.cpp"|| die 'Unable to open header file $testClassLowerCaseName.cpp';
34+
$stubString="";
35+
while(<CPPFILE>)
36+
{
37+
if(m/${testClass}::[A-Za-z0-9]*\(/)
38+
{
39+
#get the matched part of the line
40+
$line = $&;
41+
#strip off the ::
42+
$line =~ s/:://g;
43+
#strip off the (
44+
$line =~ s/\(//g;
45+
#add it to our stub code
46+
$stubString = $stubString . " void $line()\n\(\n\n\)\n";
47+
#show the user the list
48+
print $line;
49+
}
50+
}
51+
print $stubString;
52+
print "-----------------------------\n";
3253
print "Create the unit test? [y/n]: ";
3354
$createIt = <STDIN>;
3455
chop $createIt;
@@ -43,11 +64,7 @@
4364
# Substitute the class name in the file
4465
system("perl -pi -e 's/\\\[testClassLowerCaseName\\\]/$testClassLowerCaseName/g' test$testClassLowerCaseName.cpp");
4566
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-
67+
system("perl -pi -e 's/\\\[TestMethods\\\]/$stubString/g' test$testClassLowerCaseName.cpp");
5168
# Add an entry to Makefile.am
5269
open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am';
5370
open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod';

0 commit comments

Comments
 (0)