Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Testing my tests

by szabgab (Priest)
on Feb 26, 2017 at 16:17 UTC ( #1182886=note: print w/replies, xml ) Need Help??


in reply to Re: Testing my tests
in thread Testing my tests (mutation testing)

No. I would like to introspect and change my module or application and then run the unchanged tests again. (Updated the original post too with this clarification.)

Replies are listed 'Best First'.
Re^3: Testing my tests
by stevieb (Canon) on Feb 26, 2017 at 16:33 UTC

    What about running the tests, then modifying the sub, then running again? Here's a quickly thrown together example (in this example I simply mock out the whole function) to see if this is more along the lines of what you're looking for:

    package Package; { sub perform { return $_[0] + $_[1]; } } package main; { use Mock::Sub; use Test::More; tests(); my $m = Mock::Sub->new; my $changed = $m->mock('Package::perform'); $changed->return_value($_[0] - $_[1]); tests(); done_testing(); sub tests { is Package::perform(5, 5), 10, "5 + 5 = 10"; } }

    Output:

    ok 1 - 5 + 5 = 10 not ok 2 - 5 + 5 = 10 # Failed test '5 + 5 = 10' # at pack.pl line 24. # got: '0' # expected: '10' 1..2 # Looks like you failed 1 test of 2.

    If this example is more along the lines you're after (modifying code on the fly), my Devel::Examine::Subs is designed to alter code within a file (so say you wanted to modify a single line in a single sub within a package, you could (then revert it back), and I could write a mock up example of what it may look like. But perhaps I'm way off here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-08-08 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?