From: Vincent Pit Date: Tue, 10 Mar 2009 15:48:14 +0000 (+0100) Subject: More robust tests X-Git-Tag: v0.11~10 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=46f546e3a234889baf70c76b9fcb4c3b9c9d14d7;p=perl%2Fmodules%2FLinux-SysInfo.git More robust tests --- diff --git a/t/10-standard.t b/t/10-standard.t index 1642ed4..2442dff 100644 --- a/t/10-standard.t +++ b/t/10-standard.t @@ -7,9 +7,21 @@ use Test::More tests => 12 * 5; use Linux::SysInfo qw/sysinfo/; -for (1 .. 5) { - my $si = sysinfo; - ok(defined $si); +SKIP: { + for my $run (0 .. 4) { + my $si = sysinfo; + skip 'system error (sysinfo returned undef)' => (5 - $run) * 12 + unless defined $si; + is ref($si), 'HASH', "sysinfo returns a hash reference at run $run"; - ok(exists $si->{$_}) for qw/uptime load1 load5 load15 totalram freeram sharedram bufferram totalswap freeswap procs/; + for (qw/uptime load1 load5 load15 procs + totalram freeram sharedram bufferram totalswap freeswap/) { + if (defined $si->{$_}) { + like $si->{$_}, qr/^\d+(?:\.\d+)?$/, + "key $_ looks like a number at run $run"; + } else { + fail "key $_ isn't defined at run $run"; + } + } + } } diff --git a/t/20-extended.t b/t/20-extended.t index c8a270e..6cbb353 100644 --- a/t/20-extended.t +++ b/t/20-extended.t @@ -12,10 +12,21 @@ unless (LS_HAS_EXTENDED) { } else { plan tests => 4 * 5; - for (1 .. 5) { - my $si = sysinfo; - ok(defined $si); + SKIP: { + for my $run (0 .. 4) { + my $si = sysinfo; + skip 'system error (sysinfo returned undef)' => (5 - $run) * 4 + unless defined $si; + is ref($si), 'HASH', "sysinfo returns a hash reference at run $run"; - ok(exists $si->{$_}) for qw/totalhigh freehigh mem_unit/; + for (qw/totalhigh freehigh mem_unit/) { + if (defined $si->{$_}) { + like $si->{$_}, qr/^\d+(?:\.\d+)?$/, + "key $_ looks like a number at run $run"; + } else { + fail "key $_ isn't defined at run $run"; + } + } + } } }