| 1 |
;; This is intended to be a self-documenting test which explains what's |
| 2 |
;; possible in directives for this test suite in `tests/cli/*`. The purpose of |
| 3 |
;; this test suite is to make it as easy as dropping a file in this directory to |
| 4 |
;; test the `wasm-tools` CLI tool and its subcommands. The test file itself is |
| 5 |
;; generally the input to the test and what's being tested will be present in |
| 6 |
;; comments at the top of the file with directives. |
| 7 |
;; |
| 8 |
;; All test directives must come in comments at the start of the file: |
| 9 |
;; |
| 10 |
;; RUN: validate % |
| 11 |
;; |
| 12 |
;; The `RUN` prefix indicates that the specified `wasm-tools` subcommand should |
| 13 |
;; be executed. It's possible to have more than one test in a file by having |
| 14 |
;; named directives such as: |
| 15 |
;; |
| 16 |
;; RUN[validate-again]: validate % |
| 17 |
;; |
| 18 |
;; Directive names must be unique, so using `validate-again` would not be valid. |
| 19 |
;; Additionally you can't use an unprefixed directive more than once so using |
| 20 |
;; `RUN: ...` here again would not be allowed for example. |
| 21 |
;; |
| 22 |
;; You can also use the `FAIL` directive to indicate that the subcommand should |
| 23 |
;; fail rather than succeed. |
| 24 |
;; |
| 25 |
;; FAIL[should-fail]: validate % --features=-simd |
| 26 |
;; |
| 27 |
;; As you can see directives can have comments around them. Directives are |
| 28 |
;; identified as comment lines starting with `RUN` or `FAIL`. |
| 29 |
;; |
| 30 |
;; Within directives there are a few feature. First as you've seen the `%` value |
| 31 |
;; will be substituted with the current filename which means: |
| 32 |
;; |
| 33 |
;; RUN[subst]: validate % |
| 34 |
;; |
| 35 |
;; means to run `wasm-tools validate tests/cli/readme.wat` and test the result |
| 36 |
;; is successful. |
| 37 |
;; |
| 38 |
;; You can additionally use `|` to pipe commands together by feeding the stdout |
| 39 |
;; of the previous command into the stdin of the next command. |
| 40 |
;; |
| 41 |
;; RUN[pipe]: print % | validate |
| 42 |
;; |
| 43 |
;; Note that when piping commands the intermediate commands before the final |
| 44 |
;; one, in this case `print` being the intermediate, must all succeed. |
| 45 |
;; |
| 46 |
;; Tests also assert the stdout/stderr of the command being tested. For example |
| 47 |
;; if printing is tested: |
| 48 |
;; |
| 49 |
;; RUN[print]: print % |
| 50 |
;; |
| 51 |
;; then this tests that `tests/cli/readme.wat.print.stdout` is the result of |
| 52 |
;; `wasm-tools print tests/cli/readme.wat`. Note that this can be tedious to |
| 53 |
;; update so you can use the environment variable `BLESS=1` to automatically |
| 54 |
;; update all test assertions. This can then be reviewed after the test is |
| 55 |
;; passing for accuracy. |
| 56 |
;; |
| 57 |
;; Each test additionally can have a temporary directory available to it which |
| 58 |
;; is accessible with the `%tmpdir` substitution. For example: |
| 59 |
;; |
| 60 |
;; RUN[tmpdir]: print % -o %tmpdir/foo.wat | validate %tmpdir/foo.wat |
| 61 |
;; |
| 62 |
;; Note that temporary directories are persisted across tests in the same file, |
| 63 |
;; but different files all get different temporary directories. |
| 64 |
;; |
| 65 |
;; You can also split commands across multiple lines: |
| 66 |
;; |
| 67 |
;; RUN[multiline]: print % | \ |
| 68 |
;; validate |
| 69 |
;; |
| 70 |
;; here the `\` character is deleted and the next line is concatenated. |
| 71 |
|
| 72 |
|
| 73 |
;; this is the contents of the test, mostly empty in this case. |
| 74 |
(module |
| 75 |
(type (func (result v128))) |
| 76 |
) |