******************* Testworks Reference ******************* .. current-library:: testworks .. current-module:: testworks See also: :doc:`usage` The *testworks* library exports a single module named *testworks*. Suites, Tests, and Benchmarks ============================= .. macro:: test-definer Define a new test. :signature: define test *test-name* (#key *expected-to-fail-reason, expected-to-fail-test, tags*) *body* end :parameter test-name: Name of the test; a Dylan variable name. :parameter #key expected-to-fail-reason: A :drm:`` or :drm:`#f`. The reason this test is expected to fail. :parameter #key expected-to-fail-test: An instance of :drm:``. A function to decide whether the test is expected to fail. :parameter #key tags: A list of strings to tag this test. Tests may contain arbitrary code, and must have at least one assertion. That is they must call one of the ``assert-*`` or ``check-*`` macros. If they have no assertions they are given a ``NOT IMPLEMENTED`` result. If any assertion fails the test fails, but any remaining assertions in the test are still executed. If code outside of an assertion signals an error, the test is marked as ``CRASHED`` and the rest of the test is skipped. *expected-to-fail-test*, if supplied, is a function of no arguments that returns a true value if the test is expected to fail. Such a failure is then classified as an ``EXPECTED FAILURE`` result (which is a passing result). If the test passes rather than failing, it has an ``UNEXPECTED SUCCESS`` result (which is a type of failure). A common usage is to make expected failure conditional on the OS: ``method () $os-name == #"win32" end``. This option has no effect on tests which are ``NOT IMPLEMENTED`` or ``CRASHED``. *expected-to-fail-reason* should be supplied if the test is expected to fail. It is good practice to reference a bug (a URL or at least a bug number). .. note:: If *expected-to-fail-reason* is supplied without *expected-to-fail-test* the test is implicitly always expected to fail. *tags* provide a way to select or filter out specific tests during a test run. The Testworks command-line (provided by :func:`run-test-application`) has a ``--tag`` option to only run tests that match (or don't match) specific tags. .. macro:: benchmark-definer Define a new benchmark. :signature: define benchmark *benchmark-name* (#key *expected-to-fail-reason, expected-to-fail-test, tags*) *body* end :parameter benchmark-name: Name of the benchmark; a Dylan variable name. :parameter #key expected-to-fail-reason: A :drm:`` or :drm:`#f`. The reason this benchmark is expected to fail. :parameter #key expected-to-fail-test: An instance of :drm:``. A function to decide whether the benchmark is expected to fail. :parameter #key tags: A list of strings to tag this benchmark. Benchmarks may contain arbitrary code and do not require any assertions. If the benchmark signals an error it is marked as ``CRASHED``. Other than this, and minor differences in how the results are displayed, benchmarks are the same as tests. .. macro:: benchmark-repeat Repeatedly execute a block of code, recording profiling information for each execution. :signature: benchmark-repeat (#key *iterations* = 1) *body* end :parameter iterations: Number of times to execute *body*. Results for benchmarks that call benchmark-repeat display the min, max, mean, and median run times across all iterations. It may be necessary to use ``--report=full`` to display detailed benchmark statistics. At the beginning of each iteration benchmark-repeat first collects garbage to attempt to reduce variability across different executions. .. macro:: suite-definer Define a new test suite. :signature: define suite *suite-name* (#key *setup-function cleanup-function*) *body* end :parameter suite-name: Name of the suite; a Dylan variable name. :parameter #key setup-function: A function to perform setup before the suite starts. :parameter #key cleanup-function: A function to perform teardown after the suite finishes. Suites provide a way to group tests and other suites into a single executable unit. Suites may be nested arbitrarily. *setup-function* is executed before any tests or sub-suites are run. If *setup-function* signals an error the entire suite is skipped and marked as "crashed". *cleanup-function* is executed after all sub-suites and tests have completed, regardless of whether an error is signaled. .. macro:: interface-specification-suite-definer Define a test suite to verify an API. :signature: define interface-specification-suite *suite-name* () *specs* end; :parameter suite-name: Name of the suite; a Dylan variable name. This macro is useful to verify that public interfaces to your library don't change unintentionally. *specs* are clauses separated by semicolons, specifying the attributes of an exported name. Each *spec* looks much like the definition of the name being tested. The following example has one of each kind of spec: .. code-block:: dylan define interface-specification-suite time-specification-suite () sealed instantiable abstract class