in reply to Automation of testing of Moose class structure

"... able to write a class definition into some file and run a script that would automatically generate the Moose class and the tests for me ..."

How would you tell the definition what methods to call and how would you pass the necessary arguments to them? How would this process know what values to expect?

Just write the tests and be done with it. Don't worry about DRY with unit tests. The more repetitive and explicit the better. Leave clever out of your unit tests -- try to avoid loops as much as possible. Each test should be able to comment out with a simple # -- loops make you code in exceptions. Unit tests should be KISS - keep it simple and stupid. Study the unit tests in your favorite CPAN distributions: some are great and some are not so good and some are downright embarrassing.

Make your unit tests double as working examples of your code. Simple tests. Simple one line examples.

  • Comment on Re: Automation of testing of Moose class structure

Replies are listed 'Best First'.
Re^2: Automation of testing of Moose class structure
by nysus (Parson) on Feb 10, 2017 at 22:21 UTC

    It would just set up the skeleton based on variables passed to it. and print out out something like:

    use Moose; use this; ust that; has this => (is => 'ro', isa => 'that'); sub do_this { my $self = shift; confess 'not implemented'; }
    The config file would look something like this:
    $use = ['Moose, 'this', 'that';] $attributes = {name => 'this', {is => 'ro', isa => 'that'}; $methods = ['do this'];

    Maybe a templating system is better with some kind of vim plugin in. I just don't know. I'm sure this kind of thing has been done before. I'm not trying to reinvent the wheel just trying to figure out which wheel to use for this task. All I know is I'm bored stiff typing out the same thing over and over and fixing dumb typos which eat up a crap load of time. I'd rather just focus on constructing the building instead of setting up scaffolding.

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

Re^2: Automation of testing of Moose class structure
by nysus (Parson) on Feb 10, 2017 at 22:39 UTC

    Had to look up DRY. Thanks. Good advice, but I'm not sure it applies to something as mundane as checking that I don't accidentally break the code when editing. Do I really want the pain of writing 3 or 4 lines of code for every single attribute to make sure its parameters for it weren't accidentally changed by me?

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