diff options
author | Russ Allbery <eagle@eyrie.org> | 2018-05-27 20:59:59 -0700 |
---|---|---|
committer | Russ Allbery <eagle@eyrie.org> | 2018-05-27 20:59:59 -0700 |
commit | bdcb3741db27d6b773ce7cdf05aab063a70ea100 (patch) | |
tree | 11e11bb646e0b58db6e23b59e3c856ea59ef3545 /tests/tap/perl/Test/RRA.pm | |
parent | 62a9101895a2d596bf91231f119d338d2025ff08 (diff) |
Update to rra-c-util 7.2 and C TAP Harness 4.3
Update to rra-c-util 7.2:
* Improve configure output for krb5-config testing.
* Define UINT32_MAX for systems that don't have it.
* Add SPDX-License-Identifier headers to all substantial source files.
* Fix new warnings from GCC 7 and Clang warnings.
* Require Test::Strict 0.25 or later to run those tests.
* Fix off-by-one error in return-value checks for snprintf.
* Use Autoconf to probe for supported warning flags.
* Fix running module-version-t -u with current versions of Perl.
* Use C_TAP_SOURCE and C_TAP_BUILD instead of SOURCE and BUILD.
Update to C TAP Harness 4.3:
* Add support for valgrind and libtool in test lists.
* Report test failures as left and right, not wanted and expected.
* Fix string comparisons with NULL pointers and the string "(null)".
* Add SPDX-License-Identifier headers to all substantial source files.
* Avoid zero-length realloc allocations in breallocarray.
* Fix new warnings from GCC 7 and Clang warnings.
* Use C_TAP_SOURCE and C_TAP_BUILD instead of SOURCE and BUILD.
Diffstat (limited to 'tests/tap/perl/Test/RRA.pm')
-rw-r--r-- | tests/tap/perl/Test/RRA.pm | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/tests/tap/perl/Test/RRA.pm b/tests/tap/perl/Test/RRA.pm index 8608e31..807508c 100644 --- a/tests/tap/perl/Test/RRA.pm +++ b/tests/tap/perl/Test/RRA.pm @@ -5,6 +5,8 @@ # by both C packages with Automake and by stand-alone Perl modules. See # Test::RRA::Automake for additional functions specifically for C Automake # distributions. +# +# SPDX-License-Identifier: MIT package Test::RRA; @@ -13,6 +15,7 @@ use strict; use warnings; use Exporter; +use File::Temp; use Test::More; # For Perl 5.006 compatibility. @@ -26,12 +29,56 @@ our (@EXPORT_OK, @ISA, $VERSION); # consistency is good). BEGIN { @ISA = qw(Exporter); - @EXPORT_OK = qw(skip_unless_author skip_unless_automated use_prereq); + @EXPORT_OK = qw( + is_file_contents skip_unless_author skip_unless_automated use_prereq + ); # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '5.10'; + $VERSION = '7.02'; +} + +# Compare a string to the contents of a file, similar to the standard is() +# function, but to show the line-based unified diff between them if they +# differ. +# +# $got - The output that we received +# $expected - The path to the file containing the expected output +# $message - The message to use when reporting the test results +# +# Returns: undef +# Throws: Exception on failure to read or write files or run diff +sub is_file_contents { + my ($got, $expected, $message) = @_; + + # If they're equal, this is simple. + open(my $fh, '<', $expected) or BAIL_OUT("Cannot open $expected: $!\n"); + my $data = do { local $/ = undef; <$fh> }; + close($fh) or BAIL_OUT("Cannot close $expected: $!\n"); + if ($got eq $data) { + is($got, $data, $message); + return; + } + + # Otherwise, we show a diff, but only if we have IPC::System::Simple. + eval { require IPC::System::Simple }; + if ($@) { + ok(0, $message); + return; + } + + # They're not equal. Write out what we got so that we can run diff. + my $tmp = File::Temp->new(); + my $tmpname = $tmp->filename; + print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n"); + my @command = ('diff', '-u', $expected, $tmpname); + my $diff = IPC::System::Simple::capturex([0 .. 1], @command); + diag($diff); + + # Remove the temporary file and report failure. + ok(0, $message); + return; } # Skip this test unless author tests are requested. Takes a short description @@ -225,10 +272,14 @@ SOFTWARE. Test::More(3), Test::RRA::Automake(3), Test::RRA::Config(3) This module is maintained in the rra-c-util package. The current version is -available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>. +available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>. The functions to control when tests are run use environment variables defined by the L<Lancaster Consensus|https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>. =cut + +# Local Variables: +# copyright-at-end-flag: t +# End: |