/usr/bin/wibble-test-genrunner is in libwibble-dev 1.1-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #!/usr/bin/perl
my $set, %tests, %prefix, %filename;
my $mode = $ARGV[0];
shift @ARGV;
sub process() {
$file = shift;
my $in;
open IN, "$file";
$in .= $_ while (<IN>);
close IN;
$set = "not defined";
my $nest = 0, $depth = 0;
# TODO we should push/pop on { and }
for (split /[{]/, $in) {
$nest+=2; # for each item in split /}/, we decrement by 1
# meaning decrement by number of }, plus one 1
for (split /[}]/, $_) {
$nest--;
if ($nest < $depth) {
$set = "not defined";
$depth = 0;
}
for (split /[;]/, $_) {
#print "parsing: $_\n";
if (/struct ([tT]est_?)([A-Za-z][A-Za-z0-9_]*)/) {
#push @sets, $1;
$set = $2;
$filename{$set} = $file;
$prefix{$set} = $1;
$depth = $nest;
} elsif (/^[ \t]*Test[ \t\n]+([a-zA-Z_1-9]+)[ \t\n]*\(/sm) {
if ($set eq "not defined") {
print STDERR "W: test found out of scope of a Test structure, ignoring\n";
} else {
$test{$set} = () unless ($test{$set});
push @{$tests{$set}}, $1;
}
}
}
}
}
}
sub dumpfile() {
my $file = shift;
my $filecpp = $file;
$filecpp =~ s/.test.h$/.cpp/;
$filecpp =~ s,/,_,g;
print "#undef NDEBUG\n";
print "#include \"$file\"\n";
print "#define RUN(x,y) x().y()\n";
for (keys %tests) {
my $set = $_;
if ( $filename{$set} eq $file ) {
for (@{$tests{$set}}) {
print "void run_${set}_$_() {";
print " RUN( $prefix{$set}$set, $_ ); }\n";
}
}
}
}
sub dumpmain() {
print "#undef NDEBUG\n";
print "#include <wibble/test.h>\n";
print "#include <wibble/test-runner.h>\n";
for (keys %tests) {
my $set = $_;
for (@{$tests{$set}}) {
print "void run_${set}_$_();\n";
}
print "RunTest run_${set}"."[] = {\n";
print "\t{ \"$_\", run_${set}_$_ },\n" for (@{$tests{$set}});
print "};\n";
}
print "RunSuite suites[] = {\n";
for (keys %tests) {
my $count = scalar @{$tests{$_}};
print "{ \"$_\", run_$_, $count },\n";
}
print "};\n";
print "#include <wibble/test-main.h>\n";
#print "int assertFailure = 0;\n";
}
for $file (@ARGV) {
&process ($file);
}
if ($mode eq "header") {
for $file (@ARGV) {
&dumpfile($file);
}
}
if ($mode eq "main") {
&dumpmain;
}
|