Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run perl xt tests?

Lately the new great thing appeared in the Perl world. For a long time in the library package there was folder t that contained tests. Now there is one more folder xt that contains author test. The xt tests are not needed in the process of the library installation, but it helps library autor to make sure that the code is great.

There is a spript prove that ships with the Perl that runs test. If you run prove without parameters all tests from the folder 't' will be executed. If you want to run both t and xt test you should write:

prove xt t

It it possible to add to the configuration file .proverc file that parameters (xt t). Then when you run prove without parameters they will be taken from file and tests in the both folders will be executed.

But here comes the problem. In case you have xt t in your .proverc file you can't just pass the filename as the parameter to the prove. If you say prove t/00-load.t it will execute all the tests in both folders, because it takes parameters from config file. You need to write prove --norc t/00-load.t. But this seems ugly.

How do you run your xt tests?

like image 205
bessarabov Avatar asked Feb 08 '13 10:02

bessarabov


People also ask

How do I run a unit test in Perl?

Unit testing in Perl couldn't be easier. You run unit tests just like normal code (e.g., perl MYFILE ). There are just two functions you need to remember: is(EXPERIMENTAL_VALUE, EXPECTED_VALUE, OPTIONAL_MESSAGE)

How do I create a test case in Perl?

1. Write Test Cases with Test::Simple. You can write test cases in perl using the perl Test::Simple module which has the basic functionality for testing. Before proceed to writing test case, first you need to plan the number of test cases and then the actual test cases.


2 Answers

Author tests should not be run by default - you don't want a CPAN install to fail because some of your POD syntax is wrong. They should ideally be run on release, when specifically requested.

See http://elliotlovesperl.com/2009/11/24/explicitly-running-author-tests/ for a method involving Module::Build.

I sometimes use Dist::Zilla, which handles author tests by default.

like image 101
rjh Avatar answered Nov 15 '22 11:11

rjh


I add

package MY;
sub depend {
  "
xtest :: test
    \$(MAKE) test TEST_FILES=xt/*.t
"
}

to Makefile.PL. This runs the normals tests, and then the xt tests.

like image 39
rurban Avatar answered Nov 15 '22 12:11

rurban