CC: | Shin Kojima <shin [...] kojima.org>, cpan [...] howlingfrog.com |
Subject: | [PATCH] Parse SKIP directives to produce "<skipped />" |
Date: | Fri, 25 Jan 2019 16:56:56 +0900 |
To: | bug-TAP-Formatter-JUnit [...] rt.cpan.org |
From: | Shin Kojima <shin [...] kojima.org> |
Signed-off-by: Shin Kojima <shin@kojima.org>
---
Hi, Mr.Graham
Today @randomguy on stackoverflow.com asked me how to create skipped
testcase using your TAP::Formatter::JUnit.
At first glance, I noticed your package haven't implemented SKIP
directive function yet, so I created a patch to do the job.
Please take a look.
TBH, I'm not familier with JUnit report XML and I couldn't even find
its specification that I should refer.
Let me know if I missed anything.
Thanks,
See also:
https://metacpan.org/author/SKJM
https://stackoverflow.com/questions/52953305/how-to-convert-a-generated-text-file-to-junit-formatxml-using-perl?noredirect=1#comment95534416_52953305
lib/TAP/Formatter/JUnit/Result.pm | 1 +
lib/TAP/Formatter/JUnit/Session.pm | 13 +++++++++++++
t/data/tap/junit/skip | 5 ++++-
t/data/tap/junit/skip_nomsg | 5 ++++-
t/data/tests/junit/skip | 5 ++++-
t/data/tests/junit/skip_nomsg | 5 ++++-
6 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/lib/TAP/Formatter/JUnit/Result.pm b/lib/TAP/Formatter/JUnit/Result.pm
index 5803334..a95a585 100644
--- a/lib/TAP/Formatter/JUnit/Result.pm
+++ b/lib/TAP/Formatter/JUnit/Result.pm
@@ -23,6 +23,7 @@ has 'result' => (
is_plan
is_unplanned
is_ok
+ has_skip
todo_passed
explanation
diff --git a/lib/TAP/Formatter/JUnit/Session.pm b/lib/TAP/Formatter/JUnit/Session.pm
index fb7dca3..33683e6 100644
--- a/lib/TAP/Formatter/JUnit/Session.pm
+++ b/lib/TAP/Formatter/JUnit/Session.pm
@@ -142,6 +142,12 @@ sub close_test {
}, $cdata );
}
+ # create a skipped element if the test was skipped
+ my $skipped;
+ if ($result->has_skip()) {
+ $skipped = $xml->skipped();
+ }
+
# add this test to the XML stream
my $case = $xml->testcase(
{
@@ -151,6 +157,7 @@ sub close_test {
),
},
$failure,
+ $skipped,
);
$self->add_testcase($case);
@@ -203,6 +210,7 @@ sub close_test {
my $testsrun = $parser->tests_run() || 0;
my $time = $parser->end_time() - $parser->start_time();
my $failures = $parser->failed();
+ my $skipped = $parser->skipped() || 0;
my $noplan = $parser->plan() ? 0 : 1;
my $planned = $parser->tests_planned() || 0;
@@ -233,6 +241,9 @@ sub close_test {
(
$timer_enabled ? ('time' => $time) : ()
),
+ (
+ $skipped > 0 ? ('skipped' => $skipped) : ()
+ ),
);
my $testsuite = $xml->testsuite(\%attrs, @tests, $sys_out, $sys_err, $suite_err);
$self->formatter->add_testsuite($testsuite);
@@ -283,6 +294,8 @@ sub _check_for_test_bogosity {
my $self = shift;
my $result = shift;
+ return if $result->has_skip();
+
if ($result->todo_passed() && !$self->passing_todo_ok()) {
return {
level => 'error',
diff --git a/t/data/tap/junit/skip b/t/data/tap/junit/skip
index 4ad97aa..761a3e0 100644
--- a/t/data/tap/junit/skip
+++ b/t/data/tap/junit/skip
@@ -1,10 +1,13 @@
<testsuites>
<testsuite failures="0"
+ skipped="1"
errors="0"
tests="5"
name="data_tap_skip">
<testcase name="1"></testcase>
- <testcase name="2"></testcase>
+ <testcase name="2">
+ <skipped />
+ </testcase>
<testcase name="3"></testcase>
<testcase name="4"></testcase>
<testcase name="5"></testcase>
diff --git a/t/data/tap/junit/skip_nomsg b/t/data/tap/junit/skip_nomsg
index d5016e3..df6cb2a 100644
--- a/t/data/tap/junit/skip_nomsg
+++ b/t/data/tap/junit/skip_nomsg
@@ -1,9 +1,12 @@
<testsuites>
<testsuite failures="0"
+ skipped="1"
errors="0"
tests="1"
name="data_tap_skip_nomsg">
- <testcase name="1"></testcase>
+ <testcase name="1">
+ <skipped />
+ </testcase>
<system-out><![CDATA[1..1
ok 1 # Skip
]]></system-out>
diff --git a/t/data/tests/junit/skip b/t/data/tests/junit/skip
index 434c0c0..aec74f5 100644
--- a/t/data/tests/junit/skip
+++ b/t/data/tests/junit/skip
@@ -1,10 +1,13 @@
<testsuites>
<testsuite failures="0"
+ skipped="1"
errors="0"
tests="5"
name="data_tests_skip">
<testcase name="1"></testcase>
- <testcase name="2"></testcase>
+ <testcase name="2">
+ <skipped />
+ </testcase>
<testcase name="3"></testcase>
<testcase name="4"></testcase>
<testcase name="5"></testcase>
diff --git a/t/data/tests/junit/skip_nomsg b/t/data/tests/junit/skip_nomsg
index 26ac6ed..3cc6233 100644
--- a/t/data/tests/junit/skip_nomsg
+++ b/t/data/tests/junit/skip_nomsg
@@ -1,9 +1,12 @@
<testsuites>
<testsuite failures="0"
+ skipped="1"
errors="0"
tests="1"
name="data_tests_skip_nomsg">
- <testcase name="1"></testcase>
+ <testcase name="1">
+ <skipped />
+ </testcase>
<system-out><![CDATA[1..1
ok 1 # Skip
]]></system-out>
--
2.20.1