Files
webmin/t/test-lib.pl
2026-08-10 21:37:11 +02:00

29 lines
547 B
Perl

# 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;