cpan/version/t/07locale.t: Actually test what is claimed
authorKarl Williamson <public@khwilliamson.com>
Wed, 17 Jul 2013 04:05:57 +0000 (22:05 -0600)
committerKarl Williamson <public@khwilliamson.com>
Fri, 19 Jul 2013 16:35:14 +0000 (10:35 -0600)
Commit b127e37e51c21b0a36755dcd19811be931a03d83 wrongly changed two
tests, and failed to change a third.  One of the two ended up doing:
        ok ("$ver eq '1,23'", ...);
That's always going to succeed as ok() doesn't do an eval; it just looks
at the result of the expression, which in this case was a non-empty
string.

The second test was changed from an 'eq' to '=='.  It had this diff:

 -       is ($v, "1.23", "Locale doesn't apply to version objects");
 +       ok ($v == "1.23", "Locale doesn't apply to version objects");

(The code for is() does an 'eq'.)  The is() call is made from within the
scope of a "use locale" in which the decimal point character is a comma,
but version objects are supposed to always use a dot, regardless of the
locale.  The == will numify the operands, potentially throwing away the
locale's decimal point character.  Therefore the test should use an
'eq'.

Before these changes, the two tests also didn't do what they purported
(and hence the motivation for the changes).  The tests previously used
'is()', which is defined in a different file which is outside the locale
scope, so that the scalars ($v and $ver) there should have a dot even
if they have a comma within locale scope, and hence doing an is() would
not catch the bug being tested against.  Hence the third test
(overlooked in the earlier commit) remained wrong until now.

cpan/version/t/07locale.t

index 784bc11..fe8e0e5 100644 (file)
@@ -27,7 +27,10 @@ SKIP: {
        my $ver = 1.23;  # has to be floating point number
        my $loc;
        my $orig_loc = setlocale(LC_NUMERIC);
-       is ($ver, '1.23', 'Not using locale yet');
+       ok ($ver eq "1.23", 'Not using locale yet');  # Don't use is(),
+                                                      # because have to
+                                                      # evaluate in current
+                                                      # scope
        while (<DATA>) {
            chomp;
            $loc = setlocale( LC_ALL, $_);
@@ -39,11 +42,11 @@ SKIP: {
        diag ("Testing locale handling with $loc") unless $ENV{PERL_CORE};
 
         setlocale(LC_NUMERIC, $loc);
-       ok ("$ver eq '1,23'", "Using locale: $loc");
+       ok ($ver eq "1,23", "Using locale: $loc");
        $v = version->new($ver);
        unlike($warning, qr/Version string '1,23' contains invalid data/,
            "Process locale-dependent floating point");
-       ok ($v == "1.23", "Locale doesn't apply to version objects");
+       ok ($v eq "1.23", "Locale doesn't apply to version objects");
        ok ($v == $ver, "Comparison to locale floating point");
 
         {