Skip to content

Commit 0d0024f

Browse files
committed
Split out EXAMPLES.md
Part of #1302
1 parent 12ca890 commit 0d0024f

File tree

2 files changed

+84
-65
lines changed

2 files changed

+84
-65
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ in the [#perl6 IRC channel](https://perl6.org/community/irc).
1515
# TABLE OF CONTENTS
1616
- [General principles](#general-principles)
1717
- [Documenting types](#documenting-types)
18-
- [Testing examples](#testing-examples)
19-
- [Skipping tests](#skipping-tests)
18+
- [Writing and Testing examples](#writing-and-testing-examples)
2019
- [Debug mode](#debug-mode)
2120
- [Invisible index anchors](#invisible-index-anchors)
2221
- [Viewport size](#viewport-size)
@@ -113,70 +112,9 @@ tests about whitespace and spelling that might be difficult to get right
113112
on an initial commit, and shouldn't be considered to break the build. If
114113
you're contributing a patch or pull request, please make sure this passes.
115114

116-
## Testing examples
115+
## Writing and testing examples
117116

118-
To export examples from all .pod6-files use `make extract-examples`. To run
119-
individual tests pick the right .p6-file from `examples/` as a parameter to
120-
`perl6`.
121-
122-
### Skipping tests
123-
124-
Some examples fail with compile time exceptions and would interrupt the test
125-
for a file. Use the pod-config option `skip-test` to skip them.
126-
127-
=begin code :skip-test
128-
your-example-here();
129-
=end code
130-
131-
In other cases, the snippet of code isn't Perl 6; in that case, mark the
132-
language, which will also skip the test.
133-
134-
=begin code :lang<tcl>
135-
puts "this is not Perl"
136-
=end code
137-
138-
When writing examples, it's often helpful to refer to things that aren't
139-
defined in that snippet; you don't want to have to have a full working
140-
example in the code.
141-
142-
=begin code :preamble<no strict;>
143-
$x = pi;
144-
=end code
145-
146-
=begin code :preamble<my $x; sub frob {...};>
147-
$x = frob();
148-
=end code
149-
150-
You can disable certain checks with :ok-test, allowing us to
151-
generally fail certain styles, but allow them when it is explicitly the
152-
point of the code.
153-
154-
=begin code :ok-test<WHAT>
155-
say 42.WHAT;
156-
=end
157-
158-
If a code snippet looks like a method declaration, it's automatically
159-
wrapped in additional code so you don't have to specify a body in the docs.
160-
Multi-line method signatures are much harder to detect, so if you have a
161-
method body that spans likes, use the :method tag:
162-
163-
=begin code :method
164-
method arg (
165-
Bool $one,
166-
Bool $two
167-
)
168-
=end code
169-
170-
171-
### Catching expected exception
172-
173-
Some tests will throw exceptions that would stop the execution of the extracted
174-
test file. Use the pod-option `catch-all` to have a default handler installed
175-
for a single example.
176-
177-
=begin code :catch-all
178-
exception-generator-here();
179-
=end code
117+
See [EXAMPLES].
180118

181119
## Testing method completeness
182120

EXAMPLES.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## Writing Examples
2+
3+
Please use code blocks to highlight example code; any indented blocks
4+
are considered to be code, but you can use the `=for code` directive, or a
5+
combination of `=begin code` and `=end code` to better control which
6+
blocks are considered.
7+
8+
## Testing Examples
9+
10+
The file `xt/examples-compilation.t` will test code. This file is run
11+
as part of `make xtest`. Each sample
12+
13+
Note that method signatures are also compiled. They have an implied block
14+
added to insure valid compilation.
15+
16+
Care is taken to wrap the sample code in enough boilerplate so that no
17+
runtime code is executed, and that a class is available if needed.
18+
19+
## Skipping or finessing tests
20+
21+
While our goal is to test every example of Perl 6 in the repository, some
22+
blocks are not easy to test. Here are some ways you can skip the test or
23+
finesse it.
24+
25+
### Other languages
26+
27+
We're just testing Perl 6 here: to skip another language, use `:lang`
28+
29+
=begin code :lang<tcl>
30+
puts "this is not Perl"
31+
=end code
32+
33+
### Allow .WHAT
34+
35+
One of the checks is to dissaude using `.WHAT` in tests; However, rarely
36+
that is the explicit point of the test. You can whitelist it:
37+
38+
=begin code :ok-test<WHAT>
39+
say 42.WHAT;
40+
=end
41+
42+
### Methods
43+
44+
If a code snippet looks like a method declaration, it's automatically
45+
wrapped in additional code so you don't have to specify a body in the docs.
46+
Multi-line method signatures are much harder to detect, so if you have a
47+
method body that spans likes, use the :method tag:
48+
49+
=begin code :method
50+
method arg (
51+
Bool $one,
52+
Bool $two
53+
)
54+
=end code
55+
56+
This helps keep the method detection logic in the test code simple.
57+
58+
### Preambles
59+
60+
When writing examples, it's often helpful to refer to things that aren't
61+
defined in that snippet; you don't want to have to have a full working
62+
example in the code.
63+
64+
=begin code :preamble<no strict;>
65+
$x = pi;
66+
=end code
67+
68+
=begin code :preamble<my $x; sub frob {...};>
69+
$x = frob();
70+
=end code
71+
72+
### Failures
73+
74+
Some examples fail with compile time exceptions and would interrupt the test
75+
for a file. Use the pod-config option `skip-test` to skip them. When possible,
76+
specify a reason why you have to use this; it should be considered a last
77+
resort, and many examples might be amenable to using one of the previous annotations.
78+
79+
=begin code :skip-test<compile time error>
80+
if 1 "missing a block";
81+
=end code

0 commit comments

Comments
 (0)