Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Auto-compile checking??? WTF?

by jeffa (Bishop)
on Apr 15, 2016 at 18:04 UTC ( #1160553=note: print w/replies, xml ) Need Help??


in reply to Auto-compile checking??? WTF?

I solve this problem by writing unit tests. I start a Perl project with Module::Starter which provides the basis for your unit tests.

jeffa@jeffa:~/code$ module-starter --module=Foo::Bar --author=me --ema +il=me@here.com Added to MANIFEST: Changes Added to MANIFEST: ignore.txt Added to MANIFEST: lib/Foo/Bar.pm Added to MANIFEST: Makefile.PL Added to MANIFEST: MANIFEST Added to MANIFEST: README Added to MANIFEST: t/00-load.t Added to MANIFEST: t/manifest.t Added to MANIFEST: t/pod-coverage.t Added to MANIFEST: t/pod.t Added to MANIFEST: xt/boilerplate.t Created starter directories and files jeffa@jeffa:~/code$ pushd Foo-Bar/ ~/code/Foo-Bar ~/code jeffa@jeffa:~/code/Foo-Bar$ prove -lr ./t/00-load.t ....... 1/? # Testing Foo::Bar 0.01, Perl 5.022001 ./t/00-load.t ....... ok ./t/manifest.t ...... skipped: Author tests not required for installat +ion ./t/pod-coverage.t .. skipped: Author tests not required for installat +ion ./t/pod.t ........... skipped: Author tests not required for installat +ion ./xt/boilerplate.t .. ok All tests successful. Files=5, Tests=4, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.02 cusr + 0.01 csys = 0.06 CPU) Result: PASS
In my opinion, this is far better than a mere perl -c because you now have a framework with which to add finer grain tests for your code. Replace watch with a service like Jenkins or https://travis-ci.org and increase your available options.

For what it is worth, i have been using vim exclusively for over 15 years now. Good quality, maintained unit tests are more valuable to me than an IDE (and i honestly consider IDEs to be crutches).

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Auto-compile checking??? WTF?
by nysus (Vicar) on Apr 15, 2016 at 18:34 UTC

    Yes, I am definitely interested in exploring unit testing. I am starting to get comfortable with Moose and I was thinking that learning about unit testing would be the next major skill I should learn. Thanks for pointing out these tools to me because I don't know where to begin. Do you know any good basic perl-related tutorials regarding unit testing that might help me get up to speed fast?

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

      Unit testing is one of the most very useful tools of a good developer (any language). Before, or as you code, you simply write code that uses your software just like a user would (while throwing in all the edge cases you can think of) to make sure your code is doing the right thing.

      You write these tests as you go, so the more you code, you run your tests to ensure you haven't broken something you coded earlier.

      See Test::More. That'll get you well on your way. Then, go to MetaCPAN and browse to the t/ directory of random modules and read the unit tests. Some modules have clear tests with good descriptions, other modules don't have any tests.

      The most important thing about writing tests is write them now. Not after you get those two new features added, not next week, they should be part of your coding regimen. Doing it this way helps make sure code you've already written is to the best of your ability not doing something wrong due to future changes.

        I suppos I kind of do testing already by running my executing have finished code and looking to see if the results are as expected and maybe throwing in a warning if they aren't. Admittedly, this testing method is very crude, however, and not very reliable. Thanks for the advice.

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

      Getting up to speed fast will be an accomplishment. I am hard pressed to find a good, modern tutorial for unit testing with Perl, but i did run across this Youtube video and i thought the first 10 minutes are actually pretty nice. The final 20 seem to cover code coverage which might be more than you need, right now. I find code coverage to be more useful for legacy code you have inherited, but it can greatly help you ensure that all areas of your new code is being tested as well.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
      You posted a lot of vi centric questions lately, would you mind marking them consistently?

      I for instance try to mark emacs stuff with a leading [emacs] in the title.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        or just "vim" or "(vim)" :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1160553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2019-06-19 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (84 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!