-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
moved from Catch to doctest for unit tests #1439
Conversation
Wow! Thanks for the PR. I need some time to evaluate this. Thanks for your patience in advance. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@nlohmann if there is any other feature you might need - I'm open to suggestions :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Sorry for letting this get stale twice... I am now ready to have a deeper look at this. I just restarted AppVeyor to see whether the build now succeeds. |
Just merged develop again and the problems went away. Also updated to doctest 2.3.1 (released today) |
(Ignore my previous post - I checked the wrong branch) |
I compared the compile times, and I am impressed! doctest / Debugninja 179.30s user 11.26s system 633% cpu 30.100 total doctest / Releaseninja 337.00s user 11.86s system 639% cpu 54.532 total catch / Debugninja 242.05s user 13.68s system 650% cpu 39.308 total catch / Releaseninja 464.38s user 14.94s system 669% cpu 1:11.55 total |
I also compared the runtimes, and I am even more impressed! doctest / ReleaseTotal Test time (real) = 197.95 sec catch / ReleaseTotal Test time (real) = 242.26 sec |
test/CMakeLists.txt
Outdated
endif() | ||
target_include_directories(catch_main PRIVATE "thirdparty/catch") | ||
|
||
target_compile_features(doctest_main PUBLIC cxx_std_11) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you do not need the if
here? This may be an issue for CMake versions prior 3.8.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct - I assumed initially that the 3.8
check was for cxx_range_for
but it was indeed if cxx_std_11
is supported. Adding it back again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it was without that check up until commit 4fd9b52 and it used to work - guess people didn't try the tests with a CMake version older than 3.8.
For doctest 2.x C++11 is actually mandatory. For new compilers such as gcc 7/8 C++11 is on by default, but for older ones like 4.x/5 (and maybe 6) C++11 has to be explicitly stated. So I'll add -std=c++0x
to the CXX_FLAGS
property for the target if cmake < 3.8 (or the CXX_STANDARD
property)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it - cxx_range_for
is not for that particular feature but for "c++0x" support in general - and was one of the first C++11 features to be added to compilers so cxx_range_for
was added as a compile feature long before cxx_std_11
...... So I'll just revert the code to have that same exact if/else so I don't have to deal with CXX_STANDARD
I just tried the |
I had totally missed that makefile with the pedantic warnings. Currently I don't have a Unix machine on hand to test it... I'll try to get my hands on one in a few days. Could you paste a build log? I might be able to fix some (or most) of them just by looking at it. Have you thought about integrating that makefile to the CI or perhaps moving its function to CMake? This is what doctest does for setting the highest warning levels that I thought of. EDIT: I also just ran a build locally on a windows machine with GCC 8.1 and I got 303 warnings |
…way to get -std=c++0x support
I actually found why the Catch code didn't give the As a solution for the json warning we could indeed do the following in the compatibility header: #undef CHECK_THROWS
#undef CHECK_THROWS_AS
#undef CHECK_THROWS_WITH
#undef CHECK_NOTHROW
#define CHECK_THROWS(expr) DOCTEST_CHECK_THROWS(static_cast<void>(expr))
#define CHECK_THROWS_AS(expr, e) DOCTEST_CHECK_THROWS_AS(static_cast<void>(expr), e)
#define CHECK_THROWS_WITH(expr, e) DOCTEST_CHECK_THROWS_WITH(static_cast<void>(expr), e)
#define CHECK_NOTHROW(expr) DOCTEST_CHECK_NOTHROW(static_cast<void>(expr))
// TODO: Same with WARN and REQUIRE levels of asserts which aren't yet used by json This also has the effect that the Let me know how you would want to proceed with this specific issue and if there are any other warnings to take care of. EDIT: the doozer CI buil failed - no idea what that is. |
Sorry for the noise with doozer - it is a CI which I am evaluating. I now disabled building pull requests. The message should disappear with the next commit. |
Here are the warnings from clang: clang_warnings.txt. There are no warnings reported in the |
So here is the breakdown:
Let me know how you think we should proceed. |
I'm fine with whatever changes you propose, and I'd rather have changes locally (best: at one place like the compatibility header) than silencing warnings. |
Ok, I'll look into this tonight and probably push something. |
And here are the warnings from GCC: gcc_warnings.txt. |
Try the latest version of the branch and let me know |
There is one Clang warning left:
These are the remaining GCC warnings: Meanwhile, also #1551 is merged, which should resolve all nodiscard-related issues. |
let me know if there is anything left |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
Contributor entry
|
Thanks a lot for your patience! |
Thanks for the interest in doctest in the first place - almost 1.5 years ago :) |
I did this migration since there was interest for moving from Catch to doctest more than 1 year ago:
a8233c7
Here are the changes I had to make:
doctest_compatibility.h
) which includes the actualdoctest.h
header and introduces/changes a few macros in order to have the least amount of source control modifications in the commit.#define private public
because MSVC STL headers complain about redefining C++ keywords (otherwise the first STL header would come fromjson.hpp
which is after the defining)SECTION
was used inside of a loop with different filenames were rewritten to be just normal scopes with additional logging since it is practically the same (and doctest doesn't support sections (subcases) in loops with changing names) - it is weird anyway.CAPTURE
(orINFO
) was using a temporary - doctest forbids this - see notes in docs (done for runtime performance reasons):https://github.com/onqtam/doctest/blob/master/doc/markdown/logging.md#logging-macros
[!throws]
test cases are conditionally not compiled if exceptions are disabled (was done that way in 1 other place already)[udt]
user defined tag migrated to a test suite decorator (can be filtered from the command line using test suite filters)unit-allocator.cpp
) because code such asbad_json(bad_json::value_t::object)
wouldn't compile with MSVC 2017 - even outside of a macro such asCHECK_THROWS_AS
and into a simple function (without even including the framework header). Errors and warnings such as these were present:some notes:
JSON_PRIVATE
macro which is eitherprivate
orpublic
for the test framework internals - this definition of a C++ keyword is nastyCAPTURE
inside of hot functions such ascheck_utf8string
doesn't make allocations and construct strings unless an assert fails!It seems that tests are ran around 10-35% faster on the CI - I was hoping for more but this is good as well. Even if doctest is 100 times faster (which isn't true), if only 30% of the total time is due to the testing framework, then the maximum gains expected are up to 30% for the whole build time. The
Total time
on travis drops down from around 12 hours 20 minutes to 9 hours 30 minutes.When building the tests locally on a Windows machine (single threaded build) with GCC 8.1 (default cmake config) it takes for me 4 minutes 50 seconds for doctest and 7 minutes 46 seconds for Catch. Perhaps the use of a precompiled header for the json header would be of some help (10-20 seconds? ...) but would be harder to employ the
#define private public
hack.In the case of some of the OSX builds - more than half of the time is installing stuff...