Dominique Dumont > Config-Model-Tester > Config::Model::Tester



Annotate this POD


View/Report Bugs
Module Version: 2.052   Source  


Config::Model::Tester - Test framework for Config::Model


version 2.052


 # in t/model_test.t
 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) ;


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

Simple test file layout

 |-- model_test.t
 \-- model_tests.d
     |--   # test specification
     \-- lcdd-examples
         |-- t0              # test case t0
         \-- LCDD-0.5.5      # test case for older LCDproc

In the example above, we have 1 model to test: lcdd and 2 tests cases.

Test specification is written in file. Test cases are plain files in lcdd-examples. will contain instructions so that each file will be used as a /etc/LCDd.conf file during each test case. can contain specifications for more test case. Each test case will require a new file in lcdd-examples directory.

See "Examples" for a link to the actual LCDproc model tests

Test file layout for multi-file configuration

When a configuration is spread over several files, test examples must be provided in sub-directories:

 \--         # test specification
 \-- dpkg-examples
     \-- libversion            # example subdir
         \-- debian            # directory for one test case
             |-- changelog
             |-- compat
             |-- control
             |-- copyright
             |-- rules
             |-- source
             |   \-- format
             \-- watch

In the example above, the test specification is written in Dpkg layout requires several files per test case. will contain instruction so that each directory under dpkg-examples will be used.

See "Examples" for a link to the (many) Dpkg model tests

Test file layout depending on system

 |-- ssh-examples
     \-- basic
         |-- system_ssh_config
         \-- user_ssh_config

In this example, the layout of the configuration files depend on the system. For instance, system wide ssh_config is stored in /etc/ssh on Linux, and directly in /etc on MacOS. will specify the target path of each file. I.e.:

 $home_for_test = $^O eq 'darwin' ? '/Users/joe'
                :                   '/home/joe' ;

 # ...

      setup => {
        'system_ssh_config' => {
            'darwin' => '/etc/ssh_config',
            'default' => '/etc/ssh/ssh_config',
        'user_ssh_config' => "$home_for_test/.ssh/config"

See the actual Ssh and Sshd model tests

Basic test specification

Each model test is specified in <model> This file contains a set of global variable. (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
 #$conf_dir = "etc" ;
 # home directory for this test
 $home_for_test = '/home/joe' ;

Here, t0 file will be copied in wr_root/test-t0/etc/fstab.

 # config model name to test
 $model_to_test = "Fstab" ;

 # list of tests
 @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 no_warnings => 1. On the other hand, you may also want to check for warnings specifid to your model. In this case, you should avoid specifying no_warnings here and use the more specify warning tests or warning filters mentioned below.

See actual fstab test.

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 $model variable. See for instance the layer test or the test for shellvar backend.

Test specification with arbitrary file names

In some models (e.g. Multistrap, the config file is chosen by the user. In this case, the file name must be specified for each tests case:

 $model_to_test = "Multistrap";

 @tests = (
        name        => 'arm',
        config_file => '/home/foo/my_arm.conf',
        check       => {},

See actual multistrap test.

Test scenario

Each subtest follow a sequence explained below. Each step of this sequence may be altered by adding specification in the test case:

running the test

Run all tests:

 prove -l t/model_test.t

By default, all tests are run on all models.

You can pass arguments to t/model_test.t:

Examples ^



Dominique Dumont


This software is Copyright (c) 2015 by Dominique Dumont.

This is free software, licensed under:

  The GNU Lesser General Public License, Version 2.1, February 1999



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.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-config-model-tester at, or through the web interface at You will be automatically notified of any progress on the request by the system.

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 :)

  git clone git://
syntax highlighting: