From 2dd247dae8b940c05db7ca8342fa571846b790f9 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 10 Nov 2020 13:45:05 -0800 Subject: [PATCH] Improve parsing of comments without spaces after the # Better handle cases with empty test scripts --- testing/bin/ktest-to-cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/testing/bin/ktest-to-cxx b/testing/bin/ktest-to-cxx index b86bbfd5..2d86ab88 100644 --- a/testing/bin/ktest-to-cxx +++ b/testing/bin/ktest-to-cxx @@ -60,7 +60,7 @@ sub load_from_text { if ( $line eq '' ) { next; } - if ( $line =~ /^(.*?)\s*#\s+(.*)$/ ) { + if ( $line =~ /^(.*?)\s*#\s*(.*)$/ ) { $line = $1; $comment = $2; } @@ -235,8 +235,8 @@ sub generate_script { elsif ( my $action = $entry->{action} ) { if ( $action eq 'name' ) { generate_start_new_test($entry) } - elsif ( !$inside_test ) { - die "Attempting to run an action when not inside a test section on line " . $entry->{line_num} . "\n"; + elsif ( !$inside_test && defined $action ) { + die "Attempting to run an action '$action' when not inside a test section on line " . $entry->{line_num} . "\n"; } elsif ( $action eq 'press' ) { generate_press($entry) } elsif ( $action eq 'release' ) { generate_release($entry); } @@ -248,8 +248,9 @@ sub generate_script { } } - - generate_end_test(); + if ($inside_test) { + generate_end_test(); + } }