#!/usr/bin/perl use Libconf qw(:functions); use Data::Dumper; # test 1, minimal requirement : regenerate correctly display(1); my $struct = new Libconf('hosts', 'hosts', ''); #print Data::Dumper->Dump([$struct],['struct']) . "\n"; $struct->writeConf("hosts_output_1"); test(1); # test 2, test for stable loop display(2); $struct = new Libconf('hosts', 'hosts', ''); $struct->writeConf("hosts_output_2"); $struct = new Libconf("hosts_output_2", 'hosts', ''); $struct->writeConf("hosts_output_2"); test(2); display(3); $struct = new Libconf('hosts', 'hosts', ''); $struct->editAtom(-1, { 'key' => '127.0.0.1', 'values' => { 'canonical_hostname' => 'my_localhost', 'aliases' => [qw(test1 test2 test3)], }, }); $struct->writeConf("hosts_output_3"); test(3); display(4); $struct = new Libconf('hosts', 'hosts', ''); $struct->appendAtom({ key => '1.2.3.4', values => { 'canonical_hostname' => 'some_localhost', 'aliases' => [qw(test1 test3)], }, type => 'KEY_VALUES', }); $struct->writeConf("hosts_output_4"); test(4); display(5); $struct = new Libconf('hosts', 'hosts', ''); $struct->insertAtom(1, { key => '1.2.3.4', values => { 'canonical_hostname' => 'some_other_localhost', 'aliases' => [qw(test2 test3)], }, type => 'KEY_VALUES', }); $struct->writeConf("hosts_output_5"); test(5); display(-1); sub display { local $| = 1; $_[0] == -1 ? print " done\n" : print "\r * testing host " . '.' x $_[0]; local $| = 0; } sub test { my ($num, $exec) = @_; $exec ||= "diff -q hosts_output_$num hosts_verify_$num 2>/dev/null 1>/dev/null"; if (system($exec) != 0) { print "\r * testing host : TEST N°$num FAILED\n"; exit($!); } }