diff --git a/Makefile.am b/Makefile.am index 0426025..90d3597 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,6 +77,7 @@ handwritten_tests = \ t/parse_assignments.pl \ t/skip.pl \ t/ssl-validate.pl \ + t/variable_defaults.pl \ t/write_recap.pl generated_tests = \ t/version.pl diff --git a/ddclient.in b/ddclient.in index 3cd9a0c..a415b2a 100755 --- a/ddclient.in +++ b/ddclient.in @@ -556,7 +556,7 @@ sub setv { 'minimum' => shift, }; } -my %variables = ( +our %variables = ( 'global-defaults' => { 'daemon' => setv(T_DELAY, 0, 0, $daemon_default, interval('60s')), 'foreground' => setv(T_BOOL, 0, 0, 0, undef), @@ -706,7 +706,7 @@ my %variables = ( 'wildcard' => setv(T_BOOL, 0, 1, 0, undef), }, ); -my %protocols = ( +our %protocols = ( '1984' => { 'force_update' => undef, 'update' => \&nic_1984_update, diff --git a/t/variable_defaults.pl b/t/variable_defaults.pl new file mode 100644 index 0000000..09dc92c --- /dev/null +++ b/t/variable_defaults.pl @@ -0,0 +1,32 @@ +use Test::More; +SKIP: { eval { require Test::Warnings; } or skip($@, 1); } +eval { require 'ddclient'; } or BAIL_OUT($@); + +my %variable_collections = ( + map({ ($_ => $ddclient::variables{$_}) } grep($_ ne 'merged', keys(%ddclient::variables))), + map({ ("protocol=$_" => $ddclient::protocols{$_}{variables}); } keys(%ddclient::protocols)), +); +my %seen; +my @test_cases = ( + map({ + my $vcn = $_; + my $vc = $variable_collections{$_}; + map({ + my $def = $vc->{$_}; + my $seen = exists($seen{$def}); + $seen{$def} = undef; + ({desc => "$vcn $_", def => $vc->{$_}}) x !$seen; + } sort(keys(%$vc))); + } sort(keys(%variable_collections))), +); +for my $tc (@test_cases) { + if ($tc->{def}{required}) { + is($tc->{def}{default}, undef, "'$tc->{desc}' (required) has no default"); + } else { + my $norm; + my $valid = eval { $norm = ddclient::check_value($tc->{def}{default}, $tc->{def}); 1; }; + ok($valid, "'$tc->{desc}' (optional) has a valid default"); + is($norm, $tc->{def}{default}, "'$tc->{desc}' default normalizes to itself") if $valid; + } +} +done_testing();