| 1 | =head1 NAME |
|---|
| 2 | |
|---|
| 3 | Deprecated Syntax |
|---|
| 4 | |
|---|
| 5 | =head1 SYNOPSIS |
|---|
| 6 | |
|---|
| 7 | This document tries summarized common mistakes in the test suite. If you |
|---|
| 8 | help refactoring the suite, or write new tests, read this document first. |
|---|
| 9 | |
|---|
| 10 | =head1 DEPRECATED SYNTAX |
|---|
| 11 | |
|---|
| 12 | =head2 Old POD |
|---|
| 13 | |
|---|
| 14 | Old POD looks like this: |
|---|
| 15 | |
|---|
| 16 | =head1 heading |
|---|
| 17 | ... |
|---|
| 18 | =cut |
|---|
| 19 | |
|---|
| 20 | The new POD looks like this: |
|---|
| 21 | |
|---|
| 22 | =begin stuff |
|---|
| 23 | ... |
|---|
| 24 | =end stuff |
|---|
| 25 | |
|---|
| 26 | All new files, and all below C<t/spec/> should follow the new conventions. |
|---|
| 27 | |
|---|
| 28 | =head2 Array indexes with negative numbers |
|---|
| 29 | |
|---|
| 30 | The Perl 5 style negative array indexes C<@array[-1]> are spelled |
|---|
| 31 | C<@array[*-1]> in Perl 6. |
|---|
| 32 | |
|---|
| 33 | =head2 pos() |
|---|
| 34 | |
|---|
| 35 | C<pos> is dead. C<$/.to> is the replacement. |
|---|
| 36 | |
|---|
| 37 | =head2 length() |
|---|
| 38 | |
|---|
| 39 | C<length> is gone. Hashes should use C<keys>, C<values>, or the hash in numeric |
|---|
| 40 | context. For arrays, you want C<elems> or the array in numeric context. For |
|---|
| 41 | strings, you want one of C<chars>, C<graphs>, C<codes>, or C<bytes>. |
|---|
| 42 | |
|---|
| 43 | =head2 try takes a statement |
|---|
| 44 | |
|---|
| 45 | C<try> is followed by a statement, so |
|---|
| 46 | |
|---|
| 47 | is try { $operation }, 'foo', '$operation worked' |
|---|
| 48 | |
|---|
| 49 | is parsed as |
|---|
| 50 | |
|---|
| 51 | is try( { $operation }, 'foo', '$operation worked') |
|---|
| 52 | |
|---|
| 53 | which means only one argument to C<is()>, but three to C<try>. So don't use |
|---|
| 54 | this if it's not what you want. This is wrongly used in the test suite right |
|---|
| 55 | now in multiple places. |
|---|
| 56 | |
|---|
| 57 | =head2 Interpolation in test descritions |
|---|
| 58 | |
|---|
| 59 | lives_ok({ $a := $b }, "can bind $b to $a"; |
|---|
| 60 | |
|---|
| 61 | is certainly not what you want; remeber that variables in double quoted |
|---|
| 62 | strings are interpolated, and use single quotes as string delimiters where |
|---|
| 63 | appropriate. |
|---|
| 64 | |
|---|
| 65 | =head2 Special Pugs variables |
|---|
| 66 | |
|---|
| 67 | Some tests rely on C<$?PUGS_BACKEND> and similar variables. Since they are not |
|---|
| 68 | specced, they cause failures on other implementations. Either remove these |
|---|
| 69 | variables alltogether, or fudge them by prepending C<#?pugs emit> on every |
|---|
| 70 | such line. |
|---|
| 71 | |
|---|
| 72 | =head2 "my" in pointy block signatures |
|---|
| 73 | |
|---|
| 74 | C<<for @list -> my $x >> is wrong, no need for a C<my> here. The current test |
|---|
| 75 | suite seems clear of that error. |
|---|
| 76 | |
|---|
| 77 | =head2 dies_ok for tests that can fail at compile time |
|---|
| 78 | |
|---|
| 79 | C<dies_ok> should only be used for tests that have to fail at run time. For |
|---|
| 80 | example non-existant subs are no such case. Always bare in mind that a clever |
|---|
| 81 | compiler might do some type inference and prove that there always will be an |
|---|
| 82 | error, and throw it at compile time. |
|---|
| 83 | |
|---|
| 84 | If in doubt, use C<eval_dies_ok> instead. If you have a case where C<dies_ok> |
|---|
| 85 | is fine, remeber to pass a code ref to it. |
|---|
| 86 | |
|---|
| 87 | =head2 .perl isn't canonical |
|---|
| 88 | |
|---|
| 89 | The C<perl> method (which does roughly the same as perl 5's Data::Dumper) |
|---|
| 90 | returns a string that, when evaluated, returns the same value as the original |
|---|
| 91 | one. |
|---|
| 92 | |
|---|
| 93 | However it's result isn't guarantued to be of any canonical form, for example |
|---|
| 94 | C<Str.perl> might return any legal quoting syntax. Testing for the exact value |
|---|
| 95 | of C<$anything.perl> is most likely an error |
|---|
| 96 | |
|---|
| 97 | =head2 Junctions are unordered |
|---|
| 98 | |
|---|
| 99 | Junctions are unordered assemblies, and C<Junction.values> returns these |
|---|
| 100 | values in an arbitrary order, just like C<keys %hash> and the like. Don't rely |
|---|
| 101 | on that order. |
|---|
| 102 | |
|---|
| 103 | =head2 A note on :todo<bug> and similar |
|---|
| 104 | |
|---|
| 105 | Some tests (mostly outside of t/spec) look like this: |
|---|
| 106 | |
|---|
| 107 | is(foo(), bar(), 'testing whatever', :todo<bug>); |
|---|
| 108 | |
|---|
| 109 | This form is a todo note for Pugs. Since this test suite is used by multiple |
|---|
| 110 | implementations, this should be replaced with a fudge command: |
|---|
| 111 | |
|---|
| 112 | #?pugs todo 'bug' |
|---|
| 113 | is(foo(), bar(), 'testing whatever'); |
|---|
| 114 | |
|---|
| 115 | =cut |
|---|