Skip to content

Commit 6d7cccf

Browse files
committed
In ext/POSIX/t/sysconf.t, make the tests more strict.
$! should always be 0 after each call, so test this whether the result is defined or undefined. Match a defined result against a regex to ensure that it is an integer, and give better diagnostics if it is not.
1 parent 7187b54 commit 6d7cccf

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

ext/POSIX/t/sysconf.t

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ BEGIN {
99
use strict;
1010
use File::Spec;
1111
use POSIX;
12-
use Scalar::Util qw(looks_like_number);
1312

1413
sub check(@) {
1514
grep { eval "&$_;1" or $@!~/vendor has not defined POSIX macro/ } @_
@@ -57,21 +56,19 @@ sub _check_and_report {
5756
my ($sub, $constant, $description) = @_;
5857
$! = 0;
5958
my $return_val = eval {$sub->(eval "$constant()")};
60-
my $success = defined($return_val) || $! == 0;
59+
my $errno = $!; # Grab this before anything else changes it.
6160
is($@, '', $description);
6261
SKIP: {
6362
skip "terminal constants set errno on QNX", 1
6463
if $^O eq 'nto' and $description =~ $TTY;
65-
ok( $success, "\tchecking that the returned value is defined ("
66-
. (defined($return_val) ? "yes, it's $return_val)" : "it isn't)"
67-
. " or that errno is clear ("
68-
. (!($!+0) ? "it is)" : "it isn't, it's $!)"))
69-
);
64+
cmp_ok($errno, '==', 0, 'errno should be clear in all cases')
65+
or diag("\$!: $errno");
7066
}
7167
SKIP: {
7268
skip "constant not implemented on $^O or no limit in effect", 1
7369
if !defined($return_val);
74-
ok( looks_like_number($return_val), "\tchecking that the returned value looks like a number" );
70+
like($return_val, qr/\A(?:-?[1-9][0-9]*|0 but true)\z/,
71+
'the returned value should be a signed integer');
7572
}
7673
}
7774

0 commit comments

Comments
 (0)