.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Config::Model::Tester 3pm" .TH Config::Model::Tester 3pm "2014-06-05" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Config::Model::Tester \- Test framework for Config::Model .SH "VERSION" .IX Header "VERSION" version 2.048 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # in t/model_test.t \& use warnings; \& use strict; \& \& use Config::Model::Tester ; \& use ExtUtils::testlib; \& \& my $arg = shift || \*(Aq\*(Aq; \& my $test_only_model = shift || \*(Aq\*(Aq; \& my $do = shift ; \& \& run_tests($arg, $test_only_model, $do) ; .Ve .SH "DESCRIPTION" .IX Header "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. .PP A specific layout for test files must be followed .SS "Simple test file layout" .IX Subsection "Simple test file layout" .Vb 7 \& t \& |\-\- model_test.t \& \e\-\- model_tests.d \& |\-\- lcdd\-test\-conf.pl # test specification \& \e\-\- lcdd\-examples \& |\-\- t0 # test case t0 \& \e\-\- LCDD\-0.5.5 # test case for older LCDproc .Ve .PP In the example above, we have 1 model to test: \f(CW\*(C`lcdd\*(C'\fR and 2 tests cases. .PP Test specification is written in \f(CW\*(C`lcdd\-test\-conf.pl\*(C'\fR file. Test cases are plain files in \f(CW\*(C`lcdd\-examples\*(C'\fR. \f(CW\*(C`lcdd\-test\-conf.pl\*(C'\fR will contain instructions so that each file will be used as a \&\f(CW\*(C`/etc/LCDd.conf\*(C'\fR file during each test case. .PP \&\f(CW\*(C`lcdd\-test\-conf.pl\*(C'\fR can contain specifications for more test case. Each test case will require a new file in \f(CW\*(C`lcdd\-examples\*(C'\fR directory. .PP See \*(L"Examples\*(R" for a link to the actual LCDproc model tests .SS "Test file layout for multi-file configuration" .IX Subsection "Test file layout for multi-file configuration" When a configuration is spread over several files, test examples must be provided in sub-directories: .PP .Vb 10 \& t/model_tests.d \& \e\-\- dpkg\-test\-conf.pl # test specification \& \e\-\- dpkg\-examples \& \e\-\- libversion # example subdir \& \e\-\- debian # directory for one test case \& |\-\- changelog \& |\-\- compat \& |\-\- control \& |\-\- copyright \& |\-\- rules \& |\-\- source \& | \e\-\- format \& \e\-\- watch .Ve .PP In the example above, the test specification is written in \&\f(CW\*(C`dpkg\-test\-conf.pl\*(C'\fR. Dpkg layout requires several files per test case. \&\f(CW\*(C`dpkg\-test\-conf.pl\*(C'\fR will contain instruction so that each directory under \f(CW\*(C`dpkg\-examples\*(C'\fR will be used. .PP See \*(L"Examples\*(R" for a link to the (many) Dpkg model tests .SS "Test file layout depending on system" .IX Subsection "Test file layout depending on system" .Vb 6 \& t/model_tests.d/ \& |\-\- ssh\-test\-conf.pl \& |\-\- ssh\-examples \& \e\-\- basic \& |\-\- system_ssh_config \& \e\-\- user_ssh_config .Ve .PP In this example, the layout of the configuration files depend on the system. For instance, system wide \f(CW\*(C`ssh_config\*(C'\fR is stored in \f(CW\*(C`/etc/ssh\*(C'\fR on Linux, and directly in \f(CW\*(C`/etc\*(C'\fR on MacOS. .PP ssh\-test\-conf.pl will specify the target path of each file. I.e.: .PP .Vb 2 \& $home_for_test = $^O eq \*(Aqdarwin\*(Aq ? \*(Aq/Users/joe\*(Aq \& : \*(Aq/home/joe\*(Aq ; \& \& # ... \& \& setup => { \& \*(Aqsystem_ssh_config\*(Aq => { \& \*(Aqdarwin\*(Aq => \*(Aq/etc/ssh_config\*(Aq, \& \*(Aqdefault\*(Aq => \*(Aq/etc/ssh/ssh_config\*(Aq, \& }, \& \*(Aquser_ssh_config\*(Aq => "$home_for_test/.ssh/config" .Ve .PP See the actual Ssh and Sshd model tests .SS "Basic test specification" .IX Subsection "Basic test specification" Each model test is specified in \f(CW\*(C`\-test\-conf.pl\*(C'\fR. This file contains a set of global variable. (yes, global variables are often bad ideas in programs, but they are handy for tests): .PP .Vb 6 \& # config file name (used to copy test case into test wr_root directory) \& $conf_file_name = "fstab" ; \& # config dir where to copy the file \& #$conf_dir = "etc" ; \& # home directory for this test \& $home_for_test = \*(Aq/home/joe\*(Aq ; .Ve .PP Here, \f(CW\*(C`t0\*(C'\fR file will be copied in \f(CW\*(C`wr_root/test\-t0/etc/fstab\*(C'\fR. .PP .Vb 2 \& # config model name to test \& $model_to_test = "Fstab" ; \& \& # list of tests \& @tests = ( \& { \& # test name \& name => \*(Aqt0\*(Aq, \& # add optional specification here for t0 test \& }, \& { \& name => \*(Aqt1\*(Aq, \& # add optional specification here for t1 test \& }, \& ); \& \& 1; # to keep Perl happy .Ve .PP See actual fstab test . .SS "Internal tests" .IX Subsection "Internal 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 by calling create_config_class on \&\f(CW$model\fR variable. See for instance the layer test or the test for shellvar backend . .SS "Test specification with arbitrary file names" .IX Subsection "Test specification with arbitrary file names" In some models (e.g. \f(CW\*(C`Multistrap\*(C'\fR, the config file is chosen by the user. In this case, the file name must be specified for each tests case: .PP .Vb 1 \& $model_to_test = "Multistrap"; \& \& @tests = ( \& { \& name => \*(Aqarm\*(Aq, \& config_file => \*(Aq/home/foo/my_arm.conf\*(Aq, \& check => {}, \& }, \& ); .Ve .PP See actual multistrap test . .SS "Test scenario" .IX Subsection "Test scenario" Each subtest follow a sequence explained below. Each step of this sequence may be altered by adding specification in the test case: .IP "\(bu" 4 Setup test in \f(CW\*(C`wr_root//\*(C'\fR. If your configuration file layout depend on the target system, you will have to specify the path using \f(CW\*(C`setup\*(C'\fR parameter: .Sp .Vb 7 \& setup => { \& \*(Aqfile_name_in_examples_dir\*(Aq => { \& \*(Aqdarwin\*(Aq => \*(Aq/etc/foo\*(Aq, # macosx \& \*(Aqdefault\*(Aq => \*(Aq/etc/bar\*(Aq # others \& }, \& \*(Aqanother_file_in_examples_dir\*(Aq => $computed_path \& } .Ve .IP "\(bu" 4 Create configuration instance, load config data and check its validity. Use \&\f(CW\*(C`load_check => \*(Aqno\*(Aq\*(C'\fR if your file is not valid. .IP "\(bu" 4 Check for config data warning. You should pass the list of expected warnings. E.g. .Sp .Vb 1 \& load_warnings => [ qr/Missing/, (qr/deprecated/) x 3 , ], .Ve .Sp Use an empty array_ref to masks load warnings. .IP "\(bu" 4 Optionally load configuration data. You should design this config data to suppress any error or warning mentioned above. E.g: .Sp .Vb 1 \& load => \*(Aqbinary:seaview Synopsis="multiplatform interface for sequence alignment"\*(Aq, .Ve .IP "\(bu" 4 Optionally, call apply_fixes: .Sp .Vb 1 \& apply_fix => 1, .Ve .IP "\(bu" 4 Call dump_tree to check the validity of the data. Use \f(CW\*(C`dump_errors\*(C'\fR if you expect issues: .Sp .Vb 5 \& dump_errors => [ \& # the issues the fix that will be applied \& qr/mandatory/ => \*(AqFiles:"*" Copyright:0="(c) foobar"\*(Aq, \& qr/mandatory/ => \*(Aq License:FOO text="foo bar" ! Files:"*" License short_name="FOO" \*(Aq \& ], .Ve .IP "\(bu" 4 Likewise, specify any expected warnings (note the list must contain only \f(CW\*(C`qr\*(C'\fR stuff): .Sp .Vb 1 \& dump_warnings => [ (qr/deprecated/) x 3 ], .Ve .Sp You can tolerate any dump warning this way: .Sp .Vb 1 \& dump_warnings => undef , .Ve .IP "\(bu" 4 Run specific content check to verify that configuration data was retrieved correctly: .Sp .Vb 5 \& check => [ \& \*(Aqfs:/proc fs_spec\*(Aq, "proc" , \& \*(Aqfs:/proc fs_file\*(Aq, "/proc" , \& \*(Aqfs:/home fs_file\*(Aq, "/home", \& ], .Ve .Sp You can run check using different check modes (See \*(L"fetch( ... )\*(R" in Config::Model::Value) by passing a hash ref instead of a scalar : .Sp .Vb 4 \& check => [ \& \*(Aqsections:debian packages:0\*(Aq , { qw/mode layered value dpkg\-dev/}, \& \*(Aqsections:base packages:0\*(Aq, { qw/mode layered value gcc\-4.2\-base/}, \& ], .Ve .Sp The whole hash content (except \*(L"value\*(R") is passed to grab and fetch .IP "\(bu" 4 Verify annotation extracted from the configuration file comments: .Sp .Vb 4 \& verify_annotation => { \& \*(Aqsource Build\-Depends\*(Aq => "do NOT add libgtk2\-perl to build\-deps (see bug #554704)", \& \*(Aqsource Maintainer\*(Aq => "what a fine\enteam this one is", \& }, .Ve .IP "\(bu" 4 Write back the config data in \f(CW\*(C`wr_root//\*(C'\fR. 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. .Sp You can skip warning when writing back with: .Sp .Vb 1 \& no_warnings => 1, .Ve .IP "\(bu" 4 Check the content of the written files(s) with Test::File::Contents. Tests can be grouped in an array ref: .Sp .Vb 4 \& 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/ , \& } .Ve .IP "\(bu" 4 Check added or removed configuration files. If you expect changes, specify a subref to alter the file list: .Sp .Vb 5 \& file_check_sub => sub { \& my $list_ref = shift ; \& # file added during tests \& push @$list_ref, "/debian/source/format" ; \& }; .Ve .IP "\(bu" 4 Copy all config data from \f(CW\*(C`wr_root//\*(C'\fR to \f(CW\*(C`wr_root/\-w/\*(C'\fR. This steps is necessary to check that configuration written back has the same content as the original configuration. .IP "\(bu" 4 Create another configuration instance to read the conf file that was just copied (configuration data is checked.) .IP "\(bu" 4 You can skip the load check if the written file still contain errors (e.g. some errors were ignored and cannot be fixed) with \f(CW\*(C`load_check2 => \*(Aqno\*(Aq\*(C'\fR .IP "\(bu" 4 Compare data read from original data. .IP "\(bu" 4 Run specific content check on the \fBwritten\fR config file to verify that configuration data was written and retrieved correctly: .Sp .Vb 5 \& wr_check => { \& \*(Aqfs:/proc fs_spec\*(Aq, "proc" , \& \*(Aqfs:/proc fs_file\*(Aq, "/proc" , \& \*(Aqfs:/home fs_file\*(Aq, "/home", \& }, .Ve .Sp Like the \f(CW\*(C`check\*(C'\fR item explained above, you can run \f(CW\*(C`wr_check\*(C'\fR using different check modes. .SS "running the test" .IX Subsection "running the test" Run all tests: .PP .Vb 1 \& prove \-l t/model_test.t .Ve .PP By default, all tests are run on all models. .PP You can pass arguments to \f(CW\*(C`t/model_test.t\*(C'\fR: .IP "\(bu" 4 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. .Sp .Vb 2 \& # run with log and error traces \& prove \-lv t/model_test.t :: el .Ve .IP "\(bu" 4 The model name to tests. E.g.: .Sp .Vb 2 \& # run only fstab tests \& prove \-lv t/model_test.t :: x fstab .Ve .IP "\(bu" 4 The required subtest E.g.: .Sp .Vb 2 \& # run only fstab tests t0 \& prove \-lv t/model_test.t :: x fstab t0 .Ve .SH "Examples" .IX Header "Examples" .IP "\(bu" 4 LCDproc has a single configuration file: \&\f(CW\*(C`/etc/LCDd.conf\*(C'\fR. Here's LCDproc test layout and the test specification .IP "\(bu" 4 Dpkg packages are constructed from several files. These files are handled like configuration files by Config::Model::Dpkg. The test layout features test with multiple file in dpkg-examples . The test is specified in dpkg\-test\-conf.pl .IP "\(bu" 4 multistrap\-test\-conf.pl and multistrap-examples 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. .IP "\(bu" 4 backend\-shellvar\-test\-conf.pl is a more complex example showing how to test a backend. The test is done creating a dummy model within the test specification. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Config::Model .IP "\(bu" 4 Test::More .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2014 by Dominique Dumont. .PP This is free software, licensed under: .PP .Vb 1 \& The GNU Lesser General Public License, Version 2.1, February 1999 .Ve .SH "SUPPORT" .IX Header "SUPPORT" .SS "Websites" .IX Subsection "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. .IP "\(bu" 4 MetaCPAN .Sp A modern, open-source \s-1CPAN\s0 search engine, useful to view \s-1POD\s0 in \s-1HTML\s0 format. .Sp .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp The default \s-1CPAN\s0 search engine, useful to view \s-1POD\s0 in \s-1HTML\s0 format. .Sp .IP "\(bu" 4 \&\s-1RT: CPAN\s0's Bug Tracker .Sp The \s-1RT \s0( Request Tracker ) website is the default bug/issue tracking system for \s-1CPAN.\s0 .Sp .IP "\(bu" 4 AnnoCPAN .Sp The AnnoCPAN is a website that allows community annotations of Perl module documentation. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp The \s-1CPAN\s0 Ratings is a website that allows community ratings and reviews of Perl modules. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Forum .Sp The \s-1CPAN\s0 Forum is a web forum for discussing Perl modules. .Sp .IP "\(bu" 4 \&\s-1CPANTS\s0 .Sp The \s-1CPANTS\s0 is a website that analyzes the Kwalitee ( code metrics ) of a distribution. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers .Sp The \s-1CPAN\s0 Testers is a network of smokers who run automated tests on uploaded \s-1CPAN\s0 distributions. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers Matrix .Sp The \s-1CPAN\s0 Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers Dependencies .Sp The \s-1CPAN\s0 Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. .Sp .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests by email to \f(CW\*(C`bug\-config\-model\-tester at rt.cpan.org\*(C'\fR, or through the web interface at . You will be automatically notified of any progress on the request by the system. .SS "Source Code" .IX Subsection "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 :) .PP .PP .Vb 1 \& git clone git://github.com/dod38fr/config\-model\-tester.git .Ve