| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # This script attempts to reproduce: |
| 4 | # https://sourceforge.net/tracker/index.php?func=detail&aid=1230339&group_id=6926&atid=106926 |
| 5 | |
| 6 | use strict; |
| 7 | use warnings; |
| 8 | |
| 9 | use Test::More tests => 2; |
| 10 | use File::Spec; |
| 11 | |
| 12 | use Config::IniFiles; |
| 13 | |
| 14 | my $filename = File::Spec->catfile( File::Spec->curdir(), "t", |
| 15 | "store-and-retrieve-here-doc-terminator.ini" ); |
| 16 | |
| 17 | my @file_write_subs = ( |
| 18 | sub { |
| 19 | my ($cfg) = @_; |
| 20 | |
| 21 | $cfg->WriteConfig($filename); |
| 22 | |
| 23 | return; |
| 24 | }, |
| 25 | sub { |
| 26 | my ($cfg) = @_; |
| 27 | |
| 28 | open my $fh, '>', $filename |
| 29 | or die "Cannot open '$filename' for writing - $!"; |
| 30 | $cfg->OutputConfigToFileHandle($fh); |
| 31 | close($fh); |
| 32 | |
| 33 | return; |
| 34 | }, |
| 35 | ); |
| 36 | foreach my $write_sub (@file_write_subs) |
| 37 | { |
| 38 | # Prepare the offending file. |
| 39 | { |
| 40 | # Delete the stray file - we want to over-write it. |
| 41 | unlink($filename); |
| 42 | my $cfg = Config::IniFiles->new(); |
| 43 | |
| 44 | $cfg->newval( "MySection", "MyParam", "Hello\nEOT\n" ); |
| 45 | |
| 46 | $write_sub->($cfg); |
| 47 | } |
| 48 | |
| 49 | { |
| 50 | my $cfg = Config::IniFiles->new( -file => $filename ); |
| 51 | |
| 52 | # TEST*2 |
| 53 | is( |
| 54 | scalar( $cfg->val( "MySection", "MyParam" ) ), |
| 55 | "Hello\nEOT\n", |
| 56 | "Default here-doc terminator was stored and retrieved correctly", |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | # Delete it again to keep the working-copy clean. |
| 61 | unlink($filename); |
| 62 | } |