| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Config::IniFiles; |
| 4 |
use Test::More tests => 8; |
| 5 |
use File::Temp 'tempfile'; |
| 6 |
|
| 7 |
my $config_nofile = Config::IniFiles->new( -allowempty => 1 ); |
| 8 |
$config_nofile->newval( 'section', 'param', 1 ); |
| 9 |
|
| 10 |
my ( $fh, $filename ) = tempfile; |
| 11 |
|
| 12 |
## Import config, set filename, read config, then read again |
| 13 |
my $config = |
| 14 |
Config::IniFiles->new( -import => $config_nofile, -allowempty => 1 ); |
| 15 |
|
| 16 |
# TEST |
| 17 |
ok( $config->val( 'section', 'param' ), 'Configuration is imported' ); |
| 18 |
|
| 19 |
$config->SetFileName($filename); |
| 20 |
$config->ReadConfig; |
| 21 |
|
| 22 |
# TEST |
| 23 |
ok( $config->val( 'section', 'param' ), 'Configuration is still imported' ); |
| 24 |
|
| 25 |
$config->ReadConfig; |
| 26 |
|
| 27 |
# TEST |
| 28 |
ok( $config->val( 'section', 'param' ), 'Configuration is still imported' ); |
| 29 |
|
| 30 |
## Import config that has already been imported |
| 31 |
$config = Config::IniFiles->new( |
| 32 |
-import => $config_nofile, |
| 33 |
-allowempty => 1, |
| 34 |
-file => $filename |
| 35 |
); |
| 36 |
|
| 37 |
# TEST |
| 38 |
ok( $config->val( 'section', 'param' ), 'Configuration is imported again' ); |
| 39 |
|
| 40 |
$config_nofile = Config::IniFiles->new; |
| 41 |
$config_nofile->newval( 'section', 'param', 1 ); |
| 42 |
|
| 43 |
## Import config and set filename in constructor, then read again |
| 44 |
$config = Config::IniFiles->new( |
| 45 |
-import => $config_nofile, |
| 46 |
-allowempty => 1, |
| 47 |
-file => $filename |
| 48 |
); |
| 49 |
|
| 50 |
# TEST |
| 51 |
ok( $config->val( 'section', 'param' ), 'Configuration is imported' ); |
| 52 |
|
| 53 |
$config->ReadConfig; |
| 54 |
|
| 55 |
# TEST |
| 56 |
ok( $config->val( 'section', 'param' ), 'Configuration is still imported' ); |
| 57 |
|
| 58 |
## Import config that is written to file, but with parameters not written to file, then read again |
| 59 |
|
| 60 |
my ( $fh2, $filename2 ) = tempfile; |
| 61 |
my $config_file = |
| 62 |
Config::IniFiles->new( -allowempty => 1, -file => $filename2 ); |
| 63 |
$config_file->newval( 'section', 'param2', 1 ); |
| 64 |
$config_file->RewriteConfig; |
| 65 |
$config_file->newval( 'section', 'param', 1 ); |
| 66 |
|
| 67 |
$config = Config::IniFiles->new( |
| 68 |
-import => $config_file, |
| 69 |
-allowempty => 1, |
| 70 |
-file => $filename |
| 71 |
); |
| 72 |
|
| 73 |
# TEST |
| 74 |
ok( $config->val( 'section', 'param' ), 'Configuration is imported' ); |
| 75 |
|
| 76 |
$config->ReadConfig; |
| 77 |
|
| 78 |
# TEST |
| 79 |
ok( $config->val( 'section', 'param' ), 'Configuration is still imported' ); |