prove Command in Linux



The prove command in Linux runs test scripts through the TAP (Test Anything Protocol) format. It is a Perl-based utility used to execute and summarize results from automated test suites, especially in environments involving Perl or related ecosystems.

The prove command runs tests, shows results clearly, supports faster runs with parallel tests and works well in automated setups.

Table of Contents

Here is a comprehensive guide to the options available with the prove command in Linux −

Syntax of prove Command

The syntax ofthe prove command in Linux is as follows −

prove [options] [file/directory]

In the above syntax, the [options] field is used to specify various options to control how tests are run. The [file] field is used to specify the path to a specific test file. The [directory] is used to specify the path to a directory containing test scripts. By default, it runs all .t files in the t/ directory.

prove Command Options

The options of the prove command are listed below −

Flag Option Description
-v --verbose Print all test lines
-l --lib Add lib to the path for your tests (-Ilib)
-b --blib Add blib/lib and blib/arch to the path for your tests
-s --shuffle Run the tests in random order
-c --color Colored test output (default)
--nocolor Do not color test output
--count Show the X/Y test count when not verbose (default)
--nocount Disable the X/Y test count
-D --dry Dry run (Show test that would have run)
--ext Set the extension for tests (default .t)
-f --failures Show failed tests
-o --comments Show comments
--ignore-exit Ignore exit status from test scripts
-m --merge Merge test scripts STDERR with their STDOUT
-r --recurse Recursively descend into directories
--reverse Run the tests in reverse order
-q --quiet Suppress some test output while running tests
-Q --QUIET Only print summary results
-p --parse Show full list of TAP parse errors, if any
--directives Only show results with TODO or SKIP directives
--timer Print elapsed time after each test
--normalize Normalize TAP output in verbose output
-T Enable tainting checks
-t Enable tainting warnings
-W Enable fatal warnings
-w Enable warnings
-?, -h --help Display this help
-H --man Longer manpage for prove
--norc Don't process default .proverc
-I Library paths to include
-P Load plugin (searches App::Prove::Plugin::*)
-M Load a module
-e --exec Interpreter to run the tests ('' for compiled tests)
--harness Define test harness to use (See TAP::Harness)
--formatter Result formatter to use (See TAP::Harness)
-a --archive Store the resulting TAP in an archive file
-j N --jobs N Run N test jobs in parallel (try 9)
--state=opts Control prove command's persistent state
--rc=rcfile Process options from rcfile

Examples of prove Command in Linux

In this section, the usage of the Linux prove command will be discussed with examples −

Running All Tests

To run all the test files in the t/ directory, execute the prove command without any option −

prove
prove Command in Linux1

The t/ directory is a common convention in many Perl-based projects where test scripts are stored. It typically holds .t files, which are Perl test scripts written in the Test Anything Protocol (TAP) format.

Running a Specific Test File

To run a specific test file, use the prove command with the path of the test file −

prove t/script.t
prove Command in Linux2

Running a Specific Test File with Verbose Output

To run a specific test file with verbose output, use the -v or --verbose options −

prove -v t/script.t
prove Command in Linux3

The above command will print all the test lines.

Running Tests in Parallel

To run test files in parallel, use the -j or --jobs option −

prove -j 3 t/

The above command executes the tests in the t/ directory using 3 parallel processes.

Dry Running a Test File

To dry run a test file, use the -D or --dry option with the prove command −

prove -D t/script.t

The above command shows which tests would run, but does not run them (dry run).

Displaying only Failed Tests

To display only the failed test in a specified test file, use the -f or --failures option −

prove -f t/script.t

Running Tests in Reverse Order

To run the tests in the reverse order, use the -r or --reverse option −

prove -r t/

The above command runs the test scripts in reverse order, meaning the last test script will be run first, and the first one will be run last.

Displaying Elapsed Time after Test

To display elapsed time after the test, use the --timer option with the prove command −

prove --timer t/script.t
prove Command in Linux4

Suppressing Test Output

To suppress the test output, use the -q or --quiet option −

prove -q t/script.t

It is useful if the prove command is being used in the scripts.

To display the summary result only, use the -Q or --QUIET option −

prove -Q t/script.t

Displaying Output without Color

By default, the output of the prove command is colored, to remove the colors, use the --nocolor option −

prove --nocolor t/script.t
prove Command in Linux5

Displaying Usage Help

To display the usage help of the prove command, use the -?, -h or --help option −

prove -h

To get the detailed help, use the -H or --man option −

prove -H

Conclusion

The prove command in Linux is a handy tool for Perl developers to run automated test scripts, particularly in Perl-based environments. It supports various options for controlling the execution and output of tests, such as running tests in parallel, displaying verbose results, and suppressing output when necessary. Additionally, it offers features like running tests in reverse order, displaying elapsed time, and even performing dry runs.

Advertisements