Shlomi Fish avatar Shlomi Fish committed 027834c

t/02parse.t - check the localized error message.

This is a proper fix for the localized error message.

Comments (0)

Files changed (2)

 Revision history for Perl extension XML::LibXML
 
-    - Add a POSIX::setlocale call to t/02parse.t to test for the right
-    error message.
+    - Change t/02parse.t to test for the localized error message:
         - https://rt.cpan.org/Public/Bug/Display.html?id=69248
 
 
 use XML::LibXML::Common qw(:libxml);
 use XML::LibXML::SAX;
 use XML::LibXML::SAX::Builder;
-use POSIX qw(setlocale LC_ALL LC_CTYPE);
 
 use constant XML_DECL => "<?xml version=\"1.0\"?>\n";
 
-# This is to fix https://rt.cpan.org/Public/Bug/Display.html?id=69248
-# Testing for localised error messages.
-POSIX::setlocale (LC_ALL(), 'C');
+use Errno qw(ENOENT);
 
 ##
 # test values
 eval {my $fail = $parser->parse_file($badfile1);};
 like($@, qr/^$badfile1:3: parser error : Extra content at the end of the document/, "error parsing $badfile1");
 
+{
+    # This is to fix https://rt.cpan.org/Public/Bug/Display.html?id=69248
+    # Testing for localised error messages.
+    $! = ENOENT;
+    my $err_string = "$!";
+    $! = 0;
 
-eval { $parser->parse_file($badfile2); };
-like($@, qr/^Could not create file parser context for file "$badfile2": No such file or directory at/, "error parsing non-existant $badfile2");
+    my $re = qr/\ACould not create file parser context for file "\Q$badfile2\E": \Q$err_string\E/;
+
+    eval { $parser->parse_file($badfile2); };
+    like($@, $re, "error parsing non-existant $badfile2");
+}
 
 {
     my $str = "<a>    <b/> </a>";
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.