App-SimpleScan
view release on metacpan or search on metacpan
bin/simple_scan view on Meta::CPAN
would generate all four alternatives and run tests for each one:
http://bar.yoursite.com?zz=zorch /Search found/ Y check zorch search
http://baz.yoursite.com?zz=zorch /Search found/ Y check zorch search
http://bar.yoursite.com?zz=thud /Search found/ Y check thud search
http://baz.yoursite.com?zz=thud /Search found/ Y check thud search
This makes it very easy to generate many tests from very few input lines.
simple_scan's substitution engine tracks the values of the variables and
ensures that, for any given line, the substitution values stay consistent.
=head2 Nested substitutions
Substitutions can also reference other substitutions, so something
like this is also possible:
%%mirror blonk whiz thud crunch
%%welcome_msg 'Welcome to <mirror>'
http://<mirror>.yoursite.org/ /<welcome_msg>/ Y <mirror> welcome
When the test spec is expanded, the string 'Welcome to <mirror>'
is substituted in first, then the test spec is expanded again to
create a test for each one of the mirrors.
Note that at present, checking for circular substitutions is not
yet complete; if you write something like this:
%%foo <bar>
%%bar <foo>
http://<foo>.com /check/ Y Infinite loop
C<simple_scan> will substitute "<bar>" for "<foo>, then "<foo>"
for "<bar>", and will continue to happily do so until you kill
the process. At the moment, try not to do this; we'll have a fix
in an upcoming release.
=head2 Single-quotes, double-quotes, and backticks
You can use single-quoted strings in substitutions to get exact
strings containing spaces or tabs:
%%searchtext 'this one' 'that one' 'another one'
The spaces will be preserved in the values assigned to C<searchtext>.
If you want to C<eval> the contents of a string as if it were Perl code
and use that as the value of a substitution, put double quotes around it:
%%language "$ENV{LANGUAGE}"
%%now "@{[scalar localtime]}"
The first example allows you to pass in a value from the environment
variable C<$LANGUAGE>; the second gets the current date and time as a string (so its
value would be something like "Tue Feb 14 14:21:56 2006").
Lastly, you can use backticked strings to denote a command to be
executed by the shell; the command's output will be used in place of
the quoted string.
As an example, if we have the script C<languages> which looks like this:
#!/bin/sh
echo "perl java python ruby"
and the substitution
%%language `languages`
then the values finally assigned to C<language> would be
C<perl java ruby python>.
All of the different forms can be mixed on one line, so
%%try `some_command "value one" value2
would set C<try> to the output of C<some_command>,
C<value one>, and C<value2>.
Finally, since quoted strings are embedded exactly as provided, it's
possible to parameterize your test specs by using environment variables,
like this:
%%language $ENV{LANGUAGE}
http://<language>.org/ /language/i Y <language> should be on the page
Now setting the enviroment variable C<LANGUAGE> in your shell to 'perl'
will propagate 'perl' into the test spec as the language we're testing for.
=head1 OTHER PRAGMAS DEFINED BY SIMPLE_SCAN
There are a few other pragmas defined directly by C<simple_scan>. These
are not plugins, but are implemented directly in the code.
=head2 agent
The C<agent> pragma allows you to switch user agents during the test.
C<Test::WWW::Simple>'s default is C<Windows IE 6>, but you can switch it
to any of the other user agent aliases supported by C<WWW::Mechanize>.
http://gemal.dk/browserspy/basic.html /Explorer/ Y Should be Explorer
%%agent: Mac Safari
http://gemal.dk/browserspy/basic.html /Safari/ Y Should be Safari
(Note: gemal.dk actually does tell you what browser you're running, so
feel free to try this test yourself.)
=head2 cache
The C<cache> pragma turns on URL caching; once enabled, the page returned
on the I<first> access to a URL is returned directly from a memory cache,
without its being reaccessed from the Web.
Using C<cache> can result in major speedups for tests which repeatedly
hit the same page.
=head2 nocache
The C<nocache> pragma turns I<off> URL caching; this is useful if you
have something like a REST interface that may return different values
from repeated accesses to the same URL.
( run in 0.673 second using v1.01-cache-2.11-cpan-39bf76dae61 )