Module forth3::testutil

source ·
Available on crate feature _force_test_utils only.
Expand description

§Test Utilities

For now, mostly just helpers for running “ui tests”, or executing forth code at test time.

§UI Tests

Generally, forth code provided as a str will have one of the following things for each line:

  • Configuration values for the VM, specified as “frontmatter comments”. These must appear before any other non-comment lines. Currently accepted:
    • ( data_stack_elems USIZE )
    • ( return_stack_elems USIZE )
    • ( control_stack_elems USIZE )
    • ( input_buf_elems USIZE )
    • ( output_buf_elems USIZE )
    • ( dict_buf_elems USIZE )
  • Comment lines. These are any lines just containing a ( ... ) style forth comment.
  • Successful input lines, starting with > ....
  • Successful output lines, starting with < ....
    • Any successful input line can have zero or more output lines
    • If no input lines are specified, ANY successful output is accepted/ignored.
  • Unsuccessful input lines, starting with x ....
    • This line is expected to cause an “exception” - basically process_line returns an Err().
    • There is no way to specify which error yet
    • Unsuccessful input lines may not have any successful output

These ui-tests can also be run as doctests (see below), and doctests can be run in miri.

§Example

This is a forth ui-test doctest. It will be run with cargo test --all-features.

( specify VM settings with frontmatter )
( data_stack_elems 1 )

( specify input with no output )
> : star 42 emit ;

( specify input and output )
> star
< *ok.

( specify lines that cause exceptions/errors )
x starb

Structs§

Enums§

Functions§