Subject: | Does not work with non-ascii ouput |
i.e. when tests have non-ascii messages like:
ok 1, "привет"; # Russian message
attaching patch (for version 0.11).
Subject: | unicode.patch |
diff --git a/lib/TAP/Formatter/JUnit.pm b/lib/TAP/Formatter/JUnit.pm
index 30436a2..be611e3 100644
--- a/lib/TAP/Formatter/JUnit.pm
+++ b/lib/TAP/Formatter/JUnit.pm
@@ -7,6 +7,7 @@ extends qw(
);
use XML::Generator;
+use Encode;
use TAP::Formatter::JUnit::Session;
our $VERSION = '0.11';
@@ -62,7 +63,7 @@ sub summary {
return if $self->silent();
my @suites = @{$self->testsuites};
- print { $self->stdout } $self->xml->testsuites( @suites );
+ print { $self->stdout } Encode::encode("UTF-8", $self->xml->testsuites( @suites ));
}
1;
diff --git a/lib/TAP/Formatter/JUnit/Session.pm b/lib/TAP/Formatter/JUnit/Session.pm
index fb7dca3..6ad90ee 100644
--- a/lib/TAP/Formatter/JUnit/Session.pm
+++ b/lib/TAP/Formatter/JUnit/Session.pm
@@ -6,6 +6,7 @@ extends qw(
TAP::Formatter::Console::Session
);
+use Encode;
use Storable qw(dclone);
use File::Path qw(mkpath);
use IO::File;
@@ -72,6 +73,7 @@ sub result {
'time' => $self->get_time,
'result' => $result,
);
+ $wrapped->{result}{$_} = Encode::decode("UTF-8", $wrapped->{result}{$_}) for (qw/description raw/);
$self->_queue_add($wrapped);
}
}
@@ -361,8 +363,6 @@ sub _squeaky_clean {
my $string = shift;
# control characters (except CR and LF)
$string =~ s/([\x00-\x09\x0b\x0c\x0e-\x1f])/"^".chr(ord($1)+64)/ge;
- # high-byte characters
- $string =~ s/([\x7f-\xff])/'[\\x'.sprintf('%02x',ord($1)).']'/ge;
return $string;
}