eclipse-iceoryx / eclipse-iceoryx/iceoryx

Testing framework for code which is expected to not compile

Open
#213 1 comment 0 reactions 1 assignee Claimed by @elBoberido View on GitHub
feature request
Dominant language
C++
Stars
2.2k
Forks
492
Avg merge
18h 57m
Merged PRs (30d)
1

Description

## Brief feature description

We need to write tests for code which we expect to not compile.

## Detailed information

We use the type system to prevent some errors, e.g. the NewType pattern which can be used to wrap an integer and add only the required operations like being comparable but not addable. While this makes the software more robust since the compiler will reject invalid code, we can not easily test if the compiler detects the invalid usage like add something to a type which does not support it, because our tests would not compile if it works like expected.

Before we implement something, we should check if there is already framework which we can use.

Proposal for own implementation with:
- in the Setup() of Fixture, a CMakeLists.txt and main.cpp is created in e.g. `./compile_test`
- for the CMakeLists.txt there should be templates for iceoryx_utils, iceoryx_posh and iceoryx_dds, e.g. with `find_package(iceoryx_utils REQUIRED)`
- each test overwrites the main.cpp and then calls cmake to compile the file
- keep in mind to use `CMAKE_PREFIX_PATH`
- the value for `CMAKE_PREFIX_PATH` must be passed to the test executable as as parameter, e.g. `utils_modultests --library-path ../install/prefix`

Alternatively using Boost.Build for compile-fail tests:
Quoting from https://akrzemi1.wordpress.com/2016/05/10/diagnosable-validity/
***
A practical way to check if a given construct fails to compile is to do it from outside C++: prepare a small test program with erroneous construct, compile it, and test if compiler reports compilation failure. This is how “negative” unit tests work with [Boost.Build](http://www.boost.org/build/). For an example, see this negative test form Boost.Optional library: [optional_test_fail_convert_from_null.cpp](https://github.com/boostorg/optional/blob/master/test/optional_test_fail_convert_from_null.cpp). In [configuration file](https://github.com/boostorg/optional/blob/master/test/Jamfile.v2) it is annotated as compile-fail, meaning that test passes only if compilation fails.
***

Once it is implemented, use it for:
- Create compile failure tests for all classes which have deleted c'tors/assignment operators (comes from #202)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.