Skip to content

Commit 16cfe09

Browse files
committed
parser: ktap: Show full output by default if no line was parsed
In the case where a subtest don't have proper KTAP output, nothing will be shown in the UI. This is not ideal since it forces the user to open the individual log asset file and also prevent him from easily opening bugs from the helper buttons.
1 parent 131df4d commit 16cfe09

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

lib/OpenQA/Parser/Format/KTAP.pm

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ sub _parse_subtest ($self, $result) {
4848
$self->test or return;
4949

5050
my $line = $result->as_string;
51-
return unless $line =~ /^#\s*(?<status>ok|not ok)\s+(?<index>\d+)\s+(?<name>[^#]*)/;
51+
unless ($line =~ /^#\s*(?<status>ok|not ok)\s+(?<index>\d+)\s+(?<name>[^#]*)/) {
52+
push(@{$steps->{unparsed_lines}}, $line);
53+
return;
54+
}
55+
$steps->{parsed_lines_count}++;
5256
return if $line =~ /#\s*SKIP\b/i;
5357
my ($status, $index, $subtest_name) = @+{qw(status index name)};
5458

@@ -92,6 +96,22 @@ sub _testgroup_finalize ($self, $result) {
9296

9397
$steps->{name} = $self->test->{name};
9498
$steps->{test} = $self->test;
99+
100+
# If there are no parsed lines, default to simply show the whole log.
101+
# This is better than not showing anything, impeding the user to see
102+
# the buttons of adding product or test bugs and requiring him to
103+
# search and open individual log assets.
104+
if (!$steps->{parsed_lines_count}) {
105+
my $filename = "KTAP-@{[$steps->{name}]}.txt";
106+
push @{$steps->{details}},
107+
{
108+
text => $filename,
109+
title => $steps->{name},
110+
result => 'ok',
111+
};
112+
$self->_add_output({file => $filename, content => join("\n", @{$steps->{unparsed_lines}})});
113+
}
114+
95115
$self->generated_tests_results->add(OpenQA::Parser::Result::OpenQA->new($steps));
96116

97117
$self->test(undef);
@@ -106,13 +126,15 @@ sub parse ($self, $KTAP) {
106126
while (my $result = $parser->next) {
107127
next if $result->type eq 'version' || $result->type eq 'plan';
108128

109-
if ($result->type eq 'comment' && $result->as_string =~ /^#\s*selftests:\s+/) {
110-
$self->_testgroup_init($result->as_string);
111-
next;
112-
}
113-
if ($result->type eq 'comment' && $result->as_string =~ /^#\s*(ok|not ok)\s+\d+\s+/) {
114-
$self->_parse_subtest($result);
115-
next;
129+
if ($result->type eq 'comment') {
130+
if ($result->as_string =~ /^#\s*selftests:\s+/) {
131+
$self->_testgroup_init($result->as_string);
132+
next;
133+
}
134+
else {
135+
$self->_parse_subtest($result);
136+
next;
137+
}
116138
}
117139
if ($result->type eq 'test' && $result->description =~ /^selftests: /) {
118140
$self->_testgroup_finalize($result);

0 commit comments

Comments
 (0)