Config-Model-Tester-3.003/0000755000175000017500000000000013177572141013700 5ustar domidomiConfig-Model-Tester-3.003/MANIFEST0000644000175000017500000000033513177572141015032 0ustar domidomi# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. Build.PL Changes LICENSE MANIFEST MANIFEST.SKIP META.json META.yml README.pod lib/Config/Model/Tester.pm t/model_tests.t t/pod.t weaver.ini Config-Model-Tester-3.003/LICENSE0000644000175000017500000006013213177572141014707 0ustar domidomiThis 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 The GNU Lesser General Public License (LGPL) Version 2.1, February 1999 (The master copy of this license lives on the GNU website.) Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Config-Model-Tester-3.003/t/0000755000175000017500000000000013177572141014143 5ustar domidomiConfig-Model-Tester-3.003/t/pod.t0000644000175000017500000000044613177572141015116 0ustar domidomiBEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } use strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok( ); Config-Model-Tester-3.003/t/model_tests.t0000644000175000017500000000032513177572141016652 0ustar domidomi# -*- cperl -*- use warnings; use strict; use Config::Model::Tester ; use ExtUtils::testlib; my $arg = shift || ''; my $test_only_model = shift || ''; my $do = shift ; run_tests($arg, $test_only_model, $do) ; Config-Model-Tester-3.003/weaver.ini0000644000175000017500000000022513177572141015671 0ustar domidomi[@Default] [-Transformer] transformer = List [Support] perldoc = 0 bugs = metadata websites = search,anno,ratings,kwalitee,testers,testmatrix,deps Config-Model-Tester-3.003/Changes0000644000175000017500000000721313177572141015176 0ustar domidomi3.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: * pass application when creating instance * use config_dir specified in app info file Improvements: * Report error with model specification * Improved doc 2.052 2015-10-17 * New features: * subtest filter parameter is now a regexp. I.e you can filter tests like this: prove t/model_test.t :: x stuff '^foo$' * you can run update test with no_warnings and quiet param * global no_warnings param also apply to load and dump * Misc: * bug tracker is now on github 2.051 2015-05-20 * New features: + Added has_key and has_not_key parameters to check hash element content 2.050 2015-03-29 * Bug fix: * fix check_data function 2.049 2015-03-28 * New features: * check argument also accept a regexp ( i.e. a qr// ) + added option to run 'update' test * Allow to start test without config file (from scratch) * changed dependency: * replaced Path::Class with Path::Tiny * Internal changes: * refactored most of the logic in separate functions 2.048 2014-06-04 * C::M::Tester: added load_check2 parameter 2.047 2013-10-06 * Updated Pod documents and added link to examples * Updated dependency list 2.046 2013-09-20 * depends on Path::Class >= 0.29 2.045 2013-09-15 * Fix broken tests on Windows (mixup between / and \ ) 2.044 2013-09-07 * accept array ref for file_contents* tests * fix spurious creation of '0' dir 2.043 2013-08-23 * fix file_content* tests (bad path computation) 2.042 2013-08-14 * fix file created/removed comparison * added require perl5.10 2.041 2013-08-12 * rewrote using Path::Class. Added setup parameter 2.041_01 2013-08-11 * Initial release. This module was moved from Config-Model distribution. Config-Model-Tester-3.003/lib/0000755000175000017500000000000013177572141014446 5ustar domidomiConfig-Model-Tester-3.003/lib/Config/0000755000175000017500000000000013177572141015653 5ustar domidomiConfig-Model-Tester-3.003/lib/Config/Model/0000755000175000017500000000000013177572141016713 5ustar domidomiConfig-Model-Tester-3.003/lib/Config/Model/Tester.pm0000644000175000017500000012050713177572141020524 0ustar domidomi# # This file is part of Config-Model-Tester # # 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 # package Config::Model::Tester; # ABSTRACT: Test framework for Config::Model $Config::Model::Tester::VERSION = '3.003'; use warnings; use strict; use locale; use utf8; use 5.10.1; use Test::More; use Log::Log4perl 1.11 qw(:easy :levels); use Path::Tiny; use File::Copy::Recursive qw(fcopy rcopy dircopy); use Test::Warn; use Test::Exception; use Test::File::Contents ; use Test::Differences; use Test::Memory::Cycle ; # use eval so this module does not have a "hard" dependency on Config::Model # This way, Config::Model can build-depend on Config::Model::Tester without # creating a build dependency loop. eval { require Config::Model; require Config::Model::Lister; require Config::Model::Value; require Config::Model::BackendMgr; } ; use vars qw/$model $conf_file_name $conf_dir $model_to_test $home_for_test @tests $skip @ISA @EXPORT/; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(run_tests); $File::Copy::Recursive::DirPerms = 0755; sub setup_test { 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 ; $conf_file = $wr_dir->child($conf_dir,$conf_file_name) 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_data->{data_from} // $t_name); my @file_list; if (my $setup = $t_data->{setup}) { foreach my $file (keys %$setup) { my $map = $setup->{$file} ; my $destination_str = ref ($map) eq 'HASH' ? $map->{$^O} // $map->{default} : $map; 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_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 $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, $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 ; fcopy( $ex_data->stringify, $conf_file->stringify ) || die "copy $ex_data -> $conf_file failed:$!"; } else { note ('starting test without original config data, i.e. from scratch'); } ok( 1, "Copied $app_to_test example $t_name" ); return ( $wr_dir, $wr_dir2, $conf_file, $ex_data, @file_list ); } # # New subroutine "list_test_files" extracted - Thu Nov 17 17:27:20 2011. # sub list_test_files { my $debian_dir = shift; my @file_list ; my $iter = $debian_dir->iterator({ recurse => 1 }); my $debian_str = $debian_dir->stringify; while ( my $child = $iter->() ) { next if $child->is_dir ; push @file_list, '/' . $child->relative($debian_str)->stringify; #push @file_list, '/'.join('/',@l) ; # build a unix-like path even on windows }; return sort @file_list; } sub write_config_file { my ($conf_dir,$wr_dir,$t) = @_; if ($t->{config_file}) { my $file = $conf_dir ? "$conf_dir/" : ''; $file .= $t->{config_file} ; $wr_dir->child($file)->parent->mkpath({mode => 0755} ) ; } } sub check_load_warnings { my ($root,$t) = @_ ; if ( ($t->{no_warnings} or exists $t->{load_warnings}) and not defined $t->{load_warnings}) { local $Config::Model::Value::nowarning = 1; $root->init; ok( 1,"Read configuration and created instance with init() method without warning check" ); } else { warnings_like { $root->init; } $t->{load_warnings}, "Read configuration and created instance with init() method with warning check "; } } sub run_update { my ($inst, $dir, $t) = @_; my %args = %{$t->{update}}; my $ret = delete $args{returns}; local $Config::Model::Value::nowarning = $args{no_warnings} || $t->{no_warnings} || 0; 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"); } else { ok(1,"updated configuration"); } } sub load_instructions { my ($root,$steps,$trace) = @_ ; print "Loading $steps\n" if $trace ; $root->load( $steps ); ok( 1, "load called" ); } sub apply_fix { my $inst = shift; local $Config::Model::Value::nowarning = 1; $inst->apply_fixes; ok( 1, "apply_fixes called" ); } 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 => $mode ); }; if ( defined $t->{dump_errors} ) { my $nb = 0; my @tf = @{ $t->{dump_errors} }; while (@tf) { my $qr = shift @tf; throws_ok { &$risky } $qr, "Failed dump $nb of $app_to_test config tree"; my $fix = shift @tf; $root->load($fix); ok( 1, "Fixed error nb " . $nb++ ); } } 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)" ); } else { warnings_like { &$risky; } $t->{dump_warnings}, "Ran dump_tree"; } ok( $dump, "Dumped $app_to_test config tree in $mode mode" ); print $dump if $trace; return $dump; } sub check_data { my ($label, $root, $c, $nw) = @_; local $Config::Model::Value::nowarning = $nw || 0; my @checks = ref $c eq 'ARRAY' ? @$c : map { ( $_ => $c->{$_})} sort keys %$c ; while (@checks) { my $path = shift @checks; my $v = shift @checks; my $check_v = ref $v eq 'HASH' ? delete $v->{value} : $v; my @check_args = ref $v eq 'HASH' ? %$v : (); my $check_str = @check_args ? " (@check_args)" : ''; my $obj = $root->grab( step => $path, type => ['leaf','check_list'], @check_args ); my $got = $obj->fetch(@check_args); if (ref $check_v eq 'Regexp') { like( $got, $check_v, "$label check '$path' value with regexp$check_str" ); } else { is( $got, $check_v, "$label check '$path' value$check_str" ); } } } sub check_annotation { my ($root, $t) = @_; my $annot_check = $t->{verify_annotation}; foreach my $path (keys %$annot_check) { my $note = $annot_check->{$path}; is( $root->grab($path)->annotation, $note, "check $path annotation" ); } } sub has_key { my ($root, $c, $nw) = @_; _test_key($root, $c, $nw, 0); } sub has_not_key { my ($root, $c, $nw) = @_; _test_key($root, $c, $nw, 1); } sub _test_key { my ($root, $c, $nw, $invert) = @_; my @checks = ref $c eq 'ARRAY' ? @$c : map { ( $_ => $c->{$_})} sort keys %$c ; while (@checks) { my $path = shift @checks; my $spec = shift @checks; my @key_checks = ref $spec eq 'ARRAY' ? @$spec: ($spec); my $obj = $root->grab( step => $path, type => 'hash' ); my @keys = $obj->fetch_all_indexes; my $res = 0; foreach my $check (@key_checks) { my @match ; foreach my $k (@keys) { if (ref $check eq 'Regexp') { push @match, $k if $k =~ $check; } else { push @match, $k if $k eq $check; } } if ($invert) { is(scalar @match,0, "check $check matched no key" ); } else { ok(scalar @match, "check $check matched with keys @match" ); } } } } sub write_data_back { my ($app_to_test, $inst, $t) = @_; local $Config::Model::Value::nowarning = $t->{no_warnings} || 0; $inst->write_back( force => 1 ); 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) = @_; if (my $fc = $t->{file_contents} || $t->{file_content}) { foreach my $f (keys %$fc) { my $t = $fc->{$f} ; my @tests = ref $t eq 'ARRAY' ? @$t : ($t) ; foreach my $subtest (@tests) { file_contents_eq_or_diff $wr_dir->child($f)->stringify, $subtest, { encoding => 'UTF-8' }, "check that $f contains $subtest"; } } } if (my $fc = $t->{file_contents_like}) { foreach my $f (keys %$fc) { my $t = $fc->{$f} ; my @tests = ref $t eq 'ARRAY' ? @$t : ($t) ; foreach my $subtest (@tests) { file_contents_like $wr_dir->child($f)->stringify, $subtest, { encoding => 'UTF-8' }, "check that $f matches regexp $subtest"; } } } if (my $fc = $t->{file_contents_unlike}) { foreach my $f (keys %$fc) { my $t = $fc->{$f} ; my @tests = ref $t eq 'ARRAY' ? @$t : ($t) ; foreach my $subtest (@tests) { file_contents_unlike $wr_dir->child($f)->stringify, $subtest, { encoding => 'UTF-8' }, "check that $f does not match regexp $subtest"; } } } } sub check_added_or_removed_files { my ( $conf_dir, $wr_dir, $t, @file_list) = @_; # copy whole 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" ); } sub create_second_instance { my ($app_to_test, $t_name, $wr_dir, $wr_dir2,$t, $config_dir_override) = @_; # create another instance to read the conf file that was just written 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, config_file => $t->{config_file} , instance_name => "$app_to_test-$t_name-w", 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" ); local $Config::Model::Value::nowarning = $t->{no_warnings} || 0; my $i2_root = $i2_test->config_root; $i2_root->init; return $i2_root; } sub run_model_test { my ($app_to_test, $app_to_test_conf, $do, $model, $trace, $wr_root) = @_ ; $skip = 0; 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" ) { 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; } if ($skip) { note("Skipped $app_to_test test ($app_to_test_conf)"); return; } my ($trash, $appli_info, $applications) = Config::Model::Lister::available_models(1); # even undef, this resets the global variable there Config::Model::BackendMgr::_set_test_home($home_for_test) ; if (not defined $model_to_test) { $model_to_test = $applications->{$app_to_test}; if (not defined $model_to_test) { my @k = sort values %$applications; my @files = map { $_->{_file} // 'unknown' } values %$appli_info ; die "Cannot find model name for $app_to_test in files >@files<. Know dev models are >@k<. ". "Check your test name (the file ending with -test-conf.pl) or set the \$model_to_test global variable\n"; } } my $config_dir_override = $appli_info->{$app_to_test}{config_dir}; # may be undef my $note ="$app_to_test uses $model_to_test model"; $note .= " on file $conf_file_name" if defined $conf_file_name; note($note); 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++; next; } 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); 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 => $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; check_load_warnings ($root,$t); run_update($inst,$wr_dir,$t) if $t->{update}; 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 ($app_to_test, $root, 'full', $t->{no_warnings}, $t->{full_dump}, $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}; has_key ( $root, $t->{has_key}, $t->{no_warnings}) if $t->{has_key} ; has_not_key ( $root, $t->{has_not_key}, $t->{no_warnings}) if $t->{has_not_key} ; check_annotation($root,$t) if $t->{verify_annotation}; write_data_back ($app_to_test, $inst, $t) ; 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); 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( [ split /\n/,$p2_dump ], [ split /\n/,$dump ], "compare original $app_to_test custom data with 2nd instance custom data", ); ok( -s "$wr_dir2/$conf_dir/$conf_file_name" , "check that original $app_to_test file was not clobbered" ) if defined $conf_file_name ; check_data("second", $i2_root, $t->{wr_check}, $t->{no_warnings}) if $t->{wr_check} ; note("End of subtest $app_to_test $t_name"); $idx++; } note("End of $app_to_test test"); } 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 ) = @_; my $log = 0; my $trace = ($arg =~ /t/) ? 1 : 0; $log = 1 if $arg =~ /l/; my $log4perl_user_conf_file = ($ENV{HOME} || '') . '/.log4config-model'; if ( $log and -e $log4perl_user_conf_file ) { Log::Log4perl::init($log4perl_user_conf_file); } else { Log::Log4perl->easy_init( $log ? $WARN : $ERROR ); } Config::Model::Exception::Any->Trace(1) if $arg =~ /e/; ok( 1, "compiled" ); # pseudo root where config files are written by config-model my $wr_root = path('wr_root'); my @group_of_tests = grep { /-test-conf.pl$/ } glob("t/model_tests.d/*"); 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) ; } memory_cycle_ok($model,"test memory cycle") ; done_testing; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Config::Model::Tester - Test framework for Config::Model =head1 VERSION version 3.003 =head1 SYNOPSIS # in t/model_test.t use warnings; use strict; use Config::Model::Tester ; use ExtUtils::testlib; my $arg = shift || ''; # typically e t l my $test_only_app = shift || ''; # only run one set of test my $do = shift ; # select subtests to run with a regexp run_tests($arg, $test_only_app, $do) ; =head1 DESCRIPTION This class provides a way to test configuration models with tests files. This class was designed to tests several models and several tests cases per model. 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 |-- lcdproc-test-conf.pl # test specification for lcdproc app \-- lcdproc-examples |-- t0 # subtest t0 \-- LCDD-0.5.5 # subtest for older LCDproc Test specification is written in C file (i.e. this modules looks for files named like C<< -test-conf.pl> >>). 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 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, 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 \-- dpkg-examples \-- libversion # example subdir, used as subtest name \-- debian # directory for one test case |-- changelog |-- compat |-- control |-- copyright |-- rules |-- source | \-- format \-- watch See L for a link to the (many) Dpkg model tests =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 |-- ssh-examples \-- basic |-- system_ssh_config \-- user_ssh_config Unfortunately, C is a user file, so you specify where the home directory for the tests with another global variable: $home_for_test = '/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' => "~/.ssh/config" } See the actual L =head2 Basic test specification Each model test is specified in C<< -test-conf.pl >>. This file contains a set of global variables. (yes, global variables are often bad ideas in programs, but they are handy for tests): # config file name (used to copy test case into test wr_root directory) $conf_file_name = "fstab" ; # config dir where to copy the file (optional) #$conf_dir = "etc" ; # home directory for this test $home_for_test = '/home/joe' ; Here, C file will be copied in C. # config model name to test $model_to_test = "Fstab" ; # list of tests. This modules looks for @tests global variable @tests = ( { # test name name => 't0', # add optional specification here for t0 test }, { name => 't1', # add optional specification here for t1 test }, ); 1; # to keep Perl happy You can suppress warnings by specifying C<< no_warnings => 1 >>. On the other hand, you may also want to check for warnings specified to your model. In this case, you should avoid specifying C here and specify warning tests or warning filters as mentioned below. See actual L. =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 (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 or the L. =head2 Test specification with arbitrary file names 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 = ( { name => 'arm', config_file => '/home/foo/my_arm.conf', check => {}, }, ); 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 Each subtest follow a sequence explained below. Each step of this sequence may be altered by adding specification in C<< -test-conf.pl >>: =over =item * Setup test in C<< wr_root// >>. If your configuration file layout depend on the target system, you will have to specify the path using C parameter. See L. =item * Create configuration instance, load config data and check its validity. Use C<< load_check => 'no' >> if your file is not valid. =item * Check for config data warning. You should pass the list of expected warnings. E.g. load_warnings => [ qr/Missing/, (qr/deprecated/) x 3 , ], Use an empty array_ref to mask load warnings. =item * Optionally run L command: 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. =back All other arguments are passed to C method. =item * Optionally load configuration data. You should design this config data to suppress any error or warning mentioned above. E.g: load => 'binary:seaview Synopsis="multiplatform interface for sequence alignment"', See L for the syntax of the string accepted by C parameter. =item * Optionally, run a check before running apply_fix (if any). This step is useful to check warning messages: check_before_fix => { dump_errors => [ ... ] # optional, see below dump_warnings => [ ... ] # optional, see below } Use C if you expect issues: check_before_fix => { dump_errors => [ # 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" ' ], } 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 * Run specific content check to verify that configuration data was retrieved correctly: check => { 'fs:/proc fs_spec', "proc" , 'fs:/proc fs_file', "/proc" , 'fs:/home fs_file', "/home", }, The keys of the hash points to the value to be checked using the syntax described in L. You can run check using different check modes (See L) by passing a hash ref instead of a scalar : check => { 'sections:debian packages:0' , { mode => 'layered', value => 'dpkg-dev' }, 'sections:base packages:0', { mode => 'layered', value => "gcc-4.2-base' }, }, The whole hash content (except "value") is passed to L and L A regexp can also be used to check value: check => { "License text" => qr/gnu/i, "License text" => { mode => 'custom', value => qr/gnu/i }, } =item * Verify if a hash contains one or more keys (or keys matching a regexp): has_key => [ 'sections' => 'debian', # sections must point to a hash element 'control' => [qw/source binary/], 'copyright Files' => qr/.c$/, 'copyright Files' => [qr/\.h$/], qr/\.c$/], ], =item * Verify that a hash has B a key (or a key matching a regexp): has_not_key => [ 'copyright Files' => qr/.virus$/ # silly, isn't ? ], =item * Verify annotation extracted from the configuration file comments: verify_annotation => { 'source Build-Depends' => "do NOT add libgtk2-perl to build-deps (see bug #554704)", 'source Maintainer' => "what a fine\nteam this one is", }, =item * Write back the config data in C<< wr_root// >>. Note that write back is forced, so the tested configuration files are written back even if the configuration values were not changed during the test. You can skip warning when writing back with the global : no_warnings => 1, =item * Check the content of the written files(s) with L. Tests can be grouped in an array ref: file_contents => { "/home/foo/my_arm.conf" => "really big string" , "/home/bar/my_arm.conf" => [ "really big string" , "another"], , } file_contents_like => { "/home/foo/my_arm.conf" => [ qr/should be there/, qr/as well/ ] , } file_contents_unlike => { "/home/foo/my_arm.conf" => qr/should NOT be there/ , } =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: file_check_sub => sub { 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 * Copy all config data from C<< wr_root// >> to C<< wr_root/-w/ >>. This steps is necessary to check that configuration written back has the same content as the original configuration. =item * Create a second configuration instance to read the conf file that was just copied (configuration data is checked.) =item * You can skip the load check if the written file still contain errors (e.g. some errors were ignored and cannot be fixed) with C<< load_check2 => 'no' >> =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 * Run specific content check on the B config file to verify that configuration data was written and retrieved correctly: wr_check => { 'fs:/proc fs_spec' => "proc" , 'fs:/proc fs_file' => "/proc", 'fs:/home fs_file' => "/home", }, Like the C item explained above, you can run C using different check modes. =back =head2 Running the test Run all tests with one of these commands: prove -l t/model_test.t :: [ t|l|e [ [ ]]] perl -Ilib t/model_test.t [ t|l|e [ [ ]]] By default, all tests are run on all models. You can pass arguments to C: =over =item * a bunch of letters. 't' to get test traces. 'e' to get stack trace in case of errors, 'l' to have logs. All other letters are ignored. E.g. # run with log and error traces prove -lv t/model_test.t :: el =item * The model name to tests. E.g.: # run only fstab tests prove -lv t/model_test.t :: x fstab =item * A regexp to filter subtest E.g.: # run only fstab tests foobar subtest prove -lv t/model_test.t :: x fstab foobar # run only fstab tests foo subtest prove -lv t/model_test.t :: x fstab '^foo$' =back =head1 Examples =over =item * L has a single configuration file: C. Here's LCDproc test L and the L =item * Dpkg packages are constructed from several files. These files are handled like configuration files by L. The L features test with multiple file in L. The test is specified in L =item * L and L specify a test where the configuration file name is not imposed by the application. The file name must then be set in the test specification. =item * L is a more complex example showing how to test a backend. The test is done creating a dummy model within the test specification. =back =head1 SEE ALSO =over 4 =item * L =item * L =back =head1 AUTHOR Dominique Dumont =head1 COPYRIGHT AND LICENSE 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 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Websites The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources. =over 4 =item * Search CPAN The default CPAN search engine, useful to view POD in HTML format. L =item * AnnoCPAN The AnnoCPAN is a website that allows community annotations of Perl module documentation. L =item * CPAN Ratings The CPAN Ratings is a website that allows community ratings and reviews of Perl modules. L =item * CPANTS The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. L =item * CPAN Testers The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions. L =item * CPAN Testers Matrix The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. L =item * CPAN Testers Dependencies The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. L =back =head2 Bugs / Feature Requests Please report any bugs or feature requests by email to C, or through the web interface at L. You will be automatically notified of any progress on the request by the system. =head2 Source Code The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :) L git clone git://github.com/dod38fr/config-model-tester.git =cut Config-Model-Tester-3.003/README.pod0000644000175000017500000000043113177572141015337 0ustar domidomi=head1 Tester class to test configuration models for Config::Model Config::Model::Tester provides a way to test configuration models with tests files. This class was designed to tests several models and several tests cases per model. For details, see L Config-Model-Tester-3.003/META.json0000644000175000017500000000310313177572141015316 0ustar domidomi{ "abstract" : "Test framework for Config::Model", "author" : [ "Dominique Dumont" ], "dynamic_config" : 0, "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" }, "name" : "Config-Model-Tester", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.34" } }, "configure" : { "requires" : { "Module::Build" : "0.34" } }, "runtime" : { "requires" : { "File::Copy::Recursive" : "0", "Log::Log4perl" : "1.11", "Path::Tiny" : "0", "Test::Differences" : "0", "Test::Exception" : "0", "Test::File::Contents" : "0", "Test::Memory::Cycle" : "0", "Test::More" : "0", "Test::Warn" : "0", "perl" : "5.010" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "ddumont at cpan.org", "web" : "https://github.com/dod38fr/config-model-tester/issues" }, "homepage" : "https://github.com/dod38fr/config-model/wiki", "repository" : { "type" : "git", "url" : "git://github.com/dod38fr/config-model-tester.git", "web" : "http://github.com/dod38fr/config-model-tester.git" } }, "version" : "3.003", "x_serialization_backend" : "JSON::XS version 3.04" } Config-Model-Tester-3.003/MANIFEST.SKIP0000644000175000017500000000014613177572141015577 0ustar domidomi^debian/ ~$ \.ptkdb$ \.old$ dist.ini _build \.orig$ ^MYMETA blib wr_root \.rej$ README.build-from-git Config-Model-Tester-3.003/META.yml0000644000175000017500000000160213177572141015150 0ustar domidomi--- abstract: 'Test framework for Config::Model' author: - 'Dominique Dumont' build_requires: Module::Build: '0.34' configure_requires: Module::Build: '0.34' dynamic_config: 0 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 version: '1.4' name: Config-Model-Tester requires: File::Copy::Recursive: '0' Log::Log4perl: '1.11' Path::Tiny: '0' Test::Differences: '0' Test::Exception: '0' Test::File::Contents: '0' Test::Memory::Cycle: '0' Test::More: '0' Test::Warn: '0' perl: '5.010' resources: 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: '3.003' x_serialization_backend: 'YAML::Tiny version 1.70' Config-Model-Tester-3.003/Build.PL0000644000175000017500000000257713177572141015207 0ustar domidomi# # This file is part of Config-Model-Tester # # 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 v6.010. use strict; use warnings; use Module::Build 0.34; my %module_build_args = ( "build_requires" => { "Module::Build" => "0.34" }, "configure_requires" => { "Module::Build" => "0.34" }, "dist_abstract" => "Test framework for Config::Model", "dist_author" => [ "Dominique Dumont" ], "dist_name" => "Config-Model-Tester", "dist_version" => "3.003", "license" => "lgpl", "module_name" => "Config::Model::Tester", "recursive_test_files" => 1, "requires" => { "File::Copy::Recursive" => 0, "Log::Log4perl" => "1.11", "Path::Tiny" => 0, "Test::Differences" => 0, "Test::Exception" => 0, "Test::File::Contents" => 0, "Test::Memory::Cycle" => 0, "Test::More" => 0, "Test::Warn" => 0, "perl" => "5.010" } ); my %fallback_build_requires = ( "Module::Build" => "0.34" ); unless ( eval { Module::Build->VERSION(0.4004) } ) { delete $module_build_args{test_requires}; $module_build_args{build_requires} = \%fallback_build_requires; } my $build = Module::Build->new(%module_build_args); $build->create_build_script;