There's no real need to vary the generated test

class for each generated test file. removing
this makes test definitions simpler

Also, grow support for multiple tests within a script

Signed-off-by: Jesse Vincent <jesse@keyboard.io>
pull/969/head
Jesse Vincent 4 years ago
parent 5a9aa3b3a9
commit 7e5b05e447
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -13,6 +13,10 @@ my $depth = 0;
my $reports_expected = 0; my $reports_expected = 0;
my @script_lines; my @script_lines;
my $named_switches = {}; my $named_switches = {};
my $inside_test = 0;
my $test_class = 'GeneratedKTest';
GetOptions( GetOptions(
"cxx=s" => \$cxx_filename, # string "cxx=s" => \$cxx_filename, # string
@ -77,19 +81,11 @@ sub load_from_text {
} }
return undef; return undef;
}, },
type => sub {
my $type = shift;
$type =~ s/\s(\w)/uc($1)/eg;
$test->{type} = $type;
return undef;
},
name => sub { name => sub {
my $name = shift; my $name = shift;
$name =~ s/\s(\w)/uc($1)/eg; $name =~ s/\s(\w)/uc($1)/eg;
$test->{name} = $name; return { test_name => $name };
return undef;
}, },
keyswitch => sub { keyswitch => sub {
my $content = shift; my $content = shift;
if ( $content =~ /^(.*)\s+(\d+)\s+(\d+)$/ ) { if ( $content =~ /^(.*)\s+(\d+)\s+(\d+)$/ ) {
@ -208,23 +204,44 @@ sub generate_key_addrs {
} }
} }
sub generate_start_new_test {
my $entry = shift;
my $name = $entry->{data}->{test_name};
if ($inside_test) {
generate_end_test();
}
cxx( "TEST_F(" . $test_class . "," . $name . ") {" );
$inside_test = 1;
indent();
}
sub generate_end_test {
if ($reports_expected) {
generate_check_expected_reports();
}
outdent();
cxx("} // TEST_F");
$inside_test = 0;
}
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) {
if ($entry->{comment} && (! $entry->{action} ) ) { if ( $entry->{comment} && ( !$entry->{action} ) ) {
cxx_comment($entry->{comment}); cxx_comment( $entry->{comment} );
} elsif (my $action = $entry->{action} ) { }
elsif ( my $action = $entry->{action} ) {
if ( $action eq 'press' ) { generate_press( $entry ) } if ( $action eq 'name' ) { generate_start_new_test($entry) }
elsif ( $action eq 'release' ) { generate_release( $entry ); } elsif ( !$inside_test ) {
elsif ( $action eq 'run' ) { generate_run( $entry ) } die "Attempting to run an action when not inside a test section on line " . $entry->{line_num} . "\n";
elsif ( $action eq 'expect' ) { generate_expect_report( $entry ); } }
elsif ( $action eq 'press' ) { generate_press($entry) }
elsif ( $action eq 'release' ) { generate_release($entry); }
elsif ( $action eq 'run' ) { generate_run($entry) }
elsif ( $action eq 'expect' ) { generate_expect_report($entry); }
else { else {
die "$action unknown on line $entry->{line_num}"; die "$action unknown on line $entry->{line_num}";
} }
@ -232,12 +249,8 @@ sub generate_script {
} }
if ($reports_expected) { generate_end_test();
generate_check_expected_reports();
}
outdent();
cxx("} // TEST_F");
} }
sub generate_run { sub generate_run {
@ -290,6 +303,7 @@ sub generate_check_expected_reports {
} }
sub generate_preface { sub generate_preface {
my $preface = <<EOF; my $preface = <<EOF;
#include "testing/setup-googletest.h" #include "testing/setup-googletest.h"
#include "Kaleidoscope.h" #include "Kaleidoscope.h"
@ -309,7 +323,7 @@ namespace kaleidoscope {
namespace testing { namespace testing {
namespace { namespace {
class @{[$test->{type}]} : public VirtualDeviceTest {}; class @{[$test_class]} : public VirtualDeviceTest {};
EOF EOF
for my $line (split/\n/,$preface) { for my $line (split/\n/,$preface) {

@ -1,5 +1,4 @@
VERSION 1 VERSION 1
TYPE KeyboardReports
NAME Keys Active When pressed NAME Keys Active When pressed
# Comment lines end up as comments in the generated source # Comment lines end up as comments in the generated source

@ -1,5 +1,4 @@
VERSION 1 VERSION 1
TYPE Keycode
NAME Keyboard Non Modifiers NAME Keyboard Non Modifiers
KEYSWITCH A 2 1 KEYSWITCH A 2 1
@ -17,7 +16,6 @@ RELEASE A
EXPECT keyboard-report empty # Report should be empty EXPECT keyboard-report empty # Report should be empty
# TODO, this should be generate a second test stanza # TODO, this should be generate a second test stanza
# TYPE Keycode
# NAME Keyboard Modifiers # NAME Keyboard Modifiers
RUN 10 ms RUN 10 ms

@ -1,5 +1,4 @@
TYPE Issue941 NAME Issue 941 one keypress per cycle
NAME one keypress per cycle
KEYSWITCH A 2 1 KEYSWITCH A 2 1
KEYSWITCH S 2 2 KEYSWITCH S 2 2

Loading…
Cancel
Save