diff --git a/logrotate/t/run-tests.t b/logrotate/t/run-tests.t index b0ac610de..7e86a599c 100644 --- a/logrotate/t/run-tests.t +++ b/logrotate/t/run-tests.t @@ -7,9 +7,13 @@ use File::Basename qw(dirname); use File::Path qw(make_path); use File::Temp qw(tempdir); -# Build an isolated openSUSE-style /etc and /usr/etc configuration layout. -my $module_dir = abs_path(dirname(abs_path($0))."/.."); +# Locate the repository and load its common test helpers. +my $test_dir = dirname(abs_path($0)); +my $module_dir = abs_path("$test_dir/.."); my $root_dir = abs_path("$module_dir/.."); +require "$root_dir/t/test-lib.pl"; + +# Build an isolated openSUSE-style /etc and /usr/etc configuration layout. my $config_dir = tempdir(CLEANUP => 1); my $var_dir = tempdir(CLEANUP => 1); my $fixture_dir = tempdir(CLEANUP => 1); @@ -22,28 +26,6 @@ make_path("$config_dir/logrotate", $local_add_dir, "$local_add_dir/nested", "$vendor_add_dir/deep", "$vendor_add_dir/nested", dirname($wrapper)); -# write_text(file, contents) -# Writes a text fixture and fails the test immediately on an I/O error -sub write_text -{ -my ($file, $text) = @_; -open(my $fh, ">", $file) or die "open $file: $!"; -print $fh $text; -close($fh) or die "close $file: $!"; -} - -# read_text(file) -# Returns the complete contents of a text fixture -sub read_text -{ -my ($file) = @_; -open(my $fh, "<", $file) or die "open $file: $!"; -local $/; -my $text = <$fh>; -close($fh) or die "close $file: $!"; -return $text; -} - # Populate both trees with vendor-only, local-only, nested, and overridden # files so the fixture exercises the wrapper's key overlay rules. my $vendor_main_text = diff --git a/t/test-lib.pl b/t/test-lib.pl new file mode 100644 index 000000000..d3611e8ee --- /dev/null +++ b/t/test-lib.pl @@ -0,0 +1,28 @@ +# Common helpers for Webmin tests. + +use strict; +use warnings; + +# write_text(file, contents) +# Writes a text fixture and fails the test immediately on an I/O error +sub write_text +{ +my ($file, $text) = @_; +open(my $fh, ">", $file) or die "open $file: $!"; +print $fh $text; +close($fh) or die "close $file: $!"; +} + +# read_text(file) +# Returns the complete contents of a text fixture +sub read_text +{ +my ($file) = @_; +open(my $fh, "<", $file) or die "open $file: $!"; +local $/; +my $text = <$fh>; +close($fh) or die "close $file: $!"; +return $text; +} + +1;