parrotcode: Testing Parrot | |
Contents | Documentation |
docs/tests.pod - Testing Parrot
This is quick and dirty pointer to how tests for Parrot should be written. The testing system is liable to change in the future, but tests written following the guidelines below should be easy to port into a new test suite.
First, find an appropriate file in t/op/*.t (for basic ops), t/pmc/*.t (for anything to do with PMCs), and t/src/*.t for C source code tests. If there isn't an appropriate file, create one.
Near the top of each file, you'll see a line like:
use Parrot::Test tests => 8;
This sets up the test harness used to assemble and run the tests, and lets it know how many tests you plan to run. New tests should be added by:
1. Incrementing the number of planned tests.
2. Putting some code in like this:
pasm_output_is(<<'CODE', <<'OUTPUT', "name for test");
*** a big chunk of assembler, eg:
print 1
print "\n" # you can even comment it if it's obscure
end # don't forget this...!
CODE
*** what you expect the output of the chunk to be, eg.
1
OUTPUT
Tests in t/op/ or t/pmc/ are considered to be PASM tests. Tests in imcc/t/ are assumed to be PIR tests. You can put PIR tests into t/op/ or t/pmc/ by using functions like 'pir_output_is'.
c_output_is(<<'CODE', <<'OUTPUT', "name for test");
#include <stdio.h>
#include "parrot/parrot.h"
#include "parrot/embed.h"
static opcode_t *the_test(Parrot_Interp, opcode_t *, opcode_t *);
int main(int argc, char* argv[]) {
Parrot_Interp interpreter;
interpreter = Parrot_new(NULL);
if (!interpreter)
return 1;
Parrot_init(interpreter);
Parrot_run_native(interpreter, the_test);
printf("done\n");
fflush(stdout);
return 0;
}
static opcode_t*
the_test(Parrot_Interp interpreter,
opcode_t *cur_op, opcode_t *start)
{
/* Your test goes here. */
return NULL; /* always return NULL */
}
CODE
# Anything that might be output prior to "done".
done
OUTPUT
Note, it's always a good idea to output "done" to confirm that the compiled code executed completely. When mixing printf
and PIO_printf
always append a fflush(stdout);
after the former.
|