The fastest feature-rich C++11/14/17/20 single-header testing framework

Overview

master branch Windows All
dev branch Windows All

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.

Standard License Version download CII Best Practices Language grade: C/C++ Join the chat at https://gitter.im/onqtam/doctest Try it online

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:

cover-example

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:

  • Ultra light on compile times both in terms of including the header and writing thousands of asserts
  • Doesn't produce any warnings even on the most aggressive warning levels for MSVC/GCC/Clang
  • Offers a way to remove everything testing-related from the binary with the DOCTEST_CONFIG_DISABLE identifier
  • thread-safe - asserts (and logging) can be used from multiple threads spawned from a single test case - example
  • asserts can be used outside of a testing context - as a general purpose assert library - example
  • Doesn't pollute the global namespace (everything is in namespace doctest) and doesn't drag any headers with it
  • Very portable C++11 (use tag 1.2.9 for C++98) with over 180 different CI builds (static analysis, sanitizers...)
  • binaries (exe/dll) can use the test runner of another binary - so tests end up in a single registry - example

cost-of-including-the-framework-header

This 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.

  • This makes the barrier for writing tests much lower - you don't have to: 1) make a separate source file 2) include a bunch of stuff in it 3) add it to the build system and 4) add it to source control - You can just write the tests for a class or a piece of functionality at the bottom of its source file - or even header file!
  • Tests in the production code can be thought of as documentation or up-to-date comments - showing the use of APIs
  • Testing internals that are not exposed through the public API and headers is no longer a mind-bending exercise
  • Test-driven development in C++ has never been easier!

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.

CppCon 2017 talk about doctest on youtube

Documentation

Project:

Usage:

Contributing

Support 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.

Stargazers over time

Stargazers over time

Logo

The logo is licensed under a Creative Commons Attribution 4.0 International License. Copyright © 2019 area55git   License: CC BY 4.0

Comments
  • Add Github Actions CI

    Add Github Actions CI

    Opening the pull request so I can start testing the configuration. I've started by taking reproc's Github Actions configuration and removing everything reproc related. Once that works I'll start adding all doctest related configuration.

    opened by DaanDeMeyer 38
  • Regression between 2.4.6 and 2.4.7

    Regression between 2.4.6 and 2.4.7

    Description

    Following minimized code works perfectly on 2.4.6, but fails on 2.4.7

    // #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN shouldn't be defined in compilation unit to reproduce
    #include <doctest/doctest.h>
    
    #include <string>
    
    namespace {
    
    class B
    {
    public:
        const std::string& getName() const
        {
            return m_name;
        }
    
        std::string m_name = "B";
    };
    
    }  // namespace
    
    TEST_CASE("Wtf?") {
        B b;
    
        CHECK(b.getName() == "B");
    }
    

    https://godbolt.org/z/Eq48fjsed (due to the godbolt limitations see "undefined reference to `main'" linker warnings as success)

    Flags: "-std=c++11 -Wall -Wextra -Wpedantic -Werror"

    It fails on GCC version 4.9 - 10.3 with -fpermissive warning. (GCC version 11.2 compiles it without a problem though 🤔)

    doctest/doctest.h: In instantiation of 'void doctest::detail::fillstream(const T (&)[N]) [with T = char; long unsigned int N = 2]':
    doctest/doctest.h:904:31:   required from 'static void doctest::detail::filldata<T [N]>::fill(const T (&)[N]) [with T = const char; long unsigned int N = 2]'
    doctest/doctest.h:918:65:   required from 'void doctest::detail::filloss(const T (&)[N]) [with T = char; long unsigned int N = 2]'
    doctest/doctest.h:933:20:   required from 'static doctest::String doctest::detail::StringMakerBase<true>::convert(const T&) [with T = char [2]]'
    doctest/doctest.h:978:35:   required from 'doctest::String doctest::toString(const T&) [with T = char [2]; typename doctest::detail::enable_if<(! doctest::detail::is_enum<T>::value), bool>::type <anonymous> = true]'
    doctest/doctest.h:1142:45:   required from 'doctest::String doctest::detail::stringifyBinaryExpr(const L&, const char*, const R&) [with L = std::__cxx11::basic_string<char>; R = char [2]]'
    doctest/doctest.h:1320:9:   required from 'decltype (((void)((declval<L>() == declval<R>())), (doctest::detail::Result)(<brace-enclosed initializer list>()))) doctest::detail::Expression_lhs<L>::operator==(const R&) [with R = char [2]; typename doctest::detail::enable_if<(! doctest::detail::is_rvalue_reference<R>::value), void>::type* <anonymous> = 0; L = const std::__cxx11::basic_string<char>&; decltype (((void)((declval<L>() == declval<R>())), (doctest::detail::Result)(<brace-enclosed initializer list>()))) = doctest::detail::Result]'
    <source>:24:5:   required from here
    doctest/doctest.h:896:31: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char, std::char_traits<char> >'} and 'const char')
    doctest/doctest.h:557:33: note: candidate: 'std::ostream& doctest::operator<<(std::ostream&, const doctest::String&)' (near match)
    doctest/doctest.h:557:33: note:   conversion of argument 2 would be ill-formed:
    doctest/doctest.h:896:36: error: invalid user-defined conversion from 'const char' to 'const doctest::String&' [-fpermissive]
    doctest/doctest.h:519:5: note: candidate is: 'doctest::String::String(const char*)' (near match)
    doctest/doctest.h:519:5: note:   conversion of argument 1 would be ill-formed:
    doctest/doctest.h:896:36: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
    doctest/doctest.h:896:36: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
    doctest/doctest.h:519:24: note:   initializing argument 1 of 'doctest::String::String(const char*)'
    In file included from /opt/compiler-explorer/gcc-10.3.0/include/c++/10.3.0/string:55,
                     from <source>:4:
    /opt/compiler-explorer/gcc-10.3.0/include/c++/10.3.0/bits/basic_string.h:6468:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
     6468 |     operator<<(basic_ostream<_CharT, _Traits>& __os,
          |     ^~~~~~~~
    /opt/compiler-explorer/gcc-10.3.0/include/c++/10.3.0/bits/basic_string.h:6468:5: note:   template argument deduction/substitution failed:
    doctest/doctest.h:896:31: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'const char'
    

    It fails on any version of clang, but with an error instead of the warning. It fails on MSVC at least in version 19 that is accessible on Godbolt.

    Using this code as a test, it's possible to bisect a broken commit.

    opened by YarikTH 28
  • Tests inside a static library

    Tests inside a static library

    Hi,

    (This is more a question than an issue) What is the recommended way to add tests inside a static library project ?

    If I compile a library (which includes TEST_CASE(s)) as a static library, and then I try to run the tests from this library by creating a target that links to it, the test suite is actually empty (i.e I guess the tests were stripped at link time)

    Am I doing something wrong, or is there a way to circumvent this?

    Below is an example of what I am trying to achieve (using cmake):

    Project         <- main project
      CMakeLists.txt
      doctest/
        doctest.h
        doctest_main.cpp
      MyLibrary/
        lib1.cpp    <- these files includes actual library code and TEST_CASE(s)
        lib2.cpp    
        lib3.cpp    
        CMakeLists.txt <- will produce two targets : library and its test
      MyMainProgram/
        main.cpp
        CMakeLists.txt
    
    

    MyLibrary/CMakeLists.txt :

        set(sources lib1.cpp lib2.cpp lib3.cpp)
        add_library(MyLibrary STATIC ${sources})
        target_include_directories(MyLibrary PUBLIC ${CMAKE_SOURCE_DIR}/doctest )
    
        # This does not work : it links but the test list is empty !
        add_executable(MyLibrary_DocTest ${CMAKE_SOURCE_DIR}/doctest/doctest_main.cpp)
        target_link_libraries(MyLibrary_DocTest MyLibrary)
    
        # This works, but it requires to re-compile all the source files and to re-define
        # exactly the same compile options as for the library (linked library, compile definition, etc); 
        # this can be tedious
        add_executable(MyLibrary_DocTest ${sources} ${CMAKE_SOURCE_DIR}/doctest/doctest_main.cpp)
    
    

    MyMainProgram/CMakeLists.txt :

        add_executable(MyMainProgram main.cpp)
        target_link_libraries(MyMainProgram MyLibrary)
    

    A working example can be found at https://github.com/pthom/DocTest_LibTest

    opened by pthom 28
  • Count points based on the number of passed/failed cases?

    Count points based on the number of passed/failed cases?

    Hi guys, I am now trying to use doctest to grade c++ code assignments, and this is my first time to use doctest. Just one question, is there any way that I can count the points based on how many testcases are passed? Or is there any way that I can perform like IF test case passed, THEN grade ++, something like that?

    Thanks a lot!

    opened by xrb936 24
  • Doctest is not able to compile on OSX

    Doctest is not able to compile on OSX

    Description

    I am trying to get my Travis CI build working with doctest (I'm switching from Catch to this for performance), but my build is not working on OSX (It is for Linux). In my Travis CI logs, I see the following error:

    Undefined symbols for architecture x86_64:
      "std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
          doctest::String doctest::detail::stringifyBinaryExpr<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char [6]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*, char const (&) [6]) in hello_world_test.cpp.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [test/test_runner] Error 1
    make[1]: *** [test/CMakeFiles/test_runner.dir/all] Error 2
    make: *** [all] Error 2
    

    Steps to reproduce

    I'm using CMake, and my invocation command is:

    cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=$COMPILER -DBUILD_TESTS=ON ..
    

    (COMPILER is set to clang++ and BUILD_TYPE is set to Debug and Release, both of which fail)

    The CMake configuration I am using is (for flags):

    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
    elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
        # ...
    endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    

    And the test configuration:

    set(TEST_SOURCES
        factorial_test.cpp
        hello_world_test.cpp
    )
    
    add_library(doctest INTERFACE)
    target_include_directories(doctest INTERFACE 
        "${CMAKE_SOURCE_DIR}/third_party/doctest" # Contains single header
    )
    
    add_executable(test_runner test_runner.cpp ${TEST_SOURCES})
    target_link_libraries(test_runner Project-Name-lib doctest)
    
    add_test(all_tests test_runner)
    

    Extra information

    • doctest version: v1.2.8
    • Operating System: Travis CI OSX XCode image 9.2
    • Compiler+version: AppleClang 9.0.0.9000039
    opened by arnavb 23
  • Add default printers for enums

    Add default printers for enums

    I've added an assertion for a function returning an enum and the enum value. When the test failed I've got pretty informative failure output {?} == {?}...

    I don't intend to write a custom printer for my enum type, but still want to see readable values when a test fails. I've workaround the problem by casting to int, but I'd prefer if the library does this for me.

    opened by obfuscated 22
  • Logo Proposal for Doctest

    Logo Proposal for Doctest

    Hi, In response to your request for Logo, I am very grateful to be able to collaborate in your project.

    I need a short review about Doctest to start with the sketches. I can improve the existing one or create something totally new and different. You can tell me your suggestions.

    opened by area55git 20
  • [Feature] Better integration with tools (VS Code Test Adapter Extension)

    [Feature] Better integration with tools (VS Code Test Adapter Extension)

    Description

    The "Catch2 and Google Test Explorer" Extension for Visual Studio Code has experimental support for doctest. However, several tests with the same name but in different tests suites can't be run. Also, the test results can't be displayed reliably inline in the source code. This could be fixed if some additional information was available from the command line.

    Could you add the possibility to list the test suites and test cases with file names and line numbers from the command line?

    This would make it possible for the extension to work reliably and give VS Code users much better usability while using doctest.

    See: https://github.com/matepek/vscode-catch2-test-adapter/issues/143#issuecomment-566092840 And: https://github.com/matepek/vscode-catch2-test-adapter/issues/143#issuecomment-566139062

    opened by wilhem-meignan 19
  • Slower than Catch in realistic test cases

    Slower than Catch in realistic test cases

    Hi,

    I did some benchmarking of doctest on my machine (Linux, gcc-4.9.3). I adapted a bit your Python script to work on Linux (with_gcc = 1 and removed the forced CMake generator).

    First, I can confirm that in the simple benchmark case, it is indeed faster to compile than Catch by a large margin. However, this is not a very realistic test case.

    I have modified the benchmark to generate 50 files, each with 25 test cases and each with 10 CHECK (using a variable and not two constants). Here are the results:

    Catch: 1 minute 56 seconds Doctest: 2 minutes 32 seconds

    In a realistic test case, doctest is significantly slower than Catch. I can see the same thing when I replace Catch by doctest in one of my large test case of my ETL library.

    Do you have any idea why this happen ?

    I can only guess that the overhead comes from the templates used to extract lhs and rhs or by the macros generating the test cases.

    opened by wichtounet 19
  • [PROJECT ANNOUNCEMENT] Looking for maintainers for Doctest

    [PROJECT ANNOUNCEMENT] Looking for maintainers for Doctest

    Working on doctest has taught me two very important lessons: how to prioritize and how to say no, and now it's time to apply them to my life. I can no longer maintain doctest properly and that's evident by my inactivity for the past 8 months - I haven't touched C++ professionally in almost 2 years and I've moved on to other things.

    I invite anyone interested in the development & maintenance of the framework to join the Discord server. I just moved doctest to a GitHub organization as suggested here and will add whoever is interested as a member. I'll release a version or two and will stick around for some time as people join in order to resolve any disputes and respond to questions and at some point, I'll promote the ones that have shown the most interest to admins & owners of the repository and the Discord server - I won't leave but I hope that by that time others would be able to reach consensus on contentious issues and I'll redirect any donations to the maintainers once this transition period is over.

    Doctest doesn't require too much work (unless new features are added) - mostly the occasional compiler bugfix & support in issues. The design goals of the framework should be followed - what made doctest successful is the art of saying no and keeping it light & easy to use.

    EDIT: some more info - https://github.com/doctest/doctest/issues/554#issuecomment-991190934

    Best regards, Viktor

    opened by onqtam 18
  • Refactor stringification

    Refactor stringification

    So StringMaker and StringStream act as a pretty much completely parallel structure. This structure will be eradicated. For the first draft I have simply removed the StringMaker's body, attaching it's head to StringStream's body.

    The customization points are broken, as well as a few other features, namely raw memory stringification likely among others.

    This (hopefully) finally fixes #571 for good!

    opened by Saalvage 16
  • Fix SUBCASE infinite loop

    Fix SUBCASE infinite loop

    • Insert and check same hash for fullyTraversedSubcases

    Description

    Change the saved hash to match the hash later checked in the Subcase constructor. This fixes an infinite loop that I encountered with at least two different nested SUBCASEs inside a loop.

    TEST_CASE("Infinite")
    {
      for (int idx = 0; idx < 2; ++idx)
      {
          SUBCASE("A")
          {
              SUBCASE("SUB A")
              {
                  std::cout << "sub a" << std::endl;
              }
          }
          SUBCASE("B")
          {
              SUBCASE("SUB B")
              {
                  std::cout << "sub b" << std::endl;
              }
          }
      }
    }
    
    opened by AlexanderHederstaf 3
  • Use of std::sprintf causes deprecation warnings on new Mac OS (Ventura)

    Use of std::sprintf causes deprecation warnings on new Mac OS (Ventura)

    Description

    The use of std::sprintf in doctest headers (used to convert integers to strings) causes warnings (because of 'deprecation') when compiling with the AppleClang compiler shipped with the new XCode version on MacOS Ventura. Any code that uses std::sprintf or sprintf will cause a warning on that compiler/stdio.h header, and suggests to use std::snprintf instead. This is, of course, overzealous in the case of number -> string conversion (unless the platform has unusually wide integers).

    Steps to reproduce

    Just compile a very small test example on that compiler where doctest has to turn a number into a string, e.g.,

    #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
    #include "doctest/doctest.h"
    #include <vector>
    
    TEST_CASE("foo") {
    	std::vector<double> foo{1.2, 1.3, 1.4};
    	CHECK(foo == std::vector<double>{1.2, 1.3, 1.4});
    }
    

    Extra information

    • doctest version: 2.4.8
    • Operating System: MacOS Ventura
    • Compiler+version: Apple clang version 14.0.0 (clang-1400.0.29.202)
    opened by phillip-keldenich 0
  • get error alignment in CHECK macro

    get error alignment in CHECK macro

    Description

    The struct dummy_4 is defined in both a.cpp and b.cpp with different alignment requirement.

    In file b.cpp TEST_CASE, error alignment got in CHECK macro.

    CHECK(alignof(dummy_4) == std::alignment_of_v<dummy_4>);
    

    see https://en.cppreference.com/w/cpp/types/alignment_of and https://en.cppreference.com/w/cpp/language/alignof .

    Steps to reproduce

    a simple project in my GitHub repo: https://github.com/PikachuHyA/doctest_demo

    file a.cpp

    #include <type_traits>
    
    #include "doctest.h"
    
    using namespace doctest;
    
    struct alignas(4) dummy_4 {
      char a;
      short b;
    };
    
    TEST_CASE("test in file a") {
      // If we remove this check statement,
      // "test in file b" will pass
      // Why?
      CHECK(std::alignment_of_v<dummy_4> == 4);
    }
    

    file b.cpp

    #include <type_traits>
    
    #include "doctest.h"
    
    using namespace doctest;
    
    #pragma pack(push, 4)
    struct dummy_4 {
      char a;
      short b;
    };
    #pragma pack(pop)
    TEST_CASE("test in file b") {
      // check fail
      // maybe bug?
      CHECK(alignof(dummy_4) == std::alignment_of_v<dummy_4>);
      // However, static_assert passed
      static_assert(alignof(dummy_4) == std::alignment_of_v<dummy_4>);
    }
    
    

    run log

    [doctest] doctest version is "2.4.9"
    [doctest] run with "--help" for options
    ===============================================================================
    /Users/shuoshu/CLionProjects/doctest_demo/b.cpp:13:
    TEST CASE:  test in file b
    
    /Users/shuoshu/CLionProjects/doctest_demo/b.cpp:16: ERROR: CHECK( alignof(dummy_4) == std::alignment_of_v<dummy_4> ) is NOT correct!
      values: CHECK( 2 == 4 )
    
    ===============================================================================
    [doctest] test cases: 2 | 1 passed | 1 failed | 0 skipped
    [doctest] assertions: 2 | 1 passed | 1 failed |
    [doctest] Status: FAILURE!
    

    Extra information

    • doctest version: v2.4.9 (the latest main branch)
    • Operating System: macOS Monterey 12.6
    • Compiler+version: clang version 14.0.6
    opened by PikachuHyA 0
  • doctest.h -- error: call of overloaded ‘log10(unsigned int)’ is ambiguous

    doctest.h -- error: call of overloaded ‘log10(unsigned int)’ is ambiguous

    Description

    Using doctest 2.4.9, as packaged with ccache, compiling with gcc on solaris (see versions below) results in:

    In file included from /export/home/briggs/ccache-4.7.1/unittest/main.cpp:27:
    /export/home/briggs/ccache-4.7.1/src/third_party/doctest.h: In member function ‘virtual void doctest::{anonymous}::ConsoleReporter::test_run_end(const doctest::TestRunStats&)’:
    /export/home/briggs/ccache-4.7.1/src/third_party/doctest.h:6191:48: error: call of overloaded ‘log10(unsigned int)’ is ambiguous
     6191 |             auto totwidth = int(std::ceil(log10((std::max(p.numTestCasesPassingFilters, static_cast<unsigned>(p.numAsserts))) + 1)));
          |                                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/math.h:24,
                     from /usr/gcc/11/include/c++/11.2.0/bits/std_abs.h:40,
                     from /usr/gcc/11/include/c++/11.2.0/cstdlib:77,
                     from /usr/gcc/11/include/c++/11.2.0/ext/string_conversions.h:41,
                     from /usr/gcc/11/include/c++/11.2.0/bits/basic_string.h:6607,
                     from /usr/gcc/11/include/c++/11.2.0/string:55,
                     from /export/home/briggs/ccache-4.7.1/src/Stat.hpp:29,
                     from /export/home/briggs/ccache-4.7.1/unittest/../src/Util.hpp:21,
                     from /export/home/briggs/ccache-4.7.1/unittest/main.cpp:19:
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:209:28: note: candidate: ‘long double std::log10(long double)’
      209 |         inline long double log10(long double __X) { return __log10l(__X); }
          |                            ^~~~~
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:170:22: note: candidate: ‘float std::log10(float)’
      170 |         inline float log10(float __X) { return __log10f(__X); }
          |                      ^~~~~
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:70:15: note: candidate: ‘double std::log10(double)’
       70 | extern double log10 __P((double));
          |               ^~~~~
    In file included from /export/home/briggs/ccache-4.7.1/unittest/main.cpp:27:
    /export/home/briggs/ccache-4.7.1/src/third_party/doctest.h:6192:49: error: call of overloaded ‘log10(unsigned int)’ is ambiguous
     6192 |             auto passwidth = int(std::ceil(log10((std::max(p.numTestCasesPassingFilters - p.numTestCasesFailed, static_cast<unsigned>(p.numAsserts - p.numAssertsFailed))) + 1)));
          |                                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/math.h:24,
                     from /usr/gcc/11/include/c++/11.2.0/bits/std_abs.h:40,
                     from /usr/gcc/11/include/c++/11.2.0/cstdlib:77,
                     from /usr/gcc/11/include/c++/11.2.0/ext/string_conversions.h:41,
                     from /usr/gcc/11/include/c++/11.2.0/bits/basic_string.h:6607,
                     from /usr/gcc/11/include/c++/11.2.0/string:55,
                     from /export/home/briggs/ccache-4.7.1/src/Stat.hpp:29,
                     from /export/home/briggs/ccache-4.7.1/unittest/../src/Util.hpp:21,
                     from /export/home/briggs/ccache-4.7.1/unittest/main.cpp:19:
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:209:28: note: candidate: ‘long double std::log10(long double)’
      209 |         inline long double log10(long double __X) { return __log10l(__X); }
          |                            ^~~~~
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:170:22: note: candidate: ‘float std::log10(float)’
      170 |         inline float log10(float __X) { return __log10f(__X); }
          |                      ^~~~~
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:70:15: note: candidate: ‘double std::log10(double)’
       70 | extern double log10 __P((double));
          |               ^~~~~
    In file included from /export/home/briggs/ccache-4.7.1/unittest/main.cpp:27:
    /export/home/briggs/ccache-4.7.1/src/third_party/doctest.h:6193:49: error: call of overloaded ‘log10(unsigned int)’ is ambiguous
     6193 |             auto failwidth = int(std::ceil(log10((std::max(p.numTestCasesFailed, static_cast<unsigned>(p.numAssertsFailed))) + 1)));
          |                                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/math.h:24,
                     from /usr/gcc/11/include/c++/11.2.0/bits/std_abs.h:40,
                     from /usr/gcc/11/include/c++/11.2.0/cstdlib:77,
                     from /usr/gcc/11/include/c++/11.2.0/ext/string_conversions.h:41,
                     from /usr/gcc/11/include/c++/11.2.0/bits/basic_string.h:6607,
                     from /usr/gcc/11/include/c++/11.2.0/string:55,
                     from /export/home/briggs/ccache-4.7.1/src/Stat.hpp:29,
                     from /export/home/briggs/ccache-4.7.1/unittest/../src/Util.hpp:21,
                     from /export/home/briggs/ccache-4.7.1/unittest/main.cpp:19:
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:209:28: note: candidate: ‘long double std::log10(long double)’
      209 |         inline long double log10(long double __X) { return __log10l(__X); }
          |                            ^~~~~
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:170:22: note: candidate: ‘float std::log10(float)’
      170 |         inline float log10(float __X) { return __log10f(__X); }
          |                      ^~~~~
    /usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.2.0/include-fixed/iso/math_iso.h:70:15: note: candidate: ‘double std::log10(double)’
       70 | extern double log10 __P((double));
          |               ^~~~~
    

    Steps to reproduce

    For ccache 4.7.1, doing

    mkdir build && cd build && cmake --build .
    

    Extra information

    • doctest version: 2.4.9
    • Operating System: Solaris 11.4
    • Compiler+version: gcc 11.2.0

    There is indeed no log10() with an integral value argument. I believe that was introduced in C++11, and I suspect that the Solaris iso/math_iso.h predates that. While Oracle ought to fix that, it seems that a cast to float would simply avoid this dependency.

    opened by nbriggs 1
  • Doctest spams several thousands warnings with memory sanitizer

    Doctest spams several thousands warnings with memory sanitizer

    Description

    When compliing doctest with memory sanitizer,

    CXX=clang++ CXXFLAGS="-fsanitize=memory -fsanitize-recover=memory -fsanitize-memory-track-origins -Og" LDFLAGS="-fsanitize=memory" cmake .;make -j6
    

    it produce thousands of warnings when executing examples/all_features/all_features

    ==110585==WARNING: MemorySanitizer: use-of-uninitialized-value
        #0 0x55573e7a1bb9 in doctest::(anonymous namespace)::wildcmp(char const*, char const*, bool) main.cpp
        #1 0x55573e75fc7b in doctest::(anonymous namespace)::matchesAny(char const*, std::vector<doctest::String, std::allocator<doctest::String> > const&, bool, bool) main.cpp
        #2 0x55573e79270a in doctest::Context::run() (/home/rafal/test/doctest/examples/all_features/all_features+0x12770a) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #3 0x55573e79e5e8 in main (/home/rafal/test/doctest/examples/all_features/all_features+0x1335e8) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #4 0x7ffb3d635d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
        #5 0x7ffb3d635e3f in __libc_start_main csu/../csu/libc-start.c:392:3
        #6 0x55573e6c0704 in _start (/home/rafal/test/doctest/examples/all_features/all_features+0x55704) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
    
      Uninitialized value was stored to memory at
        #0 0x55573e6ee709 in __msan_memcpy (/home/rafal/test/doctest/examples/all_features/all_features+0x83709) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #1 0x55573e74ea67 in doctest::String::String(doctest::String&&) (/home/rafal/test/doctest/examples/all_features/all_features+0xe3a67) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #2 0x55573e897194 in void __gnu_cxx::new_allocator<doctest::String>::construct<doctest::String, doctest::String>(doctest::String*, doctest::String&&) (/home/rafal/test/doctest/examples/all_features/all_features+0x22c194) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #3 0x55573e89576b in void std::allocator_traits<std::allocator<doctest::String> >::construct<doctest::String, doctest::String>(std::allocator<doctest::String>&, doctest::String*, doctest::String&&) (/home/rafal/test/doctest/examples/all_features/all_features+0x22a76b) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #4 0x55573e8963ad in void std::vector<doctest::String, std::allocator<doctest::String> >::_M_realloc_insert<doctest::String>(__gnu_cxx::__normal_iterator<doctest::String*, std::vector<doctest::String, std::allocator<doctest::String> > >, doctest::String&&) (/home/rafal/test/doctest/examples/all_features/all_features+0x22b3ad) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #5 0x55573e895435 in void std::vector<doctest::String, std::allocator<doctest::String> >::emplace_back<doctest::String>(doctest::String&&) (/home/rafal/test/doctest/examples/all_features/all_features+0x22a435) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #6 0x55573e817311 in std::vector<doctest::String, std::allocator<doctest::String> >::push_back(doctest::String&&) (/home/rafal/test/doctest/examples/all_features/all_features+0x1ac311) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #7 0x55573e7a2a51 in doctest::(anonymous namespace)::parseCommaSepArgs(int, char const* const*, char const*, std::vector<doctest::String, std::allocator<doctest::String> >&)::$_2::operator()() const main.cpp
        #8 0x55573e786aad in doctest::(anonymous namespace)::parseCommaSepArgs(int, char const* const*, char const*, std::vector<doctest::String, std::allocator<doctest::String> >&) main.cpp
        #9 0x55573e7786e1 in doctest::Context::parseArgs(int, char const* const*, bool) (/home/rafal/test/doctest/examples/all_features/all_features+0x10d6e1) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #10 0x55573e7896ca in doctest::Context::setOption(char const*, char const*) (/home/rafal/test/doctest/examples/all_features/all_features+0x11e6ca) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #11 0x55573e788e0c in doctest::Context::addFilter(char const*, char const*) (/home/rafal/test/doctest/examples/all_features/all_features+0x11de0c) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #12 0x55573e79e472 in main (/home/rafal/test/doctest/examples/all_features/all_features+0x133472) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #13 0x7ffb3d635d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    
      Uninitialized value was stored to memory at
        #0 0x55573e6ee709 in __msan_memcpy (/home/rafal/test/doctest/examples/all_features/all_features+0x83709) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #1 0x55573e74c1e4 in doctest::String::String(char const*, unsigned int) (/home/rafal/test/doctest/examples/all_features/all_features+0xe11e4) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #2 0x55573e74bdd1 in doctest::String::String(char const*) (/home/rafal/test/doctest/examples/all_features/all_features+0xe0dd1) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #3 0x55573e7a2a11 in doctest::(anonymous namespace)::parseCommaSepArgs(int, char const* const*, char const*, std::vector<doctest::String, std::allocator<doctest::String> >&)::$_2::operator()() const main.cpp
        #4 0x55573e786aad in doctest::(anonymous namespace)::parseCommaSepArgs(int, char const* const*, char const*, std::vector<doctest::String, std::allocator<doctest::String> >&) main.cpp
        #5 0x55573e7786e1 in doctest::Context::parseArgs(int, char const* const*, bool) (/home/rafal/test/doctest/examples/all_features/all_features+0x10d6e1) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #6 0x55573e7896ca in doctest::Context::setOption(char const*, char const*) (/home/rafal/test/doctest/examples/all_features/all_features+0x11e6ca) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #7 0x55573e788e0c in doctest::Context::addFilter(char const*, char const*) (/home/rafal/test/doctest/examples/all_features/all_features+0x11de0c) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #8 0x55573e79e472 in main (/home/rafal/test/doctest/examples/all_features/all_features+0x133472) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #9 0x7ffb3d635d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    
      Uninitialized value was stored to memory at
        #0 0x55573e6ee709 in __msan_memcpy (/home/rafal/test/doctest/examples/all_features/all_features+0x83709) (BuildId: 3ea1d43b0b3e71f1d4967436582f7754d57a2e19)
        #1 0x7ffb3da87ee4 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long) (/lib/x86_64-linux-gnu/libstdc++.so.6+0x14cee4) (BuildId: f57e02bfadacc0c923c82457d5e18e1830b5faea)
    
      Uninitialized value was created by an allocation of 's' in the stack frame of function '_ZN7doctest12_GLOBAL__N_117parseCommaSepArgsEiPKPKcS2_RSt6vectorINS_6StringESaIS6_EE'
        #0 0x55573e785720 in doctest::(anonymous namespace)::parseCommaSepArgs(int, char const* const*, char const*, std::vector<doctest::String, std::allocator<doctest::String> >&) main.cpp
    
    SUMMARY: MemorySanitizer: use-of-uninitialized-value main.cpp in doctest::(anonymous namespace)::wildcmp(char const*, char const*, bool)
    
    

    Extra information

    • doctest version: Git
    • Operating System: Ubuntu 22.04
    • Compiler+version: Clang 14
    opened by qarmin 1
Releases(v2.4.9)
Owner
Viktor Kirilov
Working on Nimbus - an Ethereum 1.0 & 2.0 Client for Resource-Restricted Devices.
Viktor Kirilov
A unit testing framework for C

Check Table of Contents About Installing Linking Packaging About Check is a unit testing framework for C. It features a simple interface for defining

null 923 Nov 27, 2022
CppUTest unit testing and mocking framework for C/C++

CppUTest CppUTest unit testing and mocking framework for C/C++ More information on the project page Slack channel: Join if link not expired Getting St

CppUTest 1.1k Nov 26, 2022
A testing micro framework for creating function test doubles

Fake Function Framework (fff) A Fake Function Framework for C Hello Fake World! Capturing Arguments Return Values Resetting a Fake Call History Defaul

Mike Long 540 Dec 1, 2022
Googletest - Google Testing and Mocking Framework

GoogleTest OSS Builds Status Announcements Release 1.10.x Release 1.10.x is now available. Coming Soon Post 1.10.x googletest will follow Abseil Live

Google 28.5k Nov 25, 2022
Minimal unit testing framework for C

MinUnit Minunit is a minimal unit testing framework for C/C++ self-contained in a single header file. It provides a way to define and configure test s

David Siñuela Pastor 451 Nov 18, 2022
A lightweight unit testing framework for C++

Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 26 November 2020. Subscribe to https://github.com/unittest-cpp/unittest-cp

UnitTest++ 509 Nov 24, 2022
UT: C++20 μ(micro)/Unit Testing Framework

"If you liked it then you "should have put a"_test on it", Beyonce rule [Boost::ext].UT / μt | Motivation | Quick Start | Overview | Tutorial | Exampl

boost::ext 929 Nov 26, 2022
🍦IceCream-Cpp is a little (single header) library to help with the print debugging on C++11 and forward.

??IceCream-Cpp is a little (single header) library to help with the print debugging on C++11 and forward.

Renato Garcia 415 Nov 30, 2022
Simple Unit Testing for C

Unity Test Copyright (c) 2007 - 2021 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams Welcome to the Unity Test Project, one of the

Throw The Switch 2.8k Nov 24, 2022
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)

Catch2 v3 is being developed! You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rewo

Catch Org 15.9k Nov 25, 2022
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)

Catch2 v3 is being developed! You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rewo

Catch Org 15.9k Nov 24, 2022
Single C file, Realtime CPU/GPU Profiler with Remote Web Viewer

Remotery A realtime CPU/GPU profiler hosted in a single C file with a viewer that runs in a web browser. Supported Platforms: Windows Windows UWP (Hol

Celtoys 2.4k Nov 22, 2022
C++ Benchmark Authoring Library/Framework

Celero C++ Benchmarking Library Copyright 2017-2019 John Farrier Apache 2.0 License Community Support A Special Thanks to the following corporations f

John Farrier 723 Nov 24, 2022
A C++ micro-benchmarking framework

Nonius What is nonius? Nonius is an open-source framework for benchmarking small snippets of C++ code. It is very heavily inspired by Criterion, a sim

Nonius 338 Nov 28, 2022
test framework

Photesthesis This is a small, experimental parameterized-testing tool. It is intended to be used in concert with another unit-testing framework (eg. C

Graydon Hoare 11 Jun 2, 2021
A simple framework for compile-time benchmarks

Metabench A simple framework for compile-time microbenchmarks Overview Metabench is a single, self-contained CMake module making it easy to create com

Louis Dionne 162 Oct 23, 2022
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch Windows All dev branch Windows All doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of

Viktor Kirilov 4.4k Dec 1, 2022
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch dev branch doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of magnitude) and runtime c

null 4.4k Dec 2, 2022
A modern, feature-rich single header C++ interface system for GLFW

A modern, feature-rich single header C++ interface system for GLFW

Vortex 3 Dec 27, 2021
✔️The smallest header-only GUI library(4 KLOC) for all platforms

Welcome to GUI-lite The smallest header-only GUI library (4 KLOC) for all platforms. 中文 Lightweight ✂️ Small: 4,000+ lines of C++ code, zero dependenc

null 6.5k Nov 24, 2022