diff -Nru libconfig-model-tester-perl-2.053/Build.PL libconfig-model-tester-perl-3.003/Build.PL --- libconfig-model-tester-perl-2.053/Build.PL 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/Build.PL 2017-11-05 11:22:09.000000000 +0000 @@ -1,14 +1,14 @@ # # This file is part of Config-Model-Tester # -# This software is Copyright (c) 2013-2016 by Dominique Dumont. +# This software is Copyright (c) 2013-2017 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # -# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.043. +# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.010. use strict; use warnings; @@ -27,7 +27,7 @@ "Dominique Dumont" ], "dist_name" => "Config-Model-Tester", - "dist_version" => "2.053", + "dist_version" => "3.003", "license" => "lgpl", "module_name" => "Config::Model::Tester", "recursive_test_files" => 1, diff -Nru libconfig-model-tester-perl-2.053/Changes libconfig-model-tester-perl-3.003/Changes --- libconfig-model-tester-perl-2.053/Changes 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/Changes 2017-11-05 11:22:09.000000000 +0000 @@ -1,3 +1,84 @@ +3.003 2017-11-05 + + * fix test file contents to work with utf-8 + +3.002 2017-08-22 + + * add doc for $skip variable + * reset $model_to_test between test runs to fix consecutive tests + that use the same model with different setup + +3.001 2017-06-03 + + * Jump to version 3.001 because I messed up previous release. + * fix typos in doc + +2.062 2017-06-01 + + Bug fix + * Skip file mode test on Windows. + +2.061 2017-05-31 + + Improvements: + * add support for backend_arg (for Config::Model 2.104) + * add update_warnings parameter + +2.060 2017-03-05 + + Improvements: + * add file_mode parameter to test permission (mode) of + written files + +2.059 2017-02-12 + + Improvements: + * allow to reuse test data. Use data_from parameter to re-use test + data from another test case + * mention that file list is sorted when comparing files written by + first and second test instance + * add load2 parameter to load configuration data in + the second test instance. + + Bug fix + * recreate model object for each application test (i.e. a new model + object is created for each *-test-conf.pl file) + + Other: + * dist.ini: update © year + +2.058 2016-12-05 + + Minor bug fix: + * prevent undef warning seen in smoke and travis tests + +2.057 2016-09-03 + + Bug fix for Perl 5.24 and Debian perl 5.22.2-4: + * load test file even if @INC does not contain '.' + +2.056 2016-09-01 + + Improvements: + * added an option to check config tree content + before calling apply_fix + * Changed syntax of dump check parameters (old syntax is + still accepted) + +2.055 2016-05-26 + + Minor bug fixes: + * removed debug print + * avoid undef warning + +2.054 2016-04-17 + + Improvements: + * improved Tester documentation + * inform user when a global var is missing in test setup + * fix file check when setup param is used + * handle dir specification containing ~/ + 2.053 2016-03-28 New features: @@ -81,4 +162,4 @@ 2.041_01 2013-08-11 * Initial release. This module was moved from Config-Model - distribution. \ No newline at end of file + distribution. diff -Nru libconfig-model-tester-perl-2.053/debian/changelog libconfig-model-tester-perl-3.003/debian/changelog --- libconfig-model-tester-perl-2.053/debian/changelog 2016-03-29 08:34:22.000000000 +0000 +++ libconfig-model-tester-perl-3.003/debian/changelog 2021-06-06 04:33:26.000000000 +0000 @@ -1,3 +1,118 @@ +libconfig-model-tester-perl (3.003-1~16.04.sav0) xenial; urgency=medium + + * Backport to Xenial + + -- Rob Savoury Sat, 05 Jun 2021 21:33:26 -0700 + +libconfig-model-tester-perl (3.003-1) unstable; urgency=medium + + * New upstream version 3.003 + * fix test file contents to work with utf-8 + * control: declare compliance with policy 4.1.1 + + -- Dominique Dumont Sun, 05 Nov 2017 12:24:04 +0100 + +libconfig-model-tester-perl (3.002-1) unstable; urgency=medium + + * New upstream version 3.002 + * add doc for $skip variable + * reset $model_to_test between test runs to fix consecutive tests + that use the same model with different setup + * control: declare compliance with policy 4.1.0 + + -- Dominique Dumont Fri, 25 Aug 2017 12:01:53 +0200 + +libconfig-model-tester-perl (3.001-1) unstable; urgency=medium + + * New upstream version 3.001 + * Minor update (despite the change in major version number, which is due + to a mess up). + * control: updated std-version to 4.0.0 + + -- Dominique Dumont Wed, 21 Jun 2017 16:18:51 +0200 + +libconfig-model-tester-perl (2.062-1) experimental; urgency=medium + + * New upstream version 2.062 + * add support for backend_arg (for Config::Model 2.104) + * add update_warnings parameter + + -- Dominique Dumont Thu, 01 Jun 2017 21:06:41 +0200 + +libconfig-model-tester-perl (2.060-1) experimental; urgency=medium + + * New upstream version 2.060 + * add file_mode parameter to test permission (mode) of + written files + + -- Dominique Dumont Mon, 06 Mar 2017 10:31:19 +0100 + +libconfig-model-tester-perl (2.059-1) experimental; urgency=medium + + * New upstream version 2.059 + * allow one to reuse test data. Use data_from parameter to re-use test + data from another test case + * mention that file list is sorted when comparing files written by + first and second test instance + * add load2 parameter to load configuration data in + the second test instance. + * copyright: updated years + + -- Dominique Dumont Sun, 26 Feb 2017 19:16:31 +0100 + +libconfig-model-tester-perl (2.058-1) unstable; urgency=medium + + * Team upload. + + [ Nick Morrott ] + * Imported Upstream version 2.058 + * prevent undef warning seen in smoke and travis tests + + [ gregor herrmann ] + * Lower debhelper build dependency version. + + -- Nick Morrott Wed, 25 Jan 2017 01:14:49 +0000 + +libconfig-model-tester-perl (2.057-1) unstable; urgency=medium + + * New upstream version + * fix issue introduced by perl 5.22.2-4 and perl 5.24: load + test file even if @INC does not contain '.' + + -- Dominique Dumont Sun, 04 Sep 2016 08:45:38 +0200 + +libconfig-model-tester-perl (2.056-1) unstable; urgency=medium + + [ gregor herrmann ] + * debian/upstream/metadata: use HTTPS for GitHub URLs. + + [ Dominique Dumont ] + * New upstream version 2.056 + * added an option to check config tree content + before calling apply_fix + * Changed syntax of dump check parameters + (old syntax is still accepted) + + -- Dominique Dumont Fri, 02 Sep 2016 15:54:53 +0200 + +libconfig-model-tester-perl (2.055-1) unstable; urgency=medium + + [ gregor herrmann ] + * debian/copyright: change Copyright-Format 1.0 URL to HTTPS. + * debian/upstream/metadata: change GitHub/CPAN URL(s) to HTTPS. + + [ Dominique Dumont ] + * Imported Upstream version 2.055 + + -- Dominique Dumont Fri, 27 May 2016 13:31:46 +0200 + +libconfig-model-tester-perl (2.054-1) unstable; urgency=medium + + * Imported Upstream version 2.054 + * control: updated std-version to 3.9.8 + + -- Dominique Dumont Mon, 18 Apr 2016 13:21:11 +0200 + libconfig-model-tester-perl (2.053-1) unstable; urgency=medium [ Salvatore Bonaccorso ] diff -Nru libconfig-model-tester-perl-2.053/debian/control libconfig-model-tester-perl-3.003/debian/control --- libconfig-model-tester-perl-2.053/debian/control 2016-03-29 08:34:22.000000000 +0000 +++ libconfig-model-tester-perl-3.003/debian/control 2017-11-05 11:24:04.000000000 +0000 @@ -4,7 +4,7 @@ Section: perl Testsuite: autopkgtest-pkg-perl Priority: optional -Build-Depends: debhelper (>= 9.20120312), +Build-Depends: debhelper (>= 9), libmodule-build-perl Build-Depends-Indep: libfile-copy-recursive-perl, liblog-log4perl-perl, @@ -13,8 +13,8 @@ libtest-exception-perl, libtest-file-contents-perl, libtest-memory-cycle-perl, - libtest-warn-perl, -Standards-Version: 3.9.7 + libtest-warn-perl +Standards-Version: 4.1.1 Vcs-Browser: https://anonscm.debian.org/cgit/pkg-perl/packages/libconfig-model-tester-perl.git Vcs-Git: https://anonscm.debian.org/git/pkg-perl/packages/libconfig-model-tester-perl.git Homepage: https://metacpan.org/release/Config-Model-Tester diff -Nru libconfig-model-tester-perl-2.053/debian/copyright libconfig-model-tester-perl-3.003/debian/copyright --- libconfig-model-tester-perl-2.053/debian/copyright 2016-03-29 08:34:22.000000000 +0000 +++ libconfig-model-tester-perl-3.003/debian/copyright 2017-11-05 11:24:04.000000000 +0000 @@ -1,14 +1,14 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Config-Model-Tester Upstream-Contact: Dominique Dumont Source: https://metacpan.org/release/Config-Model-Tester Files: * -Copyright: 2013-2016 Dominique Dumont +Copyright: 2013-2017 Dominique Dumont License: LGPL-2.1+ Files: debian/* -Copyright: 2014-2016, Dominique Dumont +Copyright: 2014-2017, Dominique Dumont License: LGPL-2.1+ License: LGPL-2.1+ diff -Nru libconfig-model-tester-perl-2.053/debian/upstream/metadata libconfig-model-tester-perl-3.003/debian/upstream/metadata --- libconfig-model-tester-perl-2.053/debian/upstream/metadata 2016-03-29 08:34:22.000000000 +0000 +++ libconfig-model-tester-perl-3.003/debian/upstream/metadata 2017-11-05 11:24:04.000000000 +0000 @@ -1,8 +1,8 @@ --- Archive: CPAN -Bug-Database: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-Model-Tester +Bug-Database: https://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-Model-Tester Bug-Submit: bug-project@rt.cpan.org Contact: Dominique Dumont Name: Config-Model-Tester -Repository: git://github.com/dod38fr/config-model-tester.git -Repository-Browse: http://github.com/dod38fr/config-model-tester.git +Repository: https://github.com/dod38fr/config-model-tester.git +Repository-Browse: https://github.com/dod38fr/config-model-tester.git diff -Nru libconfig-model-tester-perl-2.053/lib/Config/Model/Tester.pm libconfig-model-tester-perl-3.003/lib/Config/Model/Tester.pm --- libconfig-model-tester-perl-2.053/lib/Config/Model/Tester.pm 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/lib/Config/Model/Tester.pm 2017-11-05 11:22:09.000000000 +0000 @@ -1,7 +1,7 @@ # # This file is part of Config-Model-Tester # -# This software is Copyright (c) 2013-2016 by Dominique Dumont. +# This software is Copyright (c) 2013-2017 by Dominique Dumont. # # This is free software, licensed under: # @@ -9,7 +9,7 @@ # package Config::Model::Tester; # ABSTRACT: Test framework for Config::Model -$Config::Model::Tester::VERSION = '2.053'; +$Config::Model::Tester::VERSION = '3.003'; use warnings; use strict; use locale; @@ -46,12 +46,14 @@ $File::Copy::Recursive::DirPerms = 0755; sub setup_test { - my ( $app_to_test, $t_name, $wr_root, $trace, $setup ) = @_; + my ( $app_to_test, $t_name, $wr_root, $trace, $t_data ) = @_; # cleanup before tests $wr_root->remove_tree(); $wr_root->mkpath( { mode => 0755 } ); + $conf_dir =~ s!~/!$home_for_test/! if $conf_dir and $home_for_test; + my $wr_dir = $wr_root->child('test-' . $t_name); my $wr_dir2 = $wr_root->child('test-' . $t_name.'-w'); my $conf_file ; @@ -59,11 +61,11 @@ if $conf_dir and $conf_file_name; my $ex_dir = path('t')->child('model_tests.d', "$app_to_test-examples"); - my $ex_data = $ex_dir->child($t_name); + my $ex_data = $ex_dir->child($t_data->{data_from} // $t_name); my @file_list; - if ($setup) { + if (my $setup = $t_data->{setup}) { foreach my $file (keys %$setup) { my $map = $setup->{$file} ; my $destination_str @@ -72,24 +74,31 @@ if (not defined $destination_str) { die "$app_to_test $t_name setup error: cannot find destination for test file $file" ; } + $destination_str =~ s!~/!$home_for_test/! if $home_for_test; my $destination = $wr_dir->child($destination_str) ; $destination->parent->mkpath( { mode => 0755 }) ; - my $data = $ex_data->child($file)->slurp() ; + my $data_file = $ex_data->child($file); + die "cannot find $data_file" unless $data_file->exists; + my $data = $data_file->slurp() ; $destination->spew( $data ); @file_list = list_test_files ($wr_dir); } } elsif ( $ex_data->is_dir ) { # copy whole dir - my $debian_dir = $conf_dir ? $wr_dir->child($conf_dir) : $wr_dir ; - $debian_dir->mkpath( { mode => 0755 }); - say "dircopy ". $ex_data->stringify . '->'. $debian_dir->stringify + my $destination_dir = $conf_dir ? $wr_dir->child($conf_dir) : $wr_dir ; + $destination_dir->mkpath( { mode => 0755 }); + say "dircopy ". $ex_data->stringify . '->'. $destination_dir->stringify if $trace ; - dircopy( $ex_data->stringify, $debian_dir->stringify ) - || die "dircopy $ex_data -> $debian_dir failed:$!"; - @file_list = list_test_files ($debian_dir); + dircopy( $ex_data->stringify, $destination_dir->stringify ) + || die "dircopy $ex_data -> $destination_dir failed:$!"; + @file_list = list_test_files ($destination_dir); } elsif ( $ex_data->exists ) { + # either one if true if $conf_file is undef + die "test data is missing global \$conf_dir" unless defined $conf_dir; + die "test data is missing global \$conf_file_name" unless defined $conf_file; + # just copy file say "file copy ". $ex_data->stringify . '->'. $conf_file->stringify if $trace ; @@ -156,8 +165,17 @@ local $Config::Model::Value::nowarning = $args{no_warnings} || $t->{no_warnings} || 0; - note("updating config with ". join(' ',%args)); - my $res = $inst->update( from_dir => $dir, %args ) ; + my $res ; + if (my $uw = delete $args{update_warnings}) { + note("updating config with warning check and args: ". join(' ',%args)); + warnings_like { $res = $inst->update( from_dir => $dir, %args ); } $uw, + "Updated configuration with warning check "; + } + else { + note("updating config with no warning check and args: ". join(' ',%args)); + $res = $inst->update( from_dir => $dir, %args ) ; + } + if (defined $ret) { is($res,$ret,"updated configuration, got expected return value"); } @@ -167,10 +185,10 @@ } sub load_instructions { - my ($root,$t,$trace) = @_ ; + my ($root,$steps,$trace) = @_ ; - print "Loading $t->{load}\n" if $trace ; - $root->load( $t->{load} ); + print "Loading $steps\n" if $trace ; + $root->load( $steps ); ok( 1, "load called" ); } @@ -181,13 +199,13 @@ ok( 1, "apply_fixes called" ); } -sub dump_tree_full_mode { - my ($app_to_test, $root, $t, $trace) = @_; +sub dump_tree { + my ($app_to_test, $root, $mode, $no_warnings, $t, $trace) = @_; print "dumping tree ...\n" if $trace; my $dump = ''; my $risky = sub { - $dump = $root->dump_tree( mode => 'full' ); + $dump = $root->dump_tree( mode => $mode ); }; if ( defined $t->{dump_errors} ) { @@ -202,7 +220,7 @@ } } - if ( ($t->{no_warnings} or (exists $t->{dump_warnings}) and not defined $t->{dump_warnings}) ) { + if ( ($no_warnings or (exists $t->{dump_warnings}) and not defined $t->{dump_warnings}) ) { local $Config::Model::Value::nowarning = 1; &$risky; ok( 1, "Ran dump_tree (no warning check)" ); @@ -210,24 +228,12 @@ else { warnings_like { &$risky; } $t->{dump_warnings}, "Ran dump_tree"; } - ok( $dump, "Dumped $app_to_test config tree in full mode" ); + ok( $dump, "Dumped $app_to_test config tree in $mode mode" ); print $dump if $trace; return $dump; } -# TODO: factorise with function above and create parameters to -# handle warnings in both cases with warnings_like -sub dump_tree_custom_mode { - my ($label, $root, $t, $trace) = @_; - - local $Config::Model::Value::nowarning = $t->{no_warnings} || 0; - - my $dump = $root->dump_tree(); - ok( $dump, "Dumped $label config tree in custom mode" ); - return $dump; -} - sub check_data { my ($label, $root, $c, $nw) = @_; @@ -315,6 +321,27 @@ ok( 1, "$app_to_test write back done" ); } +sub check_file_mode { + my ($wr_dir, $t) = @_; + + if ($^O eq 'MSWin32' and my $fm = $t->{file_mode}) { + note("skipping file mode tests on Windows"); + return; + } + + if (my $fm = $t->{file_mode}) { + foreach my $f (keys %$fm) { + my $expected_mode = $fm->{$f} ; + my $stat = $wr_dir->child($f)->stat; + ok($stat ,"stat found file $f"); + if ($stat) { + my $mode = $stat->mode & 07777 ; + is($mode, $expected_mode, sprintf("check $f mode (got %o vs %o)",$mode,$expected_mode)); + } + } + } +} + sub check_file_content { my ($wr_dir, $t) = @_; @@ -322,9 +349,9 @@ foreach my $f (keys %$fc) { my $t = $fc->{$f} ; my @tests = ref $t eq 'ARRAY' ? @$t : ($t) ; - foreach (@tests) { - file_contents_eq_or_diff $wr_dir->child($f)->stringify, $_, - "check that $f contains $_"; + foreach my $subtest (@tests) { + file_contents_eq_or_diff $wr_dir->child($f)->stringify, $subtest, { encoding => 'UTF-8' }, + "check that $f contains $subtest"; } } } @@ -333,9 +360,9 @@ foreach my $f (keys %$fc) { my $t = $fc->{$f} ; my @tests = ref $t eq 'ARRAY' ? @$t : ($t) ; - foreach (@tests) { - file_contents_like $wr_dir->child($f)->stringify, $_, - "check that $f matches regexp $_"; + foreach my $subtest (@tests) { + file_contents_like $wr_dir->child($f)->stringify, $subtest, { encoding => 'UTF-8' }, + "check that $f matches regexp $subtest"; } } } @@ -344,9 +371,9 @@ foreach my $f (keys %$fc) { my $t = $fc->{$f} ; my @tests = ref $t eq 'ARRAY' ? @$t : ($t) ; - foreach (@tests) { - file_contents_unlike $wr_dir->child($f)->stringify, $_, - "check that $f does not match regexp $_"; + foreach my $subtest (@tests) { + file_contents_unlike $wr_dir->child($f)->stringify, $subtest, { encoding => 'UTF-8' }, + "check that $f does not match regexp $subtest"; } } } @@ -356,8 +383,11 @@ my ( $conf_dir, $wr_dir, $t, @file_list) = @_; # copy whole dir - my $debian_dir = $conf_dir ? $wr_dir->child($conf_dir) : $wr_dir ; - my @new_file_list = list_test_files($debian_dir) ; + my $destination_dir + = $t->{setup} ? $wr_dir + : $conf_dir ? $wr_dir->child($conf_dir) + : $wr_dir ; + my @new_file_list = list_test_files($destination_dir) ; $t->{file_check_sub}->( \@file_list ) if defined $t->{file_check_sub}; eq_or_diff( \@new_file_list, [ sort @file_list ], "check added or removed files" ); } @@ -369,6 +399,9 @@ dircopy( $wr_dir->stringify, $wr_dir2->stringify ) or die "can't copy from $wr_dir to $wr_dir2: $!"; + my @options; + push @options, backend_arg => $t->{backend_arg} if $t->{backend_arg}; + my $i2_test = $model->instance( root_class_name => $model_to_test, root_dir => $wr_dir2->stringify, @@ -377,6 +410,7 @@ application => $app_to_test, check => $t->{load_check2} || 'yes', config_dir => $config_dir_override, + @options ); ok( $i2_test, "Created instance $app_to_test-test-$t_name-w" ); @@ -395,10 +429,11 @@ undef $conf_file_name ; undef $conf_dir ; undef $home_for_test ; + undef $model_to_test ; note("Beginning $app_to_test test ($app_to_test_conf)"); - unless ( my $return = do $app_to_test_conf ) { + unless ( my $return = do "./$app_to_test_conf" ) { warn "couldn't parse $app_to_test_conf: $@" if $@; warn "couldn't do $app_to_test_conf: $!" unless defined $return; warn "couldn't run $app_to_test_conf" unless $return; @@ -432,6 +467,7 @@ my $idx = 0; foreach my $t (@tests) { + translate_test_data($t); my $t_name = $t->{name} || "t$idx"; if ( defined $do and $t_name !~ /$do/) { $idx++; @@ -440,18 +476,31 @@ note("Beginning subtest $app_to_test $t_name"); my ($wr_dir, $wr_dir2, $conf_file, $ex_data, @file_list) - = setup_test ($app_to_test, $t_name, $wr_root,$trace, $t->{setup}); + = setup_test ($app_to_test, $t_name, $wr_root,$trace, $t); write_config_file($conf_dir,$wr_dir,$t); + my $inst_name = "$app_to_test-" . $t_name; + + die "Duplicated test name $t_name for app $app_to_test\n" + if $model->has_instance ($inst_name); + + my @options; + push @options, backend_arg => $t->{backend_arg} if $t->{backend_arg}; + + # eventually, we may end up with several instances of Dpkg + # model in the same process. So we can't play with chdir my $inst = $model->instance( root_class_name => $model_to_test, + # need to keed root_dir to handle config files like + # /etc/foo.ini (absolute path, like in /etc/) root_dir => $wr_dir->stringify, - instance_name => "$app_to_test-" . $t_name, + instance_name => $inst_name, application => $app_to_test, config_file => $t->{config_file} , check => $t->{load_check} || 'yes', config_dir => $config_dir_override, + @options ); my $root = $inst->config_root; @@ -460,13 +509,16 @@ run_update($inst,$wr_dir,$t) if $t->{update}; - load_instructions ($root,$t,$trace) if $t->{load} ; + load_instructions ($root,$t->{load},$trace) if $t->{load} ; + + dump_tree ('before fix '.$app_to_test , $root, 'full', $t->{no_warnings}, $t->{check_before_fix}, $trace) + if $t->{check_before_fix}; apply_fix($inst) if $t->{apply_fix}; - dump_tree_full_mode ($app_to_test, $root, $t, $trace) ; + dump_tree ($app_to_test, $root, 'full', $t->{no_warnings}, $t->{full_dump}, $trace) ; - my $dump = dump_tree_custom_mode ($app_to_test, $root, $t, $trace) ; + my $dump = dump_tree ($app_to_test, $root, 'custom', $t->{no_warnings}, {}, $trace) ; check_data("first", $root, $t->{check}, $t->{no_warnings}) if $t->{check}; @@ -479,11 +531,15 @@ check_file_content($wr_dir,$t) ; + check_file_mode($wr_dir,$t) ; + check_added_or_removed_files ($conf_dir, $wr_dir, $t, @file_list) if $ex_data->is_dir; my $i2_root = create_second_instance ($app_to_test, $t_name, $wr_dir, $wr_dir2,$t, $config_dir_override); - my $p2_dump = dump_tree_custom_mode("second $app_to_test", $i2_root, $t) ; + load_instructions ($i2_root,$t->{load2},$trace) if $t->{load2} ; + + my $p2_dump = dump_tree("second $app_to_test", $i2_root, 'custom', $t->{no_warnings},{}) ; unified_diff; eq_or_diff( @@ -506,6 +562,22 @@ } +sub translate_test_data { + my $t = shift; + map {$t->{full_dump}{$_} = delete $t->{$_} if $t->{$_}; } qw/dump_warnings dump_errors/; +} + +sub create_model_object { + my $new_model ; + eval { $new_model = Config::Model->new(); } ; + if ($@) { + # necessary to run smoke test (no Config::Model to avoid dependency loop) + plan skip_all => 'Config::Model is not loaded' ; + return; + } + return $new_model; +} + sub run_tests { my ( $arg, $test_only_app, $do ) = @_; @@ -523,12 +595,6 @@ Log::Log4perl->easy_init( $log ? $WARN : $ERROR ); } - eval { $model = Config::Model->new(); } ; - if ($@) { - plan skip_all => 'Config::Model is not loaded' ; - return; - } - Config::Model::Exception::Any->Trace(1) if $arg =~ /e/; ok( 1, "compiled" ); @@ -541,6 +607,8 @@ foreach my $app_to_test_conf (@group_of_tests) { my ($app_to_test) = ( $app_to_test_conf =~ m!\.d/([\w\-]+)-test-conf! ); next if ( $test_only_app and $test_only_app ne $app_to_test ) ; + $model = create_model_object(); + return unless $model; run_model_test($app_to_test, $app_to_test_conf, $do, $model, $trace, $wr_root) ; } @@ -563,7 +631,7 @@ =head1 VERSION -version 2.053 +version 3.003 =head1 SYNOPSIS @@ -588,40 +656,66 @@ A specific layout for test files must be followed. +=head2 Test specification + +Each set of test is defined in a file like: + + t/model_tests.d/-test-conf.pl + +This file specifies that C (which is defined in +C directory) will be used for the test cases +defined in the C<*-test-conf.pl> file. + +This file contains a list of test case (explained below) and expects a +set of files used as test data. The layout of these test data files is +explained in next section. + =head2 Simple test file layout +Each test case is represented by a configuration file (not +a directory) in the C<*-examples> directory. This configuration file +will be used by the model to test and is copied as +C<$confdir/$conf_file_name> using the global variables explained +below. + +In the example below, we have 1 app model to test: C and 2 tests +cases. The app name matches the file specified in +C directory. In this case, the app name matches +C + t |-- model_test.t \-- model_tests.d # do not change directory name - |-- lcdd-test-conf.pl # test specification for lcdd model - \-- lcdd-examples + |-- lcdproc-test-conf.pl # test specification for lcdproc app + \-- lcdproc-examples |-- t0 # subtest t0 \-- LCDD-0.5.5 # subtest for older LCDproc -In the example above, we have 1 model to test: C and 2 tests -cases. The model name matches the file specified in -C directory. In this case, the model name matches -C - -Test specification is written in C file (i.e. this -modules looks for files named like C<< -test-conf.pl> >>). +Test specification is written in C file (i.e. this +modules looks for files named like C<< -test-conf.pl> >>). -Subtests are specified in files in directory C ( -i.e. this modules looks for subtests in directory -C<< -examples.pl> >>. C contains +Subtests data is proviced in files in directory C ( +i.e. this modules looks for test data in directory +C<< -examples> >>. C contains instructions so that each file will be used as a C file during each test case. -C can contain specifications for more test -case. Each test case will require a new file in C +C can contain specifications for more test +cases. Each test case requires a new file in C directory. See L for a link to the actual LCDproc model tests =head2 Test file layout for multi-file configuration -When a configuration is spread over several files, test examples must be -provided in sub-directories: +When a configuration is spread over several files, each test case is +provided in a sub-directory. This sub-directory is copied in +C<$conf_dir> (a global variable as explained below) + +In the example below, the test specification is written in +C. Dpkg layout requires several files per test case. +C will contain instructions so that each directory +under C will be used. t/model_tests.d \-- dpkg-test-conf.pl # test specification @@ -637,14 +731,22 @@ | \-- format \-- watch -In the example above, the test specification is written in -C. Dpkg layout requires several files per test case. -C will contain instructions so that each directory -under C will be used. - See L for a link to the (many) Dpkg model tests -=head2 Test file layout depending on system +=head2 More complex file layout + +Each test case is a sub-directory on the C<*-examples> directory and +contains several files. The destination of the test files may depend +on the system (e.g. the OS). For instance, system wide C +is stored in C on Linux, and directly in C on MacOS. + +These files are copied in a test directory using a C parameter: + + setup => { + test_file_in_example_dir => 'destination' + } + +Let's consider this example of 2 tests cases for ssh: t/model_tests.d/ |-- ssh-test-conf.pl @@ -653,24 +755,31 @@ |-- system_ssh_config \-- user_ssh_config -In this example, the layout of the configuration files depend on the -system. For instance, system wide C is stored in C on -Linux, and directly in C on MacOS. +Unfortunately, C is a user file, so you specify where +the home directory for the tests with another global variable: -L -will specify the target path of each file. I.e.: + $home_for_test = '/home/joe' ; - $home_for_test = $^O eq 'darwin' ? '/Users/joe' - : '/home/joe' ; +For Linux only, the C parameter is: - # ... + setup => { + 'system_ssh_config' => '/etc/ssh/ssh_config', + 'user_ssh_config' => "~/.ssh/config" + } + +On the other hand, system wide config file is different on MacOS and +the test file must be copied in the correct location. When the value +of the C hash is another hash, the key of this other hash is +used as to specify the target location for other OS (as returned by +Perl C<$^O> variable: setup => { 'system_ssh_config' => { 'darwin' => '/etc/ssh_config', 'default' => '/etc/ssh/ssh_config', }, - 'user_ssh_config' => "$home_for_test/.ssh/config" + 'user_ssh_config' => "~/.ssh/config" + } See the actual L @@ -714,10 +823,21 @@ See actual L. -=head2 Internal tests +=head2 Skip a test + +A test file can be skipped using C<$skip> global variable. + +In this example, test is skipped when not running on a Debian system: + + eval { require AptPkg::Config; }; + $skip = ( $@ or not -r '/etc/debian_version' ) ? 1 : 0; + +=head2 Internal tests or backend tests Some tests will require the creation of a configuration class dedicated -for test. This test class can be created directly in the test specification +for test (typically to test corner cases on a backend). + +This test class can be created directly in the test specification by calling L on C<$model> variable. See for instance the L @@ -726,9 +846,11 @@ =head2 Test specification with arbitrary file names -In some models (e.g. C, the config file is chosen by the user. -In this case, the file name must be specified for each tests case: +In some models like C, the config file is chosen by the +user. In this case, the file name must be specified for each tests +case: + # not needed if test file is named multistrap-test-conf.pl $model_to_test = "Multistrap"; @tests = ( @@ -739,7 +861,35 @@ }, ); -See actual L. +See the actual L. + +=head2 Backend argument + +Some application like systemd requires a backend argument specified by +User (e.g. a service name for systemd). The parameter C +can be specified to emulate this behavior. + +=head2 Re-use test data + +When the input data for test is quite complex (several files), it may +be interested to re-use these data for other tests case. Knowing that +test name must must unique, you can re-use test data with C +parameter. For instance: + + @tests = ( + { + name => 'some-test', + # ... + }, + { + name => 'some-other-test', + data_from => 'some-test', # re-use data from test above + # ... + }, + +See +L +for a real life example. =head2 Test scenario @@ -773,11 +923,40 @@ Optionally run L command: - update => { in => 'some-test-data.txt', returns => 'foo' , no_warnings => [ 0 | 1 ] } + update => { + [ returns => 'foo' , ] + no_warnings => [ 0 | 1 ], # default 0 + quiet => [ 0 | 1], # default 0, passed to update method + update_warnings => [ qr/.../, ] + } + +Where: + +=over + +=item * + +C is the expected return value (optional). + +=item * + +C to suppress the warnings coming from +L. Note that C<< no_warnings => 1 >> may be +useful for less verbose test. + +=item * + +C to suppress progress messages during update. + +=item * + +C is an array ref of quoted regexp (See qr operator) +to check the warnings produced during update. use C<< update => [] >> +to check that no warnings are issued during update. -C is the expected return value (optional). All other -arguments are passed to C method. Note that C<< quiet => 1 >> -may be useful for less verbose test. +=back + +All other arguments are passed to C method. =item * @@ -790,30 +969,51 @@ =item * -Optionally, call L: - - apply_fix => 1, +Optionally, run a check before running apply_fix (if any). This step is useful to check +warning messages: -=item * + check_before_fix => { + dump_errors => [ ... ] # optional, see below + dump_warnings => [ ... ] # optional, see below + } -Call L to check the validity of the -data. Use C if you expect issues: +Use C if you expect issues: + check_before_fix => { dump_errors => [ - # the issues the fix that will be applied + # the issues and a way to fix the issue using Config::Model::Node::load qr/mandatory/ => 'Files:"*" Copyright:0="(c) foobar"', qr/mandatory/ => ' License:FOO text="foo bar" ! Files:"*" License short_name="FOO" ' ], + } -=item * - -Likewise, specify any expected warnings (note the list must contain only C stuff): +Likewise, specify any expected warnings (note the list must contain +only ref to regular expressions): + check_before_fix => { dump_warnings => [ (qr/deprecated/) x 3 ], + } You can tolerate any dump warning this way: + check_before_fix => { dump_warnings => undef , + } + +Both C and C can be specified in C hash. + +=item * + +Optionally, call L: + + apply_fix => 1, + +=item * + +Call L to check the validity of the +data after optional C. This step is not optional. + +As with C, both C or C can be used. =item * @@ -905,6 +1105,20 @@ =item * +Check the mode of the written files: + + file_mode => { + "~/.ssh/ssh_config" => 0600, # octal mode + "debian/stuff.postinst" => 0755, + } + +Only the last four octets of the mode are tested. I.e. the test is done with +C< $file_mode & 07777 > + +Note: this test is skipped on Windows + +=item * + Check added or removed configuration files. If you expect changes, specify a subref to alter the file list: @@ -912,7 +1126,10 @@ my $list_ref = shift ; # file added during tests push @$list_ref, "/debian/source/format" ; - }; + }, + +Note that actual and expected file lists are sorted before check, +adding a file can be done with C. =item * @@ -923,7 +1140,7 @@ =item * -Create another configuration instance to read the conf file that was just copied +Create a second configuration instance to read the conf file that was just copied (configuration data is checked.) =item * @@ -933,6 +1150,16 @@ =item * +Optionally load configuration data in the second instance. You should +design this config data to suppress any error or warning that occur in +the step below. E.g: + + load2 => 'binary:seaview', + +See L for the syntax of the string accepted by C parameter. + +=item * + Compare data read from original data. =item * @@ -1045,7 +1272,7 @@ =head1 COPYRIGHT AND LICENSE -This software is Copyright (c) 2013-2016 by Dominique Dumont. +This software is Copyright (c) 2013-2017 by Dominique Dumont. This is free software, licensed under: @@ -1092,7 +1319,7 @@ The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. -L +L =item * diff -Nru libconfig-model-tester-perl-2.053/LICENSE libconfig-model-tester-perl-3.003/LICENSE --- libconfig-model-tester-perl-2.053/LICENSE 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/LICENSE 2017-11-05 11:22:09.000000000 +0000 @@ -1,4 +1,4 @@ -This software is Copyright (c) 2013-2016 by Dominique Dumont. +This software is Copyright (c) 2013-2017 by Dominique Dumont. This is free software, licensed under: diff -Nru libconfig-model-tester-perl-2.053/MANIFEST libconfig-model-tester-perl-3.003/MANIFEST --- libconfig-model-tester-perl-2.053/MANIFEST 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/MANIFEST 2017-11-05 11:22:09.000000000 +0000 @@ -1,4 +1,4 @@ -# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.043. +# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. Build.PL Changes LICENSE diff -Nru libconfig-model-tester-perl-2.053/META.json libconfig-model-tester-perl-3.003/META.json --- libconfig-model-tester-perl-2.053/META.json 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/META.json 2017-11-05 11:22:09.000000000 +0000 @@ -4,13 +4,13 @@ "Dominique Dumont" ], "dynamic_config" : 0, - "generated_by" : "Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150005", + "generated_by" : "Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010", "license" : [ "lgpl_2_1" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", - "version" : 2 + "version" : "2" }, "name" : "Config-Model-Tester", "prereqs" : { @@ -52,6 +52,7 @@ "web" : "http://github.com/dod38fr/config-model-tester.git" } }, - "version" : "2.053" + "version" : "3.003", + "x_serialization_backend" : "JSON::XS version 3.04" } diff -Nru libconfig-model-tester-perl-2.053/META.yml libconfig-model-tester-perl-3.003/META.yml --- libconfig-model-tester-perl-2.053/META.yml 2016-03-28 19:01:44.000000000 +0000 +++ libconfig-model-tester-perl-3.003/META.yml 2017-11-05 11:22:09.000000000 +0000 @@ -7,7 +7,7 @@ configure_requires: Module::Build: '0.34' dynamic_config: 0 -generated_by: 'Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150005' +generated_by: 'Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010' license: lgpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -28,4 +28,5 @@ bugtracker: https://github.com/dod38fr/config-model-tester/issues homepage: https://github.com/dod38fr/config-model/wiki repository: git://github.com/dod38fr/config-model-tester.git -version: '2.053' +version: '3.003' +x_serialization_backend: 'YAML::Tiny version 1.70'