Open mathbunnyru opened 5 days ago
One more think to make it work - we will need to slightly change StringMaker - it should be easy: https://github.com/catchorg/Catch2/blob/devel/docs/tostring.md#catchstringmaker-specialisation
(in our case we will only need to change the namespace
, make it return std::string
instead of String
and slightly fix return statements (they will become easier, and overall it will be more efficient)).
Before doing all that (I will need to change it for the whole repo), I would like to hear what mamba team thinks about changing test framework.
Thanks for tackling this! I agree that we might migrate from an unmaintai framework to a maintained one, and Catch2 seems to be the best candidate to me (I had really bad experiences with gtest in the past). The overall approach in this PR looks good to me.
I've had a bad enough experience with gtest that I've done a gtest -> catch2 transition before in CLI11. It was worth it. :) I think doctest was really supposed to be a faster clone of catch2, and then catch2 got a lot faster with 3.0 (catch2 3.0 seems like odd versioning...), so doctest kind of doesn't have a point anymore.
Perfect, I'm glad to see support to my proposal.
Implementation update: I first thought I would have to replace TEST_SUITE
using Catch2 tags.
It seems completely unnecessary - there is a --filenames-as-tags
which allows to use test filenames as tags, and in most cases TEST_SUITE
was simply having something similar to a file name.
So I can simply replace TEST_SUITE(name) {
with namespace {
for now - this will create an anonymous namespace (no harm in that in case of tests), but the diff will be minimal.
And moreover, only some tests were using the TEST_SUITE
feature, but now it will be universal (and no need to think about the test suite name).
This is how it looks:
SOME_LONG_PATH/test_solv_cpp --list-tags --filenames-as-tags
All available tags:
2 [#test_pool]
15 [#test_queue]
1 [#test_repo]
2 [#test_scenarios]
1 [#test_solvable]
1 [#test_solver]
1 [#test_transaction]
7 tags
On the left is the number of TEST_CASE
s, which seems to be correct
I left CHECK
s instead of REQUIRE
s in 3 places (meaning they will report as failed in the end but won't stop tests execution):
libmamba/tests/src/core/test_virtual_packages.cpp
77: CHECK(Version::parse(pkgs[1].version).value() > Version());
libmamba/tests/src/util/test_os_osx.cpp
24: CHECK(maybe_version.has_value());
29: CHECK(std ::regex_match(maybe_version.value(), version_regex));
These tests don't work properly on my M2 mac, unfortunately (the same is true with doctest).
libmamba/tests/src/core/test_cpp.cpp
91- // Note: this was initially a value-parametrized test; unfortunately,
92: // doctest does not support this feature yet.
93- TEST_CASE("prompt")
94- {
I think I will take a look if there is something nice in Catch, but I don't want to change the tests themselves, so I won't do it in this PR (and this is the only mentions of doctest
in my branch, except CHANGELOGs)
This is ready for reviewing, if someone wants to 😆
Why: mostly because
doctest
doesn't seem to be well supported: https://github.com/doctest/doctest/issues/554 Last commit tomain
was March 15, 2023, todev
there were only 8 commits after that.Catch2
last commit was last week, and the project is incredibly popular.Please, let me know what you think. If we decide to switch to Catch2, I will switch in all the repo.
My personal opinion:
Catch2
is easy to use, fast enough, well supported, and feels quite modern.How to switch from
doctest
toCatch2
(easy things):cmake
forfind_package
andtarget_link_libraries
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
->#define CATCH_CONFIG_MAIN
#include <doctest/doctest.h>
->#include <catch2/catch_all.hpp>
SUBCASE
->SECTION
CHECK
->REQUIRE
,CHECK_FALSE
->REQUIRE_FALSE
CHECK_EQ(a, b);
and so on ->REQUIRE(a == b);
(can be almost done with regex replacement, a bit messy when there are commas ina
orb
)A bit more complicated:
TEST_SUITE
- doesn't exist in Catch2, but we can use tags, a second arg toTEST_CASE
. I also added brackets to tag, because this is how tags look like in Catch2.Notes:
doctest is modeled after [Catch](https://github.com/catchorg/Catch2) and some parts of the code have been taken directly
(https://github.com/doctest/doctest), that's why the switch is relatively easyTEST_SUITE
was used, I addednamespace {}
, it allows to keep indentation the same so the diff is simpleREQUIRE
andCHECK
in Catch2, the difference is: TheREQUIRE
family of macros tests an expression and aborts the test case if it fails. TheCHECK
family are equivalent but execution continues in the same test case even if the assertion fails. I useREQUIRE
to fail fast.