1 # This file serves as a model for how to write tests, so is more heavily
2 # commented than the others. All tests are run in the Test subdirectory
3 # of the distribution, which must be writable. They should end with
4 # the suffix `.ztst': this is not required by the test harness itself,
5 # but it is needed by the Makefile to run all the tests.
7 # Blank lines with no other special meaning (e.g. separating chunks of
8 # code) and all those with a `#' in the first column are ignored.
10 # All section names start with a % in the first column. The names
11 # must be in the expected order, though not all sections are required.
12 # The sections are %prep (preparatory setup: code executed should return
13 # status 0, but no other tests are performed), %test (the main tests), and
14 # %clean (to cleanup: the code is simply unconditionally executed).
16 # Literal shell code to be evaluated must be indented with any number
17 # of spaces and/or tabs, to differentiate it from tags with a special
18 # meaning to the test harness. Note that this is true even in sections
19 # where there are no such tags. Also note that file descriptor 9
20 # is reserved for input from the test script, and file descriptor 8
21 # preserves the original stdout. Option settings are preserved between the
22 # execution of different code chunks; initially, all standard zsh options
23 # (the effect of `emulate -R zsh') are set.
26 # This optional section prepares the test, creating directories and files
27 # and so on. Chunks of code are separated by blank lines (which is not
28 # necessary before the end of the section); each chunk of code is evaluated
29 # in one go and must return status 0, or the preparation is deemed to have
30 # failed and the test ends with an appropriate error message. Standard
31 # output from this section is redirected to /dev/null, but standard error
34 # Tests should use subdirectories ending in `.tmp'. These will be
35 # removed with all the contents even if the test is aborted.
36 mkdir cdtst.tmp cdtst.tmp/real cdtst.tmp/sub
38 ln -s ../real cdtst.tmp/sub/fake
46 # This is where the tests are run. It consists of blocks separated
47 # by blank lines. Each block has the same format and there may be any
48 # number of them. It consists of indented code, plus optional sets of lines
49 # beginning '<', '>' and '?' which may appear in any order. These correspond
50 # to stdin (fed to the code), stdout (compared with code output) and
51 # stderr (compared with code error output) respectively. These subblocks
52 # may occur in any order, but the natural one is: code, stdin, stdout,
55 # The rules for '<', '>' and '?' lines are the same: only the first
56 # character is stripped, with subsequent whitespace being significant;
57 # lines are not subject to any substitution unless the `q' flag (see
60 # Each chunk of indented code is to be evaluated in one go and is to
61 # be followed by a line starting (in the first column) with
62 # the expected status returned by the code when run, or - if it is
63 # irrelevant. An optional set of single-letter flags follows the status
64 # or -. The following are understood:
65 # d Don't diff stdout against the expected stdout.
66 # D Don't diff stderr against the expected stderr.
67 # q All redirection lines given in the test script (not the lines
68 # actually produced by the test) are subject to ordinary quoted shell
69 # expansion (i.e. not globbing).
70 # This can be followed by a `:' and a message describing the
71 # test, which will be printed if the test fails, along with a
72 # description of the failure that occurred. The `:' and message are
73 # optional, but highly recommended.
74 # Hence a complete status line looks something like:
75 # 0dDq:Checking whether the world will end with a bang or a whimper
77 # If either or both of the '>' and '?' sets of lines is absent, it is
78 # assumed the corresponding output should be empty and it is an error if it
79 # is not. If '<' is empty, stdin is an empty (but opened) file.
81 # It is also possible to add lines in the redirection section beginning
82 # with `F:'. The remaining text on all such lines will be concatenated
83 # (with newlines in between) and displayed in the event of an error.
84 # This text is useful for explaining certain frequent errors, for example
85 # ones which may arise from the environment rather than from the shell
86 # itself. (The example below isn't particularly useful as errors with
88 cd cdtst.tmp/sub/fake &&
91 0q:Preserving symbolic links in the current directory string
92 >$mydir/cdtst.tmp/sub/fake
93 >$mydir/cdtst.tmp/sub/fake
94 F:This test shouldn't really fail. The fact that it has indicates
95 F:something is broken. But you already knew that.
100 0q:Changing directory up through symbolic links without following them
105 cd cdtst.tmp/sub/fake &&
108 0q:Resolving symbolic links with chaselinks set
109 >$mydir/cdtst.tmp/real
110 >$mydir/cdtst.tmp/real
112 ln -s nonexistent link_to_nonexistent
114 cd -s link_to_nonexistent
116 [[ $pwd1 = $pwd2 ]] || print "Ooops, changed to directory '$pwd2'"
118 ?(eval):cd:3: not a directory: link_to_nonexistent
121 # This optional section cleans up after the test, if necessary,
122 # e.g. killing processes etc. This is in addition to the removal of *.tmp
123 # subdirectories. This is essentially like %prep, except that status
124 # return values are ignored.