Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

"including" perl scripts on the fly and leaving them controlled

by demoralizer (Beadle)
on Mar 18, 2014 at 17:20 UTC ( [id://1078823]=perlquestion: print w/replies, xml ) Need Help??

demoralizer has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

we've a test framework written in perl and I'm not sure if the implementation is done really wisely.

There is a general test runner that opens a simple text file that includes all the perl test files that have to be executed. This file is read and put on a test case stack. That makes it easy to include further tests during run time what is needed in certain cases, e.g. if I press ctrl+c the current test case will be stoppend and another test case that shows an input line is inserted on stack for beeing executed next.

Furthermore there are several helper packages that make implementing test cases very easy. The test runner and each test case "uses" all these packages.

In the helper packages there is also a hash that is used by all test cases where variables can be defined that can be used and modified by the tests

Currently I'm using "do" to execute each test case inside the test runner environment. Otherwise the test wouldn't be able to handle e.g. those common defines and other things that should be seen by the test runner.

Each test can consist of several test procedures that each can fail and pass and in critical cases can make the whole test or even the test runner beeing stopped

All test cases run in the same package "TESTCASE" that is undefined after a test case has been executed. So test cases don't come into conflict with others but e.g. all see the same HELPER package.

Here is some (pseudo) code example to make it a little bit clearer:
testrunner.pl:

#!/usr/bin/perl use strict; use helper; #... open(MYFILE, 'testcases.txt'); @HELPER::testCaseStack = <MYFILE>; close(MYFILE); foreach my $testCase (@testCaseStack) { undef %TESTCASE::; ##(1)## my $result = do($testCase); ##(2)## # do sth. with the result here next; EXIT_TESTCASE: ##(3)## # do sth. here next; EXIT_TESTRUNNER: ##(3)## # do sth. here last; }
helper.pm:
#!/usr/bin/perl package HELPER; our @testCaseStack = (); our $executedTestProcedures = 0; sub handleResult($) { my ($result) = @_; # do some default outputs... $executedTestProcedures++; leaveTestRunner() if ($result>2); leaveTestCase() if ($result>1); } sub leaveTestcase { goto EXIT_TESTCASE; ##(3)## } sub leaveTestRunner { goto EXIT_TESTCASE; ##(3)## } 1;
testcase1.pl:
#!/usr/bin/perl -w package TESTCASE; ##(1)## use HELPER; # test procedure 1 handleResult(0); # test procedure 2 handleResult(1); push(@HELPER::testCaseStack, "anotherTest.pl"); # test procedure 3 handleResult(2); return 0;

Puh, a lot of stuff so far... I hope it's not too much for one issue but I think in that way my problem becomes clearer.

Here are my questions:

1) does this undef at ##(1)## makes sense or do I understand here sth. wrong?

2) is "do" at ##(2)## the best option here or are there better ways doing this?

3) to exit the test case from a default function it's necessary to use "goto" at ##(3)## because a simple return from HELPER::handleResult will go back to the testcase and not into the test runner. But meanwhile "goto" is deprecated and I always get a warning what is not nice, any suggestions here?

4) does this "goto" at ##(3)## produces some lost memory? And if so what can be done against?

5) is there any easy possibility to find most memory consuming variables? Watching certain array/hash variables is not the problem but I have to know which one to be watched, is there any possibility to show those variables consuming most memory?

By the way it's only sample code, the real test runner is much larger and many more different results are handled but this should show my problems

Thanks a lot in advance!
demoralizer

Replies are listed 'Best First'.
Re: "including" perl scripts on the fly and leaving them controlled
by Bloodnok (Vicar) on Mar 18, 2014 at 17:43 UTC
    I know it's not quite what you asked, but have you considered Test::Class - that would, uotwardly at least, appear to meet your requirements.

    A user level that continues to overstate my experience :-))
      thanks for your answer but there are already a lot of test cases. Switching over to anything else will cause each test case to be changed with no effort because the test runner is working fine excepting some smaller points what's the reason for my questions :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1078823]
Approved by Bloodnok
Front-paged by Bloodnok
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-23 06:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found