Skip to content

Commit

Permalink
Issue #2462: fix test script YAML.t
Browse files Browse the repository at this point in the history
The changes for issue #2464 broke the script. The reason was that
the previous version used Kernel::System::YAML for testing
and the changes script, using YAML::XS, did not fully replicate the
funktionality in Kernel::System::YAML.
Furthermore there was some confusion regarding UTF8 de- and en-coding.
  • Loading branch information
bschmalhofer committed Aug 15, 2023
1 parent 8d10759 commit 9e78ca1
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions scripts/test/YAML/YAML.t
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,29 @@ my @Tests = (

for my $Test (@Tests) {

my $YAMLString = $Test->{YAMLString} || YAML::XS::Dump( Data => $Test->{Data} );
my $YAMLData = YAML::XS::Load( Data => $YAMLString );
# This block is basically replicating Kernel::System::YAML::Load.
# But the tests are still useful as they exemplify what Kernel::System::YAML does.

# When the test script contains the YAML string then the high
# code points are already in the string as 'use utf8' is in effecdt
my $YAMLString = $Test->{YAMLString};

# Alternatively we are testing the roundtrip. The result from Dump()
# is a string of octetts that encode in UTF8 the really wanted string.
if ( !$YAMLString ) {
$YAMLString = YAML::XS::Dump( Data => $Test->{Data} );
utf8::decode($YAMLString);
}

my $YAMLData = try {

# Load expects octetts that encodes UTF-8
utf8::encode($YAMLString);
YAML::XS::Load($YAMLString);
}
catch {
'YAML::XS::Load() threw an exception';
};

if ( $Test->{SuccessDecode} ) {
is(
Expand All @@ -232,8 +253,9 @@ for my $Test (@Tests) {
);
}
else {
ok(
!$YAMLData,
is(
$YAMLData,
'YAML::XS::Load() threw an exception',
"$Test->{Name} - failure reported",
);
}
Expand Down

0 comments on commit 9e78ca1

Please sign in to comment.