perlcpandist-zilla

Using Dist::Zilla dist.ini how can I have files that I only use for testing?


In a Dist::Zilla-based distribution I would like to have some files that are only used for testing, but do not get installed. These are mockup libs that aren't needed for runtime.

How do I do that?


Solution

  • CPAN distributions never install the t and xt directories. You can put your tests and your mock libs into t.

    As an example, take my module MooseX::LocalAttribute. In the dist, there is a t/, a t/lib and an xt/.

    If you install this using cpanm -l into a local lib dir, you will see there are no tests installed. This happens automatically. It's just how CPAN works.

    $ cpanm -l mylib MooseX::LocalAttribute
    --> Working on MooseX::LocalAttribute
    Fetching http://www.cpan.org/authors/id/S/SI/SIMBABQUE/MooseX-LocalAttribute-0.05.tar.gz ... OK
    Configuring MooseX-LocalAttribute-0.05 ... OK
    Building and testing MooseX-LocalAttribute-0.05 ... OK
    Successfully installed MooseX-LocalAttribute-0.05
    1 distribution installed
    
    $ tree mylib
    mylib
    ├── lib
    │   └── perl5
    │       ├── MooseX
    │       │   └── LocalAttribute.pm
    │       └── x86_64-linux
    │           ├── auto
    │           │   └── MooseX
    │           │       └── LocalAttribute
    │           └── perllocal.pod
    └── man
        └── man3
            └── MooseX::LocalAttribute.3
    
    9 directories, 3 files
    

    Note that as long as stuff is in t/lib (or anywhere under t/, really), you do not have to hide the package names from the PAUSE indexer. It's smart enough to not find it.