Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/tests instructions #1199

Merged
merged 4 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Rule type](#rule-type)
- [Coding Guidelines](#coding-guidelines)
- [C++](#c)
- [Unit testing](/tests/README.md)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to write a section about tests in the organization contributing file too?

- [Developer Certificate Of Origin](#developer-certificate-of-origin)

## Code of Conduct
Expand Down
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(FALCO_TESTS_SOURCES test_base.cpp engine/test_token_bucket.cpp falco/test_we

set(FALCO_TESTED_LIBRARIES falco_engine)

SET(FALCO_TESTS_ARGUMENTS "" CACHE STRING "Test arguments to pass to the Falco test suite")

option(FALCO_BUILD_TESTS "Determines whether to build tests." ON)

if(FALCO_BUILD_TESTS)
Expand Down Expand Up @@ -47,6 +49,6 @@ if(FALCO_BUILD_TESTS)
include(CTest)
include(Catch)
catch_discover_tests(falco_test)

add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS falco_test)
separate_arguments(FALCO_TESTS_ARGUMENTS)
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND} ${FALCO_TESTS_ARGUMENTS} DEPENDS falco_test)
endif()
57 changes: 57 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Falco unit tests

This folder contains the unit-tests suite for Falco.
The framework we use for unit-tests is [Catch2](https://github.com/catchorg/Catch2), while the one we use for mocking is [FakeIt](https://github.com/eranpeer/FakeIt).


## How to write tests

When you want to test a new file or test a non tested file, remember four steps:

- The folder structure here is the same as the one in the `userspace` folder, so `userspace/engine` becomes `tests/engine`.
- We call test files with this format `test_<original-file-name>.cpp`
- Update the `CMakeLists.txt` file to include your file in `FALCO_TESTS_SOURCES` and change the `FALCO_TESTED_LIBRARIES` accordingly. You might also need to add dependencies, in that case, look at `target_link_libraries` and `target_include_directories`
- If you are unsure on how to write tests, refer to our existing tests in this folder and to the [Catch2](https://github.com/catchorg/Catch2/tree/master/docs) documentation.

## How to execute tests

The suite can be configured with `cmake` and run with `make`.


In the root folder of Falco, after creating the build directory:

```bash
cd falco
mkdir build
cd build
```

You can prepare the tests with:

```
cmake ..
```

Optionally, you can customize the test suite by passing custom arguments like the examples below:

**filter all tests containing the word ctor**

```bash
cmake -DFALCO_TESTS_ARGUMENTS:STRING="-R ctor" ..
```

**verbose execution**

```bash
cmake -DFALCO_TESTS_ARGUMENTS:STRING="-V" ..
```


To see a list of all the custom arguments you may pass, execute `ctest --help` in your terminal.


Once you are ready, you can run your configuration with:

```bash
make tests
```