| 1 |
#!/usr/bin/perl |
| 2 |
# This script is a regression test for: |
| 3 |
# |
| 4 |
# https://rt.cpan.org/Ticket/Display.html?id=45997 |
| 5 |
# |
| 6 |
# Failure to read the ini file contents from a filehandle made out of a scalar |
| 7 |
|
| 8 |
use Test::More tests => 1; |
| 9 |
|
| 10 |
use strict; |
| 11 |
use warnings; |
| 12 |
|
| 13 |
use IO::File; |
| 14 |
|
| 15 |
use lib "./t/lib"; |
| 16 |
use Config::IniFiles::Slurp qw( slurp ); |
| 17 |
|
| 18 |
use Config::IniFiles; |
| 19 |
use File::Spec; |
| 20 |
|
| 21 |
use File::Temp qw(tempdir); |
| 22 |
|
| 23 |
my $dirname = tempdir( CLEANUP => 1 ); |
| 24 |
my $filename = File::Spec->catfile( $dirname, 'toto.ini' ); |
| 25 |
|
| 26 |
{ |
| 27 |
{ |
| 28 |
open my $fh, '>', $filename; |
| 29 |
print {$fh} <<'EOF'; |
| 30 |
[toto] |
| 31 |
tata=verylongstringtoreplacewithashorterone |
| 32 |
|
| 33 |
[section3] |
| 34 |
arg3=valf |
| 35 |
EOF |
| 36 |
close($fh); |
| 37 |
} |
| 38 |
{ |
| 39 |
my %ini; |
| 40 |
|
| 41 |
my $fh = IO::File->new( $filename, 'r+' ); |
| 42 |
die "Couldn't open file ${filename}: $!" if not defined $fh; |
| 43 |
tie %ini, 'Config::IniFiles', ( -file => $fh, -allowempty => 1 ); |
| 44 |
|
| 45 |
tied(%ini)->delval( "toto", "tata" ); |
| 46 |
tied(%ini)->RewriteConfig; |
| 47 |
|
| 48 |
$ini{toto}{tata} = 'short'; |
| 49 |
tied(%ini)->RewriteConfig; |
| 50 |
|
| 51 |
$fh->close; |
| 52 |
untie %ini; |
| 53 |
} |
| 54 |
|
| 55 |
# TEST |
| 56 |
is( |
| 57 |
scalar( slurp($filename) ), |
| 58 |
<<'EOF', |
| 59 |
[toto] |
| 60 |
tata=short |
| 61 |
|
| 62 |
[section3] |
| 63 |
arg3=valf |
| 64 |
EOF |
| 65 |
"Test that the value was properly shortened.", |
| 66 |
); |
| 67 |
} |