Skip to content
Newer
Older
100644 119 lines (84 sloc) 3.12 KB
9b4e5d0 Fixups to make parrotcode.org's autogenerated pages happier
Dan Sugalski authored Aug 27, 2002
1 =head1 TITLE
2
3 Testing Parrot
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
4
5 =head1 A basic guide to writing tests for Parrot
6
7 This is quick and dirty pointer to how tests for Parrot should be
8 written. The testing system is liable to change in the future, but
9 tests written following the guidelines below should be easy to port
10 into a new test suite.
11
1acea25 update info on pir tests in main; don't generate packfile-perl.pod
Leopold Toetsch authored Feb 26, 2004
12 =head1 How to write a test
13
14 =head2 Assembler tests
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
15
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
16 First, find an appropriate file in F<t/op/*.t> (for basic ops),
17 F<t/pmc/*.t> (for anything to do with PMCs), and F<t/src/*.t> for C
18 source code tests. If there isn't an appropriate file, create one.
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
19
553e254 Patch from Simon Glover <scog@amnh.org>:
Nicholas Clark authored Mar 19, 2002
20 Near the top of each file, you'll see a line like:
21
22 use Parrot::Test tests => 8;
23
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
24 This sets up the test harness used to assemble and run the tests, and
25 lets it know how many tests you plan to run. New tests should be added
26 by:
27
28 1. Incrementing the number of planned tests.
29
30 2. Putting some code in like this:
31
32 output_is(<<'CODE', <<'OUTPUT', "name for test");
33 *** a big chunk of assembler, eg:
34 print 1
35 print "\n" # you can even comment it if it's obscure
36 end # don't forget this...!
37 CODE
38 *** what you expect the output of the chunk to be, eg.
39 1
40 OUTPUT
41
1acea25 update info on pir tests in main; don't generate packfile-perl.pod
Leopold Toetsch authored Feb 26, 2004
42 Tests in F<t/op/> or F<t/pmc/> are considered to be B<PASM> tests.
43 Tests in F<imcc/t/> are assumed to be B<PIR> tests. You can put B<PIR>
44 tests into F<t/op/> or F<t/pmc/> by inserting the special comment B<##PIR##>
45 in the test code:
46
47 output_is(<<'CODE', <<'OUTPUT', "name for test");
48 ##PIR##
49 $P0 = new Integer
50 ...
51
52 =head2 C source tests
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
53
54 c_output_is(<<'CODE', <<'OUTPUT', "name for test");
55 #include <stdio.h>
56 #include "parrot/parrot.h"
57 #include "parrot/embed.h"
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
58
59 static opcode_t *the_test(Parrot_Interp, opcode_t *, opcode_t *);
60
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
61 int main(int argc, char* argv[]) {
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
62 Parrot_Interp interpreter;
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
63 interpreter = Parrot_new();
64
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
65 if (!interpreter)
66 return 1;
67
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
68 Parrot_init(interpreter);
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
69 Parrot_run_native(interpreter, the_test);
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
70 printf("done\n");
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
71 fflush(stdout);
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
72 return 0;
73 }
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
74
75 static opcode_t*
76 the_test(Parrot_Interp interpreter,
77 opcode_t *cur_op, opcode_t *start)
78 {
79 /* Your test goes here. */
80
81 return NULL; /* always return NULL */
82 }
c543d6f @boemmels Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
boemmels authored Sep 30, 2003
83 CODE
84 # Anything that might be output prior to "done".
85 done
86 OUTPUT
87
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
88 Note, it's always a good idea to output "done" to confirm that the compiled
89 code executed completely. When mixing C<printf> and C<PIO_printf> always
90 append a C<fflush(stdout);> after the former.
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
91
1acea25 update info on pir tests in main; don't generate packfile-perl.pod
Leopold Toetsch authored Feb 26, 2004
92 =head1 Ideal tests:
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
93
94 =over 4
95
96 =item o
97
98 Probe the boundaries (including edge cases, errors thrown etc.) of
19b32a9 Minor edits
Simon Glover authored May 14, 2003
99 whatever code they're testing. These should include potentially
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
100 out of band input unless we decide that compilers should check for this
101 themselves.
102
103 =item o
104
19b32a9 Minor edits
Simon Glover authored May 14, 2003
105 Are small and self contained, so that if the tested feature breaks we
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
106 can identify where and why quickly.
107
108 =item o
109
19b32a9 Minor edits
Simon Glover authored May 14, 2003
110 Are valid. Essentially, they should conform to the additional documentation
58c0aa8 update info on src tests
Leopold Toetsch authored Feb 26, 2004
111 that accompanies the feature (if any). [If there isn't any documentation,
112 then feel free to add some and/or complain to the mailing list].
8c4a44c @quidity This is a basic quide to writing tests with assembler.
quidity authored Nov 7, 2001
113
114 =item o
115
116 Are a chunk of assembler and a chunk of expected output.
117
9b4e5d0 Fixups to make parrotcode.org's autogenerated pages happier
Dan Sugalski authored Aug 27, 2002
118 =back
Something went wrong with that request. Please try again.