commit | f0d2eda63a410aac21ec5d37c85c627848cecd3e | [log] [tgz] |
---|---|---|
author | Jan Kundrát <jan.kundrat@cesnet.cz> | Thu Apr 30 11:40:08 2020 +0200 |
committer | Jan Kundrát <jan.kundrat@cesnet.cz> | Thu Apr 30 11:40:08 2020 +0200 |
tree | 362c01c25461a6dd6fa7e944b374fe199ca06c1b | |
parent | 7d42bd0fab6c44010c8aed9338bd02bea5feba41 [diff] |
Print subcase stack upon a subcase entry This is largely a hack to give us at least *something* for data driven testing (#215). In that pattern, it's common to structure code in a way that first "generates the data", and only then executes the actual test. It can look like this: TEST_CASE("parsing stuff") { std::string input; Something expected; DOCTEST_SUBCASE("single-line") { DOCTEST_SUBCASE("empty") {} DOCTEST_SUBCASE("trivial") { input = "create foo"; expected = {OP_CREATE, {"foo",}}; } DOCTEST_SUBCASE("two args") { input = "create blah bar"; expected = {OP_CREATE, {"blah", "bar",}}; } } DOCTEST_SUBCASE("multi-line") { DOCTEST_SUBCASE("trailing whitespace") { input = "create foo\n\n"; expected = {OP_CREATE, {"foo,}}; } DOCTEST_SUBCASE("one word per line, two words") { input = "create\nfoo"; expected = {OP_CREATE, {"foo",}}; } } REQUIRE(parse(input) == expected); } The important part is that once we're executing actual tests, the subsections will have been exited already, so the usual ways of showing the subcase stack can be no longer applied. In Catch2, there was a patch which tried to track the deepest subcase stack so far. Let's try to implement something very simple, just printing the current state of the stack once it is entered. It does not tie into any error handling, so the output will be always there, and it also probably does not support any fancy filtering when skipping subcases. However, it's something which at least shows what is going on when an error gets reported. Cc: https://github.com/onqtam/doctest/issues/215 Cc: https://github.com/onqtam/doctest/issues/125
doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of magnitude) and runtime compared to other feature-rich alternatives. It brings the ability of compiled languages such as D / Rust / Nim to have tests written directly in the production code thanks to a fast, transparent and flexible test runner with a clean interface.
The framework is and will stay free but needs your support to sustain its development. There are lots of new features and maintenance to do. If you work for a company using doctest or have the means to do so, please consider financial support. Monthly donations via Patreon and one-offs via PayPal.
A complete example with a self-registering test that compiles to an executable looks like this:
There are many C++ testing frameworks - Catch, Boost.Test, UnitTest++, cpputest, googletest and many other.
The key differences between it and other testing frameworks are that it is light and unintrusive:
DOCTEST_CONFIG_DISABLE
identifierdoctest
) and doesn't drag any headers with itThis allows the framework to be used in more ways than any other - tests can be written directly in the production code!
Tests can be considered a form of documentation and should be able to reside near the production code which they test.
The framework can be used like any other if you don't want/need to mix production code and tests - check out the features.
doctest is modeled after Catch and some parts of the code have been taken directly - check out the differences.
This table compares doctest / Catch / lest which are all very similar.
Checkout the CppCon 2017 talk on YouTube to get a better understanding of how the framework works and read about how to use it in the JetBrains article - highlighting the unique aspects of the framework! On a short description on how to use the framework along production code you could refer to this GitHub issue. There is also an older article in the february edition of ACCU Overload 2017.
Project:
Usage:
main()
entry pointSupport the development of the project with donations! There is a list of planned features which are all important and big - see the roadmap. I took a break from working in the industry to make open source software so every cent is a big deal.
If you work for a company using doctest or have the means to do so, please consider financial support.
Contributions in the form of issues and pull requests are welcome as well - check out the Contributing page.
The logo is licensed under a Creative Commons Attribution 4.0 International License. Copyright © 2019 area55git