|
|
## Catch Test Framework
|
|
|
A powerful tool to facilitate writing test for our software is the [Catch Test Framework](https://github.com/catchorg/Catch2/tree/Catch1.x). Before you start reading this page, it is strongly recommended that you read the [tutorial on the Catch Github repo](https://github.com/catchorg/Catch2/blob/Catch1.x/docs/tutorial.md), as well as the [Reference](https://github.com/catchorg/Catch2/blob/Catch1.x/docs/Readme.md).
|
|
|
A powerful tool to facilitate writing test for our software is the [Catch Test Framework](https://github.com/catchorg/Catch2/tree/Catch1.x). Before you start reading this page, it is strongly recommended that you read the [tutorial on the Catch Github repo](https://github.com/catchorg/Catch2/blob/Catch1.x/docs/tutorial.md), as well as the [Reference](https://github.com/catchorg/Catch2/blob/Catch1.x/docs/Readme.md).
|
|
|
Please note that the version of Catch used in our codebase is Catch 1.x.
|
|
|
|
|
|
## Using Catch in Skyward-Boardcore
|
... | ... | @@ -25,7 +25,7 @@ The entrypoint for the is defined as follows: |
|
|
```tcl
|
|
|
[example-test-factorial] #name of the entrypoint
|
|
|
Type: test
|
|
|
BoardId: stm32f429zi_stm32f4discovery #The board you want to run the test on
|
|
|
BoardId: stm32f407vg_stm32f4discovery #The board you want to run the test on
|
|
|
BinName: example-test-factorial #Name of the binary, must be the same as the name of the entrypoint
|
|
|
Include: #Required sources, if any
|
|
|
Defines: -DSTANDALONE_CATCH1_TEST
|
... | ... | @@ -46,7 +46,7 @@ Files: src/tests/examples/example-test-factorial |
|
|
# Run all example tests togheter
|
|
|
[example-catch1-tests]
|
|
|
Type: test
|
|
|
BoardId: stm32f429zi_stm32f4discovery
|
|
|
BoardId: stm32f407vg_stm32f4discovery
|
|
|
BinName: example-catch1-tests
|
|
|
#Add all required sources + tests sources
|
|
|
Include: %shared %example-tests
|
... | ... | @@ -57,14 +57,14 @@ When you run `example-catch1-tests`, both the tests in `example-test-fsm.cpp` an |
|
|
|
|
|
|
|
|
#### Test execution configuration
|
|
|
*Catch* provides some command line options to configure the test output and decide which tests to run. The options are described in the [command line reference page](https://github.com/catchorg/Catch2/blob/Catch1.x/docs/command-line.md) on the Catch Github repo.
|
|
|
In boardcore, these command line options are passed via a *define* in sbs.conf: `CATCH1_CL_OPTIONS`.
|
|
|
_Catch_ provides some command line options to configure the test output and decide which tests to run. The options are described in the [command line reference page](https://github.com/catchorg/Catch2/blob/Catch1.x/docs/command-line.md) on the Catch Github repo.
|
|
|
In boardcore, these command line options are passed via a _define_ in sbs.conf: `CATCH1_CL_OPTIONS`.
|
|
|
Usage: `-DCATCH1_CL_OPTIONS="\"[tag1][tag2] -a -b -c\""`
|
|
|
Example:
|
|
|
```tcl
|
|
|
[example-catch1-tests]
|
|
|
Type: test
|
|
|
BoardId: stm32f429zi_stm32f4discovery
|
|
|
BoardId: stm32f407vg_stm32f4discovery
|
|
|
BinName: example-catch1-tests
|
|
|
#Add all required sources + tests sources
|
|
|
Include: %shared %example-tests
|
... | ... | @@ -94,10 +94,10 @@ TEST_CASE("This will leak memory") |
|
|
delete[] array;
|
|
|
}
|
|
|
```
|
|
|
Where's the catch? If a *REQUIRE* macro fails, the whole test case is interrupted, the line `delete[] array;` will not be executed, and memory will be leaked.
|
|
|
Where's the catch? If a _REQUIRE_ macro fails, the whole test case is interrupted, the line `delete[] array;` will not be executed, and memory will be leaked.
|
|
|
|
|
|
#### GOOD: RAII (Resource Acquisition Is Initialization)
|
|
|
This is a pattern that you should use in all the code base, and not just for testing: any object should acquire resources in its constructor, and release them in its destructor. The destructor is automatically called when the object goes out of scope (of course you can't use *new* to create the object, or the whole purpose of this point is defeated, and we get back at the previous example).
|
|
|
This is a pattern that you should use in all the code base, and not just for testing: any object should acquire resources in its constructor, and release them in its destructor. The destructor is automatically called when the object goes out of scope (of course you can't use `new` to create the object, or the whole purpose of this point is defeated, and we get back at the previous example).
|
|
|
|
|
|
```cpp
|
|
|
// Wrapper for the array
|
... | ... | |