Skip to content
This repository
Newer
Older
100644 149 lines (105 sloc) 3.882 kb
b38c8aa8 »
2005-03-04 Some fiddling with test suite:
1 # Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
9d8cce43 »
2004-02-28 a bit more tidying up
2 # $Id$
9b4e5d00 »
2002-08-27 Fixups to make parrotcode.org's autogenerated pages happier
3
9d8cce43 »
2004-02-28 a bit more tidying up
4 =head1 NAME
5
6 docs/tests.pod - Testing Parrot
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
7
8 =head1 A basic guide to writing tests for Parrot
9
10 This is quick and dirty pointer to how tests for Parrot should be
11 written. The testing system is liable to change in the future, but
12 tests written following the guidelines below should be easy to port
13 into a new test suite.
14
1acea255 »
2004-02-26 update info on pir tests in main; don't generate packfile-perl.pod
15 =head1 How to write a test
16
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
17 New tests should be added to F<*.t> files. These test files
18 can be found in the directories F<t>, F<imcc/t> and F<languages/*/t>.
19 If a new feature is tested,
20 it might also make sense to create a new F<*.t> file.
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
21
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
22 The testing framework needs to know how many tests it should expect.
23 So the number of planned tests needs to be
24 incremented when adding a new test.
25 This is done near the top of a test file, in a line that looks like:
553e254a »
2002-03-19 Patch from Simon Glover <scog@amnh.org>:
26
27 use Parrot::Test tests => 8;
28
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
29 =head2 Parrot Assembler
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
30
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
31 PASM test are mostly used for testing ops.
32 Appropriate test files for basic ops are F<t/op/*.t>.
33 Perl Magic Cookies are tested in F<t/pmc/*.t>.
34 Add the new test like this:
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
35
b38c8aa8 »
2005-03-04 Some fiddling with test suite:
36 pasm_output_is(<<'CODE', <<'OUTPUT', "name for test");
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
37 *** a big chunk of assembler, eg:
38 print 1
39 print "\n" # you can even comment it if it's obscure
40 end # don't forget this...!
41 CODE
42 *** what you expect the output of the chunk to be, eg.
43 1
44 OUTPUT
45
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
46 =head2 Parrot Intermediate Representation
47
48 Tests can also be written in B<PIR>. This is done with
49 C<pir_output_is> and friends.
50
51 pir_output_is(<<'CODE',<<'OUT','nothing useful');
52 .include 'library/config.imc'
53
54 .sub main @MAIN
55 print "hi\n"
56 .end
57 CODE
58 hi
59 OUT
1acea255 »
2004-02-26 update info on pir tests in main; don't generate packfile-perl.pod
60
61 =head2 C source tests
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
62
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
63 C source tests are usually located in F<t/src/*.t>.
64 A simple test looks like:
65
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
66 c_output_is(<<'CODE', <<'OUTPUT', "name for test");
67 #include <stdio.h>
68 #include "parrot/parrot.h"
69 #include "parrot/embed.h"
58c0aa8c »
2004-02-26 update info on src tests
70
71 static opcode_t *the_test(Parrot_Interp, opcode_t *, opcode_t *);
72
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
73 int main(int argc, char* argv[]) {
58c0aa8c »
2004-02-26 update info on src tests
74 Parrot_Interp interpreter;
01f4e37a »
2004-09-16 Updated doc and some code to reflect new Parrot_new() interface
75 interpreter = Parrot_new(NULL);
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
76
58c0aa8c »
2004-02-26 update info on src tests
77 if (!interpreter)
9d8cce43 »
2004-02-28 a bit more tidying up
78 return 1;
58c0aa8c »
2004-02-26 update info on src tests
79
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
80 Parrot_init(interpreter);
58c0aa8c »
2004-02-26 update info on src tests
81 Parrot_run_native(interpreter, the_test);
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
82 printf("done\n");
9d8cce43 »
2004-02-28 a bit more tidying up
83 fflush(stdout);
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
84 return 0;
85 }
58c0aa8c »
2004-02-26 update info on src tests
86
87 static opcode_t*
88 the_test(Parrot_Interp interpreter,
9d8cce43 »
2004-02-28 a bit more tidying up
89 opcode_t *cur_op, opcode_t *start)
58c0aa8c »
2004-02-26 update info on src tests
90 {
91 /* Your test goes here. */
92
93 return NULL; /* always return NULL */
94 }
c543d6fa »
2003-09-30 Add C test info to tests.pod (Courtesy of Michael Scott <michael_scot…
95 CODE
96 # Anything that might be output prior to "done".
97 done
98 OUTPUT
99
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
100 Note that it's always a good idea to output "done" to confirm that the compiled
58c0aa8c »
2004-02-26 update info on src tests
101 code executed completely. When mixing C<printf> and C<PIO_printf> always
102 append a C<fflush(stdout);> after the former.
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
103
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
104 =head2 Testing language implementations
105
106 Language implementations are usually tested with the test function
107 C<language_output_is>.
108
1acea255 »
2004-02-26 update info on pir tests in main; don't generate packfile-perl.pod
109 =head1 Ideal tests:
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
110
111 =over 4
112
113 =item o
114
115 Probe the boundaries (including edge cases, errors thrown etc.) of
19b32a9c »
2003-05-14 Minor edits
116 whatever code they're testing. These should include potentially
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
117 out of band input unless we decide that compilers should check for this
118 themselves.
119
120 =item o
121
19b32a9c »
2003-05-14 Minor edits
122 Are small and self contained, so that if the tested feature breaks we
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
123 can identify where and why quickly.
124
125 =item o
126
19b32a9c »
2003-05-14 Minor edits
127 Are valid. Essentially, they should conform to the additional documentation
58c0aa8c »
2004-02-26 update info on src tests
128 that accompanies the feature (if any). [If there isn't any documentation,
129 then feel free to add some and/or complain to the mailing list].
8c4a44c5 »
2001-11-07 This is a basic quide to writing tests with assembler.
130
131 =item o
132
133 Are a chunk of assembler and a chunk of expected output.
134
9b4e5d00 »
2002-08-27 Fixups to make parrotcode.org's autogenerated pages happier
135 =back
a754c8cd »
2005-04-06 Mention 'pir_output_is', 'language_output_is' and TODO in docs/tests.…
136
137 =head1 TODO tests
138
139 In test driven development, tests are implemented first.
140 So the tests are initially expected to fail.
141 This can be expressed by marking the tests as TODO.
142 See L<Test::More> on how to do that.
143
144 =head1 SEE ALSO
145
146 L<http://qa.perl.org>
147
148 =cut
Something went wrong with that request. Please try again.