Test::Whitespaces - test source code for errors in whitespaces


version 1.2.1


In xt/whitespaces.t (read FAQ section to find out why it is recommended to place test file in xt directory):

    use Test::Whitespaces {

        # Directories to check all the files from
        dirs => [


The test will check all the files specified by parameters. It will pretty print all the errors, so it is easy to undestand where is the problem.


This module is intend to solve one simple task: to make sure that your source code don't have problems with whitespaces.

This module checks that all the rules are followed.

  • Each line ends with "\n" (including the last line)

  • For new lines "\n" is used (not "\r\n")

  • There are no ending spaces on the lines

  • 4 spaces are used instead of tabs

  • No empty lines in the end of file

This module don't export any subroutines, you only need to write a test file and write there:

    use Test::Whitespaces { dirs => ['lib'] };

Here is the full list of all avaliable parameters:

    use Test::Whitespaces {

        # Directories to check all the files from
        dirs => [ 'lib', 'bin', 't' ],

        # Files to be checekd (if you don't need to check the whole dir)
        files => [ 'README' ],

        # Files that matches any of this regexp will not be checked
        ignore => [ qr{\.bak$} ],


This module does not check the files that are stored in the version control system directories (you remember, that .git, .svn and friends).

This module is shiped with 2 scripts. `test_whitespaces` to easy check files and directories and `whiter` to fix all that errors.

And by the way, this module don't have any dependencies, but Perl. It does not matter much, but it is nice =)


Why not to use perltidy instead of this module?

Perltidy is a great thing. It fixes some whitespace problems in the Perl source code. But sometimes you don't need the whole perltidy possibilities, but only want to make your whitespaces accurate. Adding Test::Whitespaces to the project affects less than adding perltidy. And with Test::Whitespaces you can test and fix not only the Perl source code, but any texts. For example, you can make sure that you javasript code has no problems with whitespaces or you can fix your text files.

Why there is no default values?

The idea behind this test is to make delelopers work simplier. There are a lot of things a developer should remember. I don't want to ask developers to remember the default values of this module. The person writing test should write the exact list of thing to check, but such precise writing simplifies the work of person who reads the code.

What Perl version do I need to use Test::Whitespaces?

This module works with Perl 5.8.0 and above. In Perl 5.8.0 the better Unicode support was implemented that is needed for this module.

What is the logic for version numbering?

Test::Whitespaces version numbers uses Semantic Versioning standart. Please visit to find out all about this great thing.

I recomend create test file as xt/whitespaces.t, not t/whitespaces.t. Directory `t` stores all the tests that will be run when the user installs module from CPAN. If you add testing whitespaces of the module to the `t` directory you will need to add dependency Test::Whitespaces to your module. But checking whitespaces does matter for the module author, and does not matter for the module user. I think that we should simplify module user life and not to oblige the user to install Test::Whitespaces. Directory `xt` is for extened tests. That tests are run by the module author, but are not run when the user installs module from CPAN. So xt directory is the perfect place to store file that checks whitespaces.


If this module is not what you need, you may try to look to these modules (but I hope you will prefer to use Test::Whitespaces):


  • Rob Hoelz (RHOELZ)

  • Michael Jemmeson (MJEMMESON)


The source code for this module and scripts is hosted on GitHub


Please report any bugs or feature requests in GitHub Issues


Ivan Bessarabov <>


This software is copyright (c) 2013 by Ivan Bessarabov.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.