features.md (7980B)
1 ## Features and design goals 2 3 **doctest** has been designed from the start to be as **light** and **unintrusive** as possible. These key features should be kept. 4 5 ## Unintrusive (transparent): 6 7 - everything testing-related can be removed from the binary executable by defining the [**```DOCTEST_CONFIG_DISABLE```**](configuration.md#doctest_config_disable) identifier 8 - very small and easy to integrate - single header 9 - **Extremely** low footprint on compile times - [**around 25ms**](benchmarks.md#cost-of-including-the-header) of compile time overhead for including the header in a file 10 - The [**fastest possible**](benchmarks.md#cost-of-an-assertion-macro) assertion macros - 50k asserts can compile for under 30 seconds (even under 10 sec) 11 - doesn't drag any headers when included (except for in the translation unit where the library gets implemented) 12 - everything is in the ```doctest``` namespace (and the implementation details are in a nested ```detail``` namespace) 13 - all macros have prefixes - some by default have unprefixed versions as well but that is optional - see [**configuration**](configuration.md) 14 - 0 warnings even with the most aggressive flags (on all tested compilers!!!) 15 - ```-Weverything -pedantic``` for **clang** 16 - ```-Wall -Wextra -pedantic``` and **>> over 35 <<** other warnings **not** covered by these flags for **GCC**!!! - see [**here**](../../scripts/cmake/common.cmake#L84) 17 - ```/Wall``` for **MSVC** 18 - doesn't error on unrecognized [**command line**](commandline.md) options and supports prefixes for interop with client command line parsing 19 - can set options [**procedurally**](main.md) and not deal with passing ```argc```/```argv``` from the command line 20 - doesn't leave warnings disabled after itself 21 22 ## Extremely portable: 23 24 **SOME OF THIS IS OUTDATED** 25 26 - Standards compliant **C++11** code - should work with any **C++11** capable compiler (use tag [**1.2.9**](https://github.com/doctest/doctest/tree/1.2.9) for C++98 and older compilers) 27 - tested with **GCC**: **4.8**, **4.9**, **5**, **6**, **7**, **8**, **9**, **10**, **11** 28 - tested with **Clang**: **3.5**, **3.6**, **3.7**, **3.8**, **3.9**, **4**, **5**, **6**, **7**, **8**, **9**, **10**, **11**, **12**, **13** (XCode 10+) 29 - tested with **MSVC**: **2015**, **2017**, **2019**, **2022** (also in 32 bit mode) 30 - per-commit tested on [**GitHub Actions**](https://github.com/doctest/doctest/actions) 31 - warnings as errors even on the most aggressive warning levels - see [**here**](../../scripts/cmake/common.cmake#L84) 32 - statically analyzed on the CI - [**Cppcheck**](http://cppcheck.sourceforge.net/) / [**Clang-Tidy**](https://clang.llvm.org/extra/clang-tidy/) / [**Coverity Scan**](https://scan.coverity.com/) / [**OCLint**](http://oclint.org/) / [**Visual Studio Analyzer**](https://docs.microsoft.com/en-us/visualstudio/code-quality/analyzing-c-cpp-code-quality-by-using-code-analysis) 33 - all tests have their output compared to reference output of a previous known good run 34 - all tests built and ran in **Debug**/**Release** modes 35 - all tests ran through **valgrind** under **Linux** (sadly [not under OSX](https://github.com/doctest/doctest/issues/11)) 36 - all tests ran through **address**, **UB** and **thread** sanitizers under **Linux**/**OSX** 37 - tests are ran in more than **300** different configurations on UNIX (Linux + OSX) & Windows 38 39 ## Other features: 40 41 - really easy to get started - it's just 1 header file - see the [**tutorial**](tutorial.md) 42 - **very** light, unintrusive and portable - see the sections above - and also the [**benchmarks**](benchmarks.md) 43 - offers a way to remove **everything** testing-related from the binary with the [**```DOCTEST_CONFIG_DISABLE```**](configuration.md#doctest_config_disable) macro 44 - tests are registered automatically - no need to add them to a collection manually 45 - [**Subcases**](tutorial.md#test-cases-and-subcases) - an intuitive way to share common setup and teardown code for test cases (alternative to [**test fixtures**](testcases.md#test-fixtures) which are also supported) 46 - [**templated test cases**](parameterized-tests.md#templated-test-cases---parameterized-by-type) - parameterized by type 47 - supports [**logging macros**](logging.md) for capturing local variables and strings - as a message for when an assert fails - with lazy stringification and no allocations when possible! 48 - crash handling support - uses signals for UNIX and SEH for Windows 49 - [**thread-safe**](faq.md#is-doctest-thread-aware) - asserts (and logging) can be used from multiple threads spawned from a single test case - [**example**](../../examples/all_features/concurrency.cpp) 50 - an extensible [**reporter system**](reporters.md) (can be also used for implementing event listeners) 51 - output from all compilers on all platforms is the same - byte by byte 52 - binaries (exe/dll) can use the test runner of another binary - so tests end up in a single registry - [**example**](../../examples/executable_dll_and_plugin/) 53 - supports [**BDD style**](testcases.md) tests 54 - one core [**assertion macro**](assertions.md) for comparisons - standard C++ operators are used for the comparison (less than, equal, greater than...) - yet the full expression is decomposed and left and right values of the expression are logged 55 - asserts can be used [**outside of a testing context**](assertions.md#using-asserts-out-of-a-testing-context) - [**example**](../../examples/all_features/asserts_used_outside_of_tests.cpp) 56 - assertion macros for [**exceptions**](assertions.md#exceptions) - if something should or shouldn't throw 57 - floating point comparison support - see the [**```Approx()```**](assertions.md#floating-point-comparisons) helper 58 - powerful mechanism for [**stringification**](stringification.md) of user types - including [**exceptions**](stringification.md#translating-exceptions)! 59 - tests can be grouped in [**test suites**](testcases.md#test-suites) 60 - test case [**decorators**](testcases.md#decorators) such as ```description``` / ```skip``` / ```may_fail``` / ```should_fail``` / ```expected_failures``` / ```timeout``` 61 - can be used without exceptions and rtti - checkout [**```DOCTEST_CONFIG_NO_EXCEPTIONS```**](configuration.md#doctest_config_no_exceptions) 62 - powerful [**command line**](commandline.md) with lots of options 63 - can report the duration of test cases 64 - tests can be [**filtered**](commandline.md) based on their name/file/test suite using wildcards 65 - can [**filter**](commandline.md) subcases using wildcards and by specifying the nesting levels for which those filters should work 66 - failures can (optionally) break into the debugger on Windows and Mac 67 - integration with the output window of Visual Studio for failing tests 68 - a ```main()``` can be provided when implementing the library with the [**```DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN```**](main.md#doctest_config_implement_with_main) identifier 69 - can write tests in headers - they will still be registered only once in the executable/shared object 70 - [**range-based**](commandline.md) execution of tests within a binary - see the [**example python script**](../../examples/range_based_execution.py) 71 - [**extension headers**](extensions.md) for extra functionality which doesn't need to go into the main `doctest.h` header 72 - colored output in the console 73 - controlling the order of test execution 74 - different ```doctest::Context```s can be created and ran many times within a single execution of the program 75 - ability to query if code is currently being ran in a test - ```doctest::is_running_in_test``` 76 - tests can be registered in CTest with the use of [```doctest_discover_tests(<target>)``` from scripts/cmake/doctest.cmake](../../scripts/cmake/doctest.cmake) 77 78 There is a list of planned features which are all important and big - see the [**roadmap**](https://github.com/doctest/doctest/issues/600). 79 80 --------------- 81 82 [Home](readme.md#reference) 83 84 <p align="center"><img src="../../scripts/data/logo/icon_2.svg"></p>