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

Greetings wise monks

I come to you as a man on his last resort.

I am attempting to develop an automated test scripting language for a certain IT company to automate their whole test process.

My problem is that I need my scripters to be able to identify areas of the script that may or may not be run, but in either situation, my language must output something to the screen in order for a test auditor to decide what has and hasn't been run, and why. I think an example makes things clearer. This is what I am after

startTestScript(); step a; step b; testBlock("Block1",checkRunningOnWindows){ step c; }

So in this example, if we're on windows platform step c will be executed and the script will continue. However if we're on linux, the script should output "Not runnin step c as checkRunningOnWindows failed".

Test and Test::More are very close to what I want, but insufficient becuase it skips tests but not actual code. An if..else construct is deemed to complicated for my target users (don't ask!!). A translator/parser works well, but again if the traceability between what is written and what is run is lost, my target users will not be able to debug.

Has anyone ever see, heard of or thought about any such system or solution? I have tried a couple of techniques, none of which have been too fruitful. I would love to know what you monks come up with

Many thanks

Joe

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: Test Blocks and skipping
by djp (Hermit) on Oct 17, 2006 at 03:31 UTC
    Hi Joe, does this satisfy your requirement?
    $ cat joew.t #!/opt/local/bin/perl -w use strict; use warnings; use Test::More tests => 3; ok(0==0, '0==0'); SKIP: { skip "Skipping odd tests", 1 unless 0; ok(1==1, '1==1'); } ok(2==2, '2==2'); $ perl joew.t 1..3 ok 1 - 0==0 ok 2 # skip Skipping odd tests ok 3 - 2==2 $ prove joew.t joew....ok 1/3 skipped: Skipping odd tests All tests successful, 1 subtest skipped. Files=1, Tests=3, 1 wallclock secs ( 0.12 cusr + 0.06 csys = 0.18 C +PU)
    David
Re: Test Blocks and skipping
by adrianh (Chancellor) on Oct 17, 2006 at 10:09 UTC
    Test and Test::More are very close to what I want, but insufficient becuase it skips tests but not actual code.

    They skip the tests by skipping the code that runs those tests - so you should be able to use them (or the same technique - using next to exit a block from within a subroutine - evil but it works).

Re: Test Blocks and skipping
by doowah2004 (Monk) on Oct 16, 2006 at 21:42 UTC
    I am sure that I do not understand you question fully, but it sounds like the use of labels and goto statements might help. If so see: perldoc goto
    If not, sorry...but good luck in your search, and I am sure that some of the much wiser monks will have suggestions.

      Not sure how this would help.

      Effectively what I want is for this
      step a; testBlock("Block1",checkSomething) step b; }
      to work like
      step a; if(checkSomething){ step b; }else{ print "Not running step b as checkSomething failed" }
      Hope that makes things clearer
        So what you want to do is invent a programming language, and make it work by parsing it then translating it to Perl. If the language is simple, that shouldn't be that hard to do.

        However you want to make it not look like a programming language. And you want it to be capable. And you don't want to let your users know that they are actually programming. Oh, and you want to be able to extend the language easily.

        That's a hard problem. And it is mostly a psychological one. What I'd suggest doing is a lot of whiteboarding. Write up samples of what people should write and what it would do. Go over it with users. When you have something mutually acceptable, then write a filter to turn that into Perl code. (Filter::Simple may help.)

        You can then make it extensible by having some command in your new language that loads a Perl module that adds new functions. :-)

        step a; testBlock("Block1",checkSomething) step b; }

        What does the unbalanced curly right bracket mean?

        The closest I can whip up - with a bit of syntax change - is

        sub checkSomething { 0 } sub testBlock (**&) { my ($block,$cond,$sub) = @_; my $test = &{$cond}; $test ? &$sub : warn "not running code for $block since '$cond' fa +iled \n"; } testBlock "Block1", 'checkSomething', sub { print "done\n"; # or another test };

        But I do ask - what good is it to provide test suites for somebody who doesn't grok if/else, and what could that target user possibly debug?

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      I hope this was a troll, and not meant seriously. If not, then you've missed out on several decades of programming theory.
        Tilly,
        If you read in his text "if..else construct is deemed to complicated for my target users". This made me believe that it could have been a solution if not for the targeted users, what is simpler labels?