1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# -*- cperl -*-
use ExtUtils::testlib;
use Test::More ;
use Test::Memory::Cycle;
use Config::Model;
use File::Path;
use File::Copy;
use Data::Dumper;
use IO::File;
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
use warnings;
use strict;
my ($model, $trace) = init_test();
# pseudo root where config files are written by config-model
my $wr_root = setup_test_dir( stringify => 0 );
my $subdir = $wr_root->child('plain');
$subdir->mkpath;
$model->create_config_class(
name => "WithPlainFile",
element => [
[qw/source new/] => {qw/type leaf value_type uniline/},
clean => { qw/type list/, cargo => {qw/type leaf value_type uniline/} },
],
rw_config => {
backend => 'plain_file',
config_dir => $subdir->relative($wr_root),
},
);
$subdir->child('source')->spew("2.0\n");
ok( 1, "wrote source file" );
$subdir->child('clean')->spew("foo\n*/*/bar\n");
ok( 1, "wrote clean file" );
my $inst = $model->instance(
root_class_name => 'WithPlainFile',
root_dir => $wr_root,
);
ok( $inst, "Created instance" );
my $root = $inst->config_root;
is( $root->grab_value("source"), "2.0", "got correct source value" );
is( $root->grab_value("clean:0"), "foo", "got clean 0" );
is( $root->grab_value("clean:1"), "*/*/bar", "got clean 1" );
my $load = qq[source="3.0 (quilt)"\nnew="new stuff" clean:2="baz*"\n];
$root->load($load);
$inst->write_back;
ok( 1, "plain file write back done" );
my $new_file = $wr_root->child('plain/new');
ok($new_file->is_file, "check that config file $new_file was written" );
is($root->grab('source')->backend_support_annotation(), 0, "check backend annotation support");
# create another instance to read the file that was just written
my $i2_plain = $model->instance(
instance_name => 'inst2',
root_class_name => 'WithPlainFile',
root_dir => $wr_root,
);
ok( $i2_plain, "Created 2nd instance" );
my $i2_root = $i2_plain->config_root;
my $p2_dump = $i2_root->dump_tree;
is( $p2_dump, $root->dump_tree, "compare original data with 2nd instance data" );
memory_cycle_ok($model, "memory cycles");
done_testing;
|