2015-03-17 13:06:24 +01:00
|
|
|
---
|
|
|
|
title: Test Cases
|
2021-05-26 21:13:21 +02:00
|
|
|
permalink: /testing.html
|
|
|
|
created_at: 2015-03-17 13:06:24 +0100
|
|
|
|
last_modified_at: 2021-02-17 10:38:00 +0200
|
2015-03-17 13:06:24 +01:00
|
|
|
---
|
|
|
|
|
2015-05-12 21:42:57 +02:00
|
|
|
# Test Cases
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
The boxes sources have a low-tech test suite in the
|
|
|
|
[test](https://github.com/{{ site.github }}/tree/master/test){:target="_blank"} subdirectory. Our continuous
|
|
|
|
integration pipeline will execute it in order to make sure that a change did not break the program.
|
2015-05-12 21:42:57 +02:00
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2
|
|
|
|
text="Invocation" %}
|
2015-05-12 21:42:57 +02:00
|
|
|
|
|
|
|
Start the entire suite by running `make && make test` from the top level directory.
|
|
|
|
|
|
|
|
Run an individual test by calling `./testrunner.sh testcase.txt` from the *test* directory.
|
|
|
|
|
|
|
|
|
2021-05-26 21:13:21 +02:00
|
|
|
{% comment %} ---------------------------------------------------------------------------------------- {% endcomment %}
|
|
|
|
{% include heading.html
|
|
|
|
level=2
|
|
|
|
text="Test Case Format" %}
|
2015-05-12 21:42:57 +02:00
|
|
|
|
|
|
|
Each test case is a single file within the *test* subdirectory. It must follow this naming convention:
|
|
|
|
|
|
|
|
nnn_description.txt
|
|
|
|
|
2021-02-17 10:38:51 +01:00
|
|
|
where `nnn` is a three-digit number which uniquely identifies the test case. `description` is any short text that
|
|
|
|
describes what the test case does. It must not contain spaces; use underscores instead. The file extension is always
|
|
|
|
`.txt`.
|
2015-05-12 21:42:57 +02:00
|
|
|
|
|
|
|
A test case that tests a **successful** invocation of boxes looks like this:
|
|
|
|
|
2021-02-17 10:38:51 +01:00
|
|
|
:DESC
|
|
|
|
Tests invoking boxes with a fixed result box size.
|
|
|
|
|
2015-05-12 21:42:57 +02:00
|
|
|
:ARGS
|
|
|
|
-s 10x4
|
|
|
|
:INPUT
|
|
|
|
foo
|
|
|
|
:OUTPUT-FILTER
|
|
|
|
:EXPECTED
|
|
|
|
/********/
|
|
|
|
/* foo */
|
|
|
|
/* */
|
|
|
|
/********/
|
|
|
|
:EOF
|
|
|
|
|
2021-02-17 10:38:51 +01:00
|
|
|
Sections may be empty, e.g. if there are no arguments or there is no input. The `:DESC` section is optional, so it is
|
|
|
|
valid if the test case starts with an `:ARGS` section. The order of sections is fixed.
|
2015-05-12 21:42:57 +02:00
|
|
|
|
|
|
|
A test case that makes sure boxes **fails** under certain conditions looks like this:
|
|
|
|
|
2021-02-17 10:38:51 +01:00
|
|
|
:DESC
|
|
|
|
Tests that the right error message is shown when the boxes
|
|
|
|
config file cannot be found.
|
|
|
|
|
2015-05-12 21:42:57 +02:00
|
|
|
:ARGS
|
|
|
|
-f nonexistent
|
|
|
|
:INPUT
|
|
|
|
:OUTPUT-FILTER
|
|
|
|
:EXPECTED-ERROR 1
|
2021-05-26 21:13:21 +02:00
|
|
|
boxes: Couldn't find config file at 'nonexistent'
|
2015-05-12 21:42:57 +02:00
|
|
|
:EOF
|
|
|
|
|
2021-02-17 10:38:51 +01:00
|
|
|
Note that you write `:EXPECTED-ERROR` instead of just `:EXPECTED`, and the expected return code is given after a space
|
|
|
|
(in this example, it is `1`).
|
2015-05-12 21:42:57 +02:00
|
|
|
|
2021-02-17 10:38:51 +01:00
|
|
|
The `:OUTPUT-FILTER` section can be used to give a *sed* script which is run on the actual output before comparing it
|
|
|
|
to the expected output
|
|
|
|
([example](https://github.com/{{ site.github }}/blob/master/test/065_size_missing_argument.txt){:target="_blank"}).
|
|
|
|
This way, differences in output that occur because of platform differences can be filtered out. The general advice is
|
|
|
|
to leave this section empty unless you are facing a situation where there is no other solution.
|