in reply to Running tests on modules generated by Module::Starter still in /lib directory

How, and from which directory are you running your tests?

make test from within the distribution's root directory will Do The Right Thing. If you are running individual tests (eg: perl t/00-load.t), you need to first do a make install first. In the distribution root dir:

perl Makefile.PL make make test make install

Thereafter, if you don't make any changes to your Makefile.PL and want to run test files individually, simply make install after any change to your library (.pm file):

make install perl t/xx-frobnicate_tests.t

On a side note, each to their own on how they use module-starter, but I like to have the software configure as much as possible for me:

module-starter --module=My::Module \ --author="Steve Bertrand" \ --email=my@email.com \ --license=perl

At the very end of the help screen (just type "module-starter" without any arguments), there's an example if you forget (less the license option):

Example: module-starter --module=Foo::Bar,Foo::Bat \ --author="Andy Lester" --email=andy@petdance.com

Replies are listed 'Best First'.
Re^2: Running tests on modules generated by Module::Starter still in /lib directory
by haukex (Archbishop) on Feb 12, 2017 at 18:32 UTC

    Hi stevieb,

    If you are running individual tests (eg: perl t/00-load.t), you need to first do a make install first.

    make install should not be necessary to run tests, otherwise you've got a chicken/egg problem; perl -Ilib t/foo.t should be enough. Update: or prove -l t/foo.t.

    Regards,
    -- Hauke D

      You're right. I should have said "you *can* do a make install first". It's just a habit for me to do it this way.

        Hi stevieb,

        I should have said "you *can* do a make install first". It's just a habit for me to do it this way.

        I understand, and on the system of a developer who knows what they're doing this is probably acceptable, but after thinking about it a bit more, I have to say that as general advice, I would strongly recommend against make install for running tests. Who knows how other peoples' systems are set up (not everyone uses perlbrew or local::lib - someone might even get the idea to do sudo make install and muck up their system Perl), and at the very least uninstalling a broken Perl module or reverting it to a previous state is no fun at all. The whole point of tests is that one should run them to find problems before install :-)

        Regards,
        -- Hauke D

Re^2: Running tests on modules generated by Module::Starter still in /lib directory
by nysus (Parson) on Feb 12, 2017 at 18:35 UTC

    I am running the tests using a nifty keystroke shortcut ;t from within VIM when editing MyModule/lib/MyModule.pm. The shortcut triggers a VIM script which automatically runs the tests found at MyModule/*.t.

    So if I follow you correctly, are you saying I should run make install before I run every test? Is that something I should automate as part of the VIM script. Please bear with me, I never got the whole Makefile thing (did I tell you I was lame?)

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      Hi nysus,

      Did you try what choroba suggested? The way I run my tests for all my (pure-Perl) modules is prove -l from the command line from the base directory of the module. make should not be necessary unless you've got XS code that you need to compile, but even then, prove should be able to run all the tests (AFAIK you need prove -lb in that case).

      Hope this helps,
      -- Hauke D

        I'm attempting to automate the process and run the tests from VIM with a shortcut command. See my comment further down for details.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

      What exactly does the Vim shortcut run when executed? fwiw, tests should reside in MyModule/t/*.t. Also, you never specified which directory you are in when running the test command. You should be in the distribution's root dir.

      You don't need to make install to run tests. make test is a common way to run your suite (all tests), and it automatically knows where to look for your libraries. You only need to do things differently when running individual test files. make install works, but as haukex stated in an earlier reply, it isn't necessary. Both of the below will work all the same, without installing (granted you're in the dist's root dir as I've said):

      "perl -Ilib t/foo.t should be enough. Update: or prove -l t/foo.t."

        It's a nifty little VIM script in that goes in .vimrc file:

        "=====[ Run a Perl module's test suite ]========================= let g:PerlTests_program = 'perltests' " ...What to call let g:PerlTests_search_height = 5 " ...How far up to searc +h let g:PerlTests_test_dir = '/t' " ...Where to look for t +ests augroup Perl_Tests autocmd! autocmd BufEnter *.p[lm] nmap <buffer> ;t :call RunPerlTests()<CR +> autocmd BufEnter *.t nmap <buffer> ;t :call RunPerlTests()<CR +> augroup END function! RunPerlTests () " Start in the current directory... let dir = expand('%:h') " Walk up through parent directories, looking for a test directory +... for n in range(g:PerlTests_search_height) " When found... if isdirectory(dir . g:PerlTests_test_dir) " Go there... silent exec 'cd ' . dir " Run the tests... exec ':!' . g:PerlTests_program " Return to the previous directory... silent cd - return endif " Otherwise, keep looking up the directory tree... let dir = dir . '/..' endfor " If not found, report the failure... echohl WarningMsg echomsg "Couldn't find a suitable" g:PerlTests_test_dir '(tried' g +:PerlTests_search_height 'levels up)' echohl None endfunction

        The VIM script makes use of a perltests script in ~/bin which finds the tests and executes them via TAP::Harness which itself can take a lib argument when creating a new object. So it seems like I should be able to put something in there to make this work. The beauty of it is I can do ;t keystroke and run tests.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks