Little bits of refactoring to the ktest parser

pull/966/head
Jesse Vincent 4 years ago
parent 4517ff7c0e
commit 533b6da571
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -51,6 +51,7 @@ sub load_from_text {
chomp $line; chomp $line;
$line =~ s/^\s+//; $line =~ s/^\s+//;
$line =~ s/\s+$//;
if ( $line eq '' ) { if ( $line eq '' ) {
next; next;
@ -78,13 +79,13 @@ sub load_from_text {
}, },
type => sub { type => sub {
my $type = shift; my $type = shift;
$type =~ s/\s//g; $type =~ s/\s(\w)/uc($1)/eg;
$test->{type} = $type; $test->{type} = $type;
return undef; return undef;
}, },
name => sub { name => sub {
my $name = shift; my $name = shift;
$name =~ s/\s//g; $name =~ s/\s(\w)/uc($1)/eg;
$test->{name} = $name; $test->{name} = $name;
return undef; return undef;
}, },
@ -174,6 +175,7 @@ sub load_from_text {
}; };
} }
close ($text_fh); close ($text_fh);
@script_lines = @content; @script_lines = @content;
} }
@ -181,52 +183,13 @@ sub load_from_text {
sub generate_test_file { sub generate_test_file {
my $preface = <<EOF; generate_preface();
#include "testing/setup-googletest.h"
#include "Kaleidoscope.h"
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !! WARNING! This test file was automatically generated. !!
// !! It -will- be overwritten on on subsequent test runs. !!
// !! Do not edit it. You will be sad, when you lose all !!
// !! your changes. !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Source file: @{[File::Spec->rel2abs( $text_filename ) ]}
SETUP_GOOGLETEST();
namespace kaleidoscope {
namespace testing {
namespace {
class KeyboardReports : public VirtualDeviceTest {};
EOF
for my $line (split/\n/,$preface) {
cxx($line);
}
cxx( "TEST_F(" . $test->{type} . "," . $test->{name} . ") {" );
indent();
generate_key_addrs(); generate_key_addrs();
generate_script( ); generate_script( );
outdent(); generate_postscript();
cxx("} // TEST_F");
my $postscript = <<EOF;
} // namespace
} // namespace testing
} // namespace kaleidoscope
EOF
for my $line (split/\n/,$postscript) {
cxx($line);
}
if ( $depth != 0 ) { if ( $depth != 0 ) {
die "Unbalanced indentation"; die "Unbalanced indentation";
@ -248,6 +211,9 @@ sub generate_key_addrs {
sub generate_script { sub generate_script {
cxx_section("Test script"); cxx_section("Test script");
cxx( "TEST_F(" . $test->{type} . "," . $test->{name} . ") {" );
indent();
$reports_expected = 0; $reports_expected = 0;
for my $entry (@script_lines) { for my $entry (@script_lines) {
@ -264,9 +230,14 @@ sub generate_script {
} }
} }
} }
if ($reports_expected) { if ($reports_expected) {
generate_check_expected_reports(); generate_check_expected_reports();
} }
outdent();
cxx("} // TEST_F");
} }
sub generate_run { sub generate_run {
@ -318,6 +289,47 @@ sub generate_check_expected_reports {
cxx(""); cxx("");
} }
sub generate_preface {
my $preface = <<EOF;
#include "testing/setup-googletest.h"
#include "Kaleidoscope.h"
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !! WARNING! This test file was automatically generated. !!
// !! It -will- be overwritten on on subsequent test runs. !!
// !! Do not edit it. You will be sad, when you lose all !!
// !! your changes. !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Source file: @{[File::Spec->rel2abs( $text_filename ) ]}
SETUP_GOOGLETEST();
namespace kaleidoscope {
namespace testing {
namespace {
class @{[$test->{type}]} : public VirtualDeviceTest {};
EOF
for my $line (split/\n/,$preface) {
cxx($line);
}
}
sub generate_postscript {
my $postscript = <<EOF;
} // namespace
} // namespace testing
} // namespace kaleidoscope
EOF
for my $line (split/\n/,$postscript) {
cxx($line);
}
}
sub indent { sub indent {
$depth += 2; $depth += 2;
} }

Loading…
Cancel
Save