NAME
Parrot::Test - testing routines for Parrot and language implementations
SYNOPSIS
Set the number of tests to be run like this:
use Parrot::Test tests => 8;
Write individual tests like this:
pasm_output_is(<<'CODE', <<'OUTPUT', "description of test");
print "this is ok\n"
end
CODE
this is ok
OUTPUT
DESCRIPTION
This module provides various Parrot-specific test functions.
Function Parameters
$language
-
The language of the code being tested.
$code
-
The code that should be executed or transformed.
$expected
-
The expected result.
$unexpected
-
The unexpected result.
$description
-
A short description of the test.
Any optional parameters can follow. For example, to mark a test as a TODO test (where you know the implementation does not work yet), pass:
todo => 'reason to consider this TODO'
at the end of the argument list. Valid reasons include bug
, unimplemented
, and so on.
Note: you must use a $description
with TODO tests.
Functions
language_output_is($language, $code, $expected, $description)
language_error_output_is($language, $code, $expected, $description)
-
Runs a language test and passes the test if a string comparison of the output with the expected result is true. For
language_error_output_is()
, the exit code also has to be non-zero. language_output_like($language, $code, $expected, $description)
language_error_output_like($language, $code, $expected, $description)
-
Runs a language test and passes the test if the output matches the expected result. For
language_error_output_like()
, the exit code also has to be non-zero. language_output_isnt($language, $code, $expected, $description)
language_error_output_isnt($language, $code, $expected, $description)
-
Runs a language test and passes the test if a string comparison of the output with the unexpected result is false. For
language_error_output_isnt()
, the exit code also has to be non-zero. pasm_output_is($code, $expected, $description)
-
Runs the PASM code and passes the test if a string comparison of the output with the expected result is true.
pasm_error_output_is($code, $expected, $description)
-
Runs the PASM code and passes the test if a string comparison of the output with the expected result is true and if Parrot exits with a non-zero exit code.
pasm_output_like($code, $expected, $description)
-
Runs the PASM code and passes the test if the output matches
$expected
. pasm_error_output_like($code, $expected, $description)
-
Runs the PASM code and passes the test if the output matches
$expected
and if Parrot exits with a non-zero exit code. pasm_output_isnt($code, $unexpected, $description)
-
Runs the PASM code and passes the test if a string comparison of the output with the unexpected result is false.
pasm_error_output_isnt($code, $unexpected, $description)
-
Runs the PASM code and passes the test if a string comparison of the output with the unexpected result is false and if Parrot exits with a non-zero exit code.
pasm_exit_code_is($code, $exit_code, $description)
-
Runs the PASM code and passes the test if the exit code equals $exit_code, fails the test otherwise.
pir_output_is($code, $expected, $description)
-
Runs the PIR code and passes the test if a string comparison of the output with the expected result is true.
pir_error_output_is($code, $expected, $description)
-
Runs the PIR code and passes the test if a string comparison of the output with the expected result is true and if Parrot exits with a non-zero exit code.
pir_output_like($code, $expected, $description)
-
Runs the PIR code and passes the test if the output matches the expected result.
pir_error_output_like($code, $expected, $description)
-
Runs the PIR code and passes the test if the output matches the expected result and if Parrot exits with a non-zero exit code.
pir_output_isnt($code, $unexpected, $description)
-
Runs the PIR code and passes the test if a string comparison of the output with the unexpected result is false.
pir_error_output_isnt($code, $unexpected, $description)
-
Runs the PIR code and passes the test if a string comparison of the output with the unexpected result is false and if Parrot exits with a non-zero exit code.
pir_exit_code_is($code, $exit_code, $description)
-
Runs the PIR code and passes the test if the exit code equals $exit_code, fails the test otherwise.
pbc_output_is($code, $expected, $description)
-
Runs the Parrot bytecode and passes the test if a string comparison of the output with the expected result is true.
pbc_error_output_is($code, $expected, $description)
-
Runs the Parrot bytecode and passes the test if a string comparison of the output with the expected result is true and if Parrot exits with a non-zero exit code.
pbc_output_like($code, $expected, $description)
-
Runs the Parrot bytecode and passes the test if the output matches the expected result.
pbc_error_output_like($code, $expected, $description)
-
Runs the Parrot bytecode and passes the test if the output matches the expected result and if Parrot exits with a non-zero exit code.
pbc_output_isnt($code, $unexpected, $description)
-
Runs the Parrot bytecode and passes the test if a string comparison of the output with the unexpected result is false.
pbc_error_output_isnt($code, $unexpected, $description)
-
Runs the Parrot bytecode and passes the test if a string comparison of the output with the unexpected result is false and if Parrot exits with a non-zero exit code.
pbc_exit_code_is($code, $exit_code, $description)
-
Runs the Parrot bytecode and passes the test if the exit code equals $exit_code, fails the test otherwise.
c_output_is($code, $expected, $description, %options)
-
Compiles and runs the C code, passing the test if a string comparison of the output with the expected result is true. Valid options are 'todo' => 'reason' to mark a TODO test.
c_output_like($code, $expected, $description, %options)
-
Compiles and runs the C code, passing the test if the output matches the expected result. Valid options are 'todo' => 'reason' to mark a TODO test.
c_output_isnt($code, $unexpected, $description, %options)
-
Compiles and runs the C code, passing the test if a string comparison of the output with the unexpected result is false. Valid options are 'todo' => 'reason' to mark a TODO test.
example_output_is($example_f, $expected, @todo)
example_output_like($example_f, $expected, @todo)
example_output_isnt($example_f, $expected, @todo)
-
Determines the language, PIR or PASM, from the extension of
$example_f
and runs the appropriatelanguage_output_(is|like|isnt)
subroutine.$example_f
is used as a description, so don't pass one. skip($why, $how_many)
-
Use within a
SKIP: { ... }
block to indicate why and how many tests to skip, just like in Test::More. run_command($command, %options)
-
Run the given $command in a cross-platform manner.
%options include...
STDOUT name of file to redirect STDOUT to STDERR name of file to redirect STDERR to CD directory to run the command in
For example:
# equivalent to "cd some_dir && make test" run_command("make test", CD => "some_dir");
slurp_file($file_name)
-
Read the whole file $file_name and return the content as a string. This is just an alias for
Parrot::BuildUtil::slurp_file
. convert_line_endings($text)
-
Convert Win32 style line endings with Unix style line endings.
path_to_parrot()
-
Construct an absolute path to the Parrot root directory.
per_test($ext, $test_no)
-
Construct a path for temporary files. Takes
$0
into account. write_code_to_file($code, $code_f)
-
Writes
$code
into the file$code_f
. generate_languages_functions()
-
Generate functions that are only used by a couple of Parrot::Test::<lang> modules. This implementation is experimental and currently only works for languages/pipp.
- "pbc_postprocess_output_like"
-
Takes a path to binary which will post process PBC, a file to run, the extension of the file, one regex or an array reference of regexes, and an optional diagnostic message. This function generates PBC for the input file, then post processes this with the binary and captures the output. The output is then verified to match the single or multiple regular expressions given.
my $postprocess = File::Spec->catfile( ".", "pbc_dump" ); my $file = 'foo.pir'; my $ext = 'pir'; my $check = [ qr/has a foo/, qr/and a bar/ ]; pbc_postprocess_output_like ( $postprocess, $file, $ext, $check, "checking pbc_dump" );
pir_stdin_output_is($input_string, $code, $expected, $description)
-
Runs the PIR code while piping data into its standard input and passes the test if a string comparison of output with the expected result is true.
pir_stdin_output_like($input_string, $code, $expected, $description)
-
Runs the PIR code while piping data into its standard input and passes the test if the output matches the expected result.
SEE ALSO
- t/harness
- docs/tests.pod
- "More" in Test
- "Builder" in Test