16 # 0 = default/reading, 1 = header, 2 = function/setup/teardown,
19 # buffer to store everything in until state change
21 # list of acceptable commands
22 my @_commands = qw(.Header .SetUp .TearDown .Vars .End);
27 print STDERR
"error: $msg\n";
33 error
("$_filename:$lineno: $msg");
38 print STDERR
"warning: $msg\n";
44 warning
("$_filename:$lineno: $msg");
48 open(COUT
,">",$_output) or error
$!;
58 $_buffer .= $_smallbuf;
63 $_smallbuf .= "}\n\n";
64 # append to funcbuffer
65 $_funcbuffer .= $_smallbuf;
70 $_varbuffer .= $_smallbuf;
73 # reset state and smallbuf
80 if($_state == 0 && $_smallbuf ne "") {
81 errorl
($_lineno, "Filler not in section");
84 if(!($line =~ m/^@\.?[[:alnum:]_]+:.*$/) && !($line eq "@.End")) {
85 errorl
($_lineno, "Invalid \@-section identifier: `$line'");
88 #my command is your line
89 $line =~ m/^@(\.?[[:alnum:]]+):?/;
92 #check for invalid command
93 if($command =~ m/^\./) {
94 my @match = grep { $_ eq $command } @_commands;
95 if(scalar @match != 1) {
96 errorl
$_lineno, "Invalid command: `$command'";
100 #check for non-strict syntax
102 if($command ne ".End") {
103 warningl
$_lineno, "New \@-section without closing \@.End";
104 warningl
$_lineno, "Assuming implicit \@.End";
109 #find what command we're actually going to use...
113 errorl
$_lineno, "Double declaration of `\@.Header' section";
117 $_buffer .= "#line $_lineno \"$_filename\"\n";
121 if($_declared{".SetUp"}) {
122 errorl
$_lineno, "Double declaration of `\@.SetUp' section";
125 $_declared{".SetUp"} = 1;
126 $_funcbuffer .= "#line $_lineno \"$_filename\"\nvoid setUp() {\n";
130 if($_declared{".TearDown"}) {
131 errorl
$_lineno,"Double declaration of `\@.TearDown' section";
134 $_declared{".TearDown"} = 1;
135 $_funcbuffer .= "#line $_lineno \"$_filename\"\nvoid tearDown() {\n";
139 if($_varbuffer ne "") {
140 errorl
$_lineno, "Double declaration of `\@.Vars' section";
143 $_varbuffer = "\n#line $_lineno \"$_filename\"\n";
152 # no special command... Then it must be a function name...
153 if($_declared{$command}) {
154 errorl
$_lineno, "Double declaration of `$command' testcase";
156 if($command eq "setUp") {
157 errorl
$_lineno, "Tried to create a testcase with name `setUp'"
159 if($command eq "tearDown") {
160 errorl
$_lineno, "Tried to create a testcase with name `tearDown'"
164 $_declared{$command} = 1;
165 $_funcbuffer .= "#line $_lineno \"$_filename\"\nvoid $command() {\n";
167 # check for extra attrs...
168 if($line =~ m/:\s*throw\(\s*([[:alnum:]:_]+)\s*\)$/) {
169 $_funclist .= "CPPUNIT_TEST_EXCEPTION($command,$1);\n";
171 $_funclist .= "CPPUNIT_TEST($command);\n";
176 my $classname = $_classname;
177 $classname =~ s/\.cpp$//;
178 $classname = "Test" . ucfirst $classname;
181 /* Generated by mktest.pl. Do not modify by hand! */
183 // include CPPUnit header
184 #include <cppunit/extensions/HelperMacros.h>
189 open(CIN
, "<", $_filename) or error
$!;
190 while(my $line = <CIN
>) {
192 #test if $line is a special marker
193 my $chompline = $line;
195 if($chompline =~ m/^@.*/) {
199 # nop, copy in to out.
201 if(!($line eq "\n") || $_state != 0) {
202 $_smallbuf .= "$line";
206 #okay, so we are done. Now let's put everything togheter...
207 #$_buffer should contain the header...
208 #so, add the class declaration
211 class $classname : public CppUnit::TestFixture {
213 CPPUNIT_TEST_SUITE($classname);
215 #add the function lists
216 $_buffer .= $_funclist;
220 CPPUNIT_TEST_SUITE_END();
225 $_buffer .= $_funcbuffer;
228 $_buffer .= "// Variable list\nprivate:$_varbuffer";
235 // register test suite with CppUnit
236 CPPUNIT_TEST_SUITE_REGISTRATION($classname);
243 #first check for args...
244 if($#ARGV != 1 or $ARGV[0] =~ m/^-{1,2}h(elp)?$/) {
245 printf STDERR
"Usage: mktest.pl <in> <out>" ;
248 $_filename = $ARGV[0];
250 #check if filename is a testcase (tst)
251 if(not $_filename =~ m/.*\.tst$/) {
252 warning
"$_filename does not have .tst extension -- is it testcase?" ;
255 #get the name of the output file
256 $_output = basename
$_filename;
257 $_output =~ s/\..*?$/.cpp/;
258 $_classname = $_output;
259 $_output = $ARGV[1] . "/" . $_output;