bindings: cxx: Migrate C++ tests to use Catch2 v3
PATCH 1/1 bindings: cxx: Migrate C++ tests to use Catch2 v3
Catch2 v3.x has API changes which needs to be addressed in the tests themselves, hence this changeset is to fix those.
--- bindings/cxx/tests/Makefile.am | 2 +- bindings/cxx/tests/gpiod-cxx-test-main.cpp | 3 +-- bindings/cxx/tests/helpers.hpp | 8 +++--- bindings/cxx/tests/tests-chip-info.cpp | 30 ++++++++++----------- bindings/cxx/tests/tests-chip.cpp | 14 +++++----- bindings/cxx/tests/tests-edge-event.cpp | 2 +- bindings/cxx/tests/tests-info-event.cpp | 2 +- bindings/cxx/tests/tests-line-config.cpp | 2 +- bindings/cxx/tests/tests-line-info.cpp | 22 +++++++-------- bindings/cxx/tests/tests-line-request.cpp | 16 +++++------ bindings/cxx/tests/tests-line-settings.cpp | 2 +- bindings/cxx/tests/tests-line.cpp | 2 +- bindings/cxx/tests/tests-misc.cpp | 2 +- bindings/cxx/tests/tests-request-config.cpp | 10 +++---- configure.ac | 4 +-- 15 files changed, 60 insertions(+), 61 deletions(-)
bindings/cxx/tests/Makefile.am +1 -1
@@ -4,7 +4,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/bindings/cxx/ -I$(top_srcdir)/include AM_CXXFLAGS += -I$(top_srcdir)/tests/gpiosim/ AM_CXXFLAGS += -Wall -Wextra -g -std=gnu++17 $(CATCH2_CFLAGS) -AM_LDFLAGS = -pthread +AM_LDFLAGS = -pthread $(CATCH2_LIBS) LDADD = $(top_builddir)/bindings/cxx/libgpiodcxx.la LDADD += $(top_builddir)/tests/gpiosim/libgpiosim.la
bindings/cxx/tests/gpiod-cxx-test-main.cpp +1 -2
@@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> -#define CATCH_CONFIG_MAIN -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp>
bindings/cxx/tests/helpers.hpp +4 -4
@@ -4,13 +4,13 @@ #ifndef __GPIOD_CXX_TEST_HELPERS_HPP__ #define __GPIOD_CXX_TEST_HELPERS_HPP__ -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <regex> #include <string> #include <sstream> #include <system_error> -class system_error_matcher : public Catch::MatcherBase<::std::system_error> +class system_error_matcher : public Catch::Matchers::MatcherBase<::std::system_error> { public: explicit system_error_matcher(int expected_errno);
@@ -21,7 +21,7 @@ private: ::std::error_condition _m_cond; }; -class regex_matcher : public Catch::MatcherBase<::std::string> +class regex_matcher : public Catch::Matchers::MatcherBase<::std::string> { public: explicit regex_matcher(const ::std::string& pattern);
@@ -33,7 +33,7 @@ private: ::std::string _m_repr; }; -template<class T> class stringify_matcher : public Catch::MatcherBase<T> +template<class T> class stringify_matcher : public Catch::Matchers::MatcherBase<T> { public: explicit stringify_matcher(const ::std::string& expected) : _m_expected(expected)
bindings/cxx/tests/tests-chip-info.cpp +15 -15
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include <sstream>
@@ -24,12 +24,12 @@ TEST_CASE("chip_info properties can be read", "[chip-info][chip]") SECTION("get chip name") { - REQUIRE_THAT(info.name(), Catch::Equals(sim.name())); + REQUIRE_THAT(info.name(), Catch::Matchers::Equals(sim.name())); } SECTION("get chip label") { - REQUIRE_THAT(info.label(), Catch::Equals("foobar")); + REQUIRE_THAT(info.label(), Catch::Matchers::Equals("foobar")); } SECTION("get num_lines")
@@ -52,12 +52,12 @@ TEST_CASE("chip_info can be copied and moved", "[chip-info]") { auto copy(info); - REQUIRE_THAT(copy.name(), Catch::Equals(sim.name())); - REQUIRE_THAT(copy.label(), Catch::Equals("foobar")); + REQUIRE_THAT(copy.name(), Catch::Matchers::Equals(sim.name())); + REQUIRE_THAT(copy.label(), Catch::Matchers::Equals("foobar")); REQUIRE(copy.num_lines() == 4); - REQUIRE_THAT(info.name(), Catch::Equals(sim.name())); - REQUIRE_THAT(info.label(), Catch::Equals("foobar")); + REQUIRE_THAT(info.name(), Catch::Matchers::Equals(sim.name())); + REQUIRE_THAT(info.label(), Catch::Matchers::Equals("foobar")); REQUIRE(info.num_lines() == 4); }
@@ -67,12 +67,12 @@ TEST_CASE("chip_info can be copied and moved", "[chip-info]") copy = info; - REQUIRE_THAT(copy.name(), Catch::Equals(sim.name())); - REQUIRE_THAT(copy.label(), Catch::Equals("foobar")); + REQUIRE_THAT(copy.name(), Catch::Matchers::Equals(sim.name())); + REQUIRE_THAT(copy.label(), Catch::Matchers::Equals("foobar")); REQUIRE(copy.num_lines() == 4); - REQUIRE_THAT(info.name(), Catch::Equals(sim.name())); - REQUIRE_THAT(info.label(), Catch::Equals("foobar")); + REQUIRE_THAT(info.name(), Catch::Matchers::Equals(sim.name())); + REQUIRE_THAT(info.label(), Catch::Matchers::Equals("foobar")); REQUIRE(info.num_lines() == 4); }
@@ -80,8 +80,8 @@ TEST_CASE("chip_info can be copied and moved", "[chip-info]") { auto moved(std::move(info)); - REQUIRE_THAT(moved.name(), Catch::Equals(sim.name())); - REQUIRE_THAT(moved.label(), Catch::Equals("foobar")); + REQUIRE_THAT(moved.name(), Catch::Matchers::Equals(sim.name())); + REQUIRE_THAT(moved.label(), Catch::Matchers::Equals("foobar")); REQUIRE(moved.num_lines() == 4); }
@@ -91,8 +91,8 @@ TEST_CASE("chip_info can be copied and moved", "[chip-info]") moved = ::std::move(info); - REQUIRE_THAT(moved.name(), Catch::Equals(sim.name())); - REQUIRE_THAT(moved.label(), Catch::Equals("foobar")); + REQUIRE_THAT(moved.name(), Catch::Matchers::Equals(sim.name())); + REQUIRE_THAT(moved.label(), Catch::Matchers::Equals("foobar")); REQUIRE(moved.num_lines() == 4); } }
bindings/cxx/tests/tests-chip.cpp +7 -7
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include <sstream> #include <system_error>
@@ -48,9 +48,9 @@ TEST_CASE("chip constructor works", "[chip]") .build(); ::gpiod::chip first(sim.dev_path()); - REQUIRE_THAT(first.get_info().label(), Catch::Equals("foobar")); + REQUIRE_THAT(first.get_info().label(), Catch::Matchers::Equals("foobar")); ::gpiod::chip second(::std::move(first)); - REQUIRE_THAT(second.get_info().label(), Catch::Equals("foobar")); + REQUIRE_THAT(second.get_info().label(), Catch::Matchers::Equals("foobar")); } }
@@ -70,9 +70,9 @@ TEST_CASE("chip operators work", "[chip]") ::gpiod::chip moved_chip(moved_sim.dev_path()); - REQUIRE_THAT(chip.get_info().label(), Catch::Equals("foobar")); + REQUIRE_THAT(chip.get_info().label(), Catch::Matchers::Equals("foobar")); chip = ::std::move(moved_chip); - REQUIRE_THAT(chip.get_info().label(), Catch::Equals("moved")); + REQUIRE_THAT(chip.get_info().label(), Catch::Matchers::Equals("moved")); } SECTION("boolean operator")
@@ -94,7 +94,7 @@ TEST_CASE("chip properties can be read", "[chip]") SECTION("get device path") { - REQUIRE_THAT(chip.path(), Catch::Equals(sim.dev_path())); + REQUIRE_THAT(chip.path(), Catch::Matchers::Equals(sim.dev_path())); } SECTION("get file descriptor")
@@ -169,7 +169,7 @@ TEST_CASE("stream insertion operator works for chip", "[chip]") "\", label=\"foobar\", num_lines=4))"; buf << chip; - REQUIRE_THAT(buf.str(), Catch::Equals(expected.str())); + REQUIRE_THAT(buf.str(), Catch::Matchers::Equals(expected.str())); } SECTION("closed chip")
bindings/cxx/tests/tests-edge-event.cpp +1 -1
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <chrono> #include <gpiod.hpp> #include <sstream>
bindings/cxx/tests/tests-info-event.cpp +1 -1
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <chrono> #include <filesystem> #include <gpiod.hpp>
bindings/cxx/tests/tests-line-config.cpp +1 -1
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include "gpiosim.hpp"
bindings/cxx/tests/tests-line-info.cpp +11 -11
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include <string>
@@ -35,9 +35,9 @@ TEST_CASE("get_line_info() works", "[chip][line-info]") auto info = chip.get_line_info(0); REQUIRE(info.offset() == 0); - REQUIRE_THAT(info.name(), Catch::Equals("foobar")); + REQUIRE_THAT(info.name(), Catch::Matchers::Equals("foobar")); REQUIRE(info.used()); - REQUIRE_THAT(info.consumer(), Catch::Equals("hog")); + REQUIRE_THAT(info.consumer(), Catch::Matchers::Equals("hog")); REQUIRE(info.direction() == ::gpiod::line::direction::OUTPUT); REQUIRE_FALSE(info.active_low()); REQUIRE(info.bias() == ::gpiod::line::bias::UNKNOWN);
@@ -74,9 +74,9 @@ TEST_CASE("line properties can be retrieved", "[line-info]") auto info6 = chip.get_line_info(6); REQUIRE(info4.offset() == 4); - REQUIRE_THAT(info4.name(), Catch::Equals("baz")); + REQUIRE_THAT(info4.name(), Catch::Matchers::Equals("baz")); REQUIRE(info4.used()); - REQUIRE_THAT(info4.consumer(), Catch::Equals("hog4")); + REQUIRE_THAT(info4.consumer(), Catch::Matchers::Equals("hog4")); REQUIRE(info4.direction() == direction::OUTPUT); REQUIRE(info4.edge_detection() == edge::NONE); REQUIRE_FALSE(info4.active_low());
@@ -102,10 +102,10 @@ TEST_CASE("line_info can be copied and moved") { auto copy(info); REQUIRE(copy.offset() == 2); - REQUIRE_THAT(copy.name(), Catch::Equals("foobar")); + REQUIRE_THAT(copy.name(), Catch::Matchers::Equals("foobar")); /* info can still be used */ REQUIRE(info.offset() == 2); - REQUIRE_THAT(info.name(), Catch::Equals("foobar")); + REQUIRE_THAT(info.name(), Catch::Matchers::Equals("foobar")); } SECTION("assignment operator works")
@@ -113,17 +113,17 @@ TEST_CASE("line_info can be copied and moved") auto copy = chip.get_line_info(0); copy = info; REQUIRE(copy.offset() == 2); - REQUIRE_THAT(copy.name(), Catch::Equals("foobar")); + REQUIRE_THAT(copy.name(), Catch::Matchers::Equals("foobar")); /* info can still be used */ REQUIRE(info.offset() == 2); - REQUIRE_THAT(info.name(), Catch::Equals("foobar")); + REQUIRE_THAT(info.name(), Catch::Matchers::Equals("foobar")); } SECTION("move constructor works") { auto copy(::std::move(info)); REQUIRE(copy.offset() == 2); - REQUIRE_THAT(copy.name(), Catch::Equals("foobar")); + REQUIRE_THAT(copy.name(), Catch::Matchers::Equals("foobar")); } SECTION("move assignment operator works")
@@ -131,7 +131,7 @@ TEST_CASE("line_info can be copied and moved") auto copy = chip.get_line_info(0); copy = ::std::move(info); REQUIRE(copy.offset() == 2); - REQUIRE_THAT(copy.name(), Catch::Equals("foobar")); + REQUIRE_THAT(copy.name(), Catch::Matchers::Equals("foobar")); } }
bindings/cxx/tests/tests-line-request.cpp +8 -8
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include <sstream> #include <stdexcept>
@@ -20,7 +20,7 @@ using pull = ::gpiosim::chip::pull; namespace { -class value_matcher : public Catch::MatcherBase<value> +class value_matcher : public Catch::Matchers::MatcherBase<value> { public: value_matcher(pull pull, bool active_low = false)
@@ -117,7 +117,7 @@ TEST_CASE("consumer string is set correctly", "[line-request]") auto info = chip.get_line_info(2); REQUIRE(info.used()); - REQUIRE_THAT(info.consumer(), Catch::Equals("foobar")); + REQUIRE_THAT(info.consumer(), Catch::Matchers::Equals("foobar")); } SECTION("empty consumer")
@@ -130,7 +130,7 @@ TEST_CASE("consumer string is set correctly", "[line-request]") auto info = chip.get_line_info(2); REQUIRE(info.used()); - REQUIRE_THAT(info.consumer(), Catch::Equals("?")); + REQUIRE_THAT(info.consumer(), Catch::Matchers::Equals("?")); } }
@@ -380,7 +380,7 @@ TEST_CASE("line_request can be moved", "[line-request]") auto moved(::std::move(request)); REQUIRE(moved.fd() == fd); - REQUIRE_THAT(moved.offsets(), Catch::Equals(offs)); + REQUIRE_THAT(moved.offsets(), Catch::Matchers::Equals(offs)); } SECTION("move assignment operator works")
@@ -388,7 +388,7 @@ TEST_CASE("line_request can be moved", "[line-request]") another = ::std::move(request); REQUIRE(another.fd() == fd); - REQUIRE_THAT(another.offsets(), Catch::Equals(offs)); + REQUIRE_THAT(another.offsets(), Catch::Matchers::Equals(offs)); } }
@@ -484,7 +484,7 @@ TEST_CASE("line_request stream insertion operator works", "[line-request]") { buf << request; - REQUIRE_THAT(buf.str(), Catch::Equals(expected.str())); + REQUIRE_THAT(buf.str(), Catch::Matchers::Equals(expected.str())); } SECTION("request released")
@@ -493,7 +493,7 @@ TEST_CASE("line_request stream insertion operator works", "[line-request]") buf << request; - REQUIRE_THAT(buf.str(), Catch::Equals("gpiod::line_request(released)")); + REQUIRE_THAT(buf.str(), Catch::Matchers::Equals("gpiod::line_request(released)")); } }
bindings/cxx/tests/tests-line-settings.cpp +1 -1
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include "helpers.hpp"
bindings/cxx/tests/tests-line.cpp +1 -1
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <gpiod.hpp> #include "helpers.hpp"
bindings/cxx/tests/tests-misc.cpp +1 -1
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <filesystem> #include <gpiod.hpp> #include <string>
bindings/cxx/tests/tests-request-config.cpp +5 -5
@@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> -#include <catch2/catch.hpp> +#include <catch2/catch_all.hpp> #include <cstddef> #include <gpiod.hpp> #include <string>
@@ -33,7 +33,7 @@ TEST_CASE("request_config can be moved", "[request-config]") SECTION("move constructor works") { auto moved(::std::move(cfg)); - REQUIRE_THAT(moved.consumer(), Catch::Equals("foobar")); + REQUIRE_THAT(moved.consumer(), Catch::Matchers::Equals("foobar")); REQUIRE(moved.event_buffer_size() == 64); }
@@ -43,7 +43,7 @@ TEST_CASE("request_config can be moved", "[request-config]") moved = ::std::move(cfg); - REQUIRE_THAT(moved.consumer(), Catch::Equals("foobar")); + REQUIRE_THAT(moved.consumer(), Catch::Matchers::Equals("foobar")); REQUIRE(moved.event_buffer_size() == 64); } }
@@ -55,7 +55,7 @@ TEST_CASE("request_config mutators work", "[request-config]") SECTION("set consumer") { cfg.set_consumer("foobar"); - REQUIRE_THAT(cfg.consumer(), Catch::Equals("foobar")); + REQUIRE_THAT(cfg.consumer(), Catch::Matchers::Equals("foobar")); } SECTION("set event_buffer_size")
@@ -77,7 +77,7 @@ TEST_CASE("request_config stream insertion operator works", "[request-config]") ::std::string expected("gpiod::request_config(consumer='foobar', event_buffer_size=32)"); - REQUIRE_THAT(buf.str(), Catch::Equals(expected)); + REQUIRE_THAT(buf.str(), Catch::Matchers::Equals(expected)); } } /* namespace */
configure.ac +2 -2
@@ -206,9 +206,9 @@ then if test "x$with_tests" = xtrue then - PKG_CHECK_MODULES([CATCH2], [catch2],, [ + PKG_CHECK_MODULES([CATCH2], [catch2-with-main],, [ AC_LANG_PUSH([C++]) - AC_CHECK_HEADERS([catch2/catch.hpp], [], [HEADER_NOT_FOUND_CXX([catch2/catch.hpp])]) + AC_CHECK_HEADERS([catch2/catch_all.hpp], [], [HEADER_NOT_FOUND_CXX([catch2/catch_all.hpp])]) AC_LANG_POP([C++]) ]) fi
Quoted 8 lines · Khem Raj
Catch2 v3.x has API changes which needs to be addressed in the tests themselves, hence this changeset is to fix those.
Signed-off-by Khem Raj <[email protected]>Cc Bartosz Golaszewski <[email protected]>---
Thanks for doing this, I recently added it to my TODO. I slightly modified the change - added a version requirement for catch2 to configure.ac (>= 3.0).
Bart
Quoted 6 lines · Bartosz Golaszewski
Quoted 5 lines · Khem Raj
Catch2 v3.x has API changes which needs to be addressed in the tests themselves, hence this changeset is to fix those.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Khem Raj <[email protected]>Cc Bartosz Golaszewski <[email protected]>---
Thanks for doing this, I recently added it to my TODO. I slightly modified the change - added a version requirement for catch2 to configure.ac (>= 3.0).
The only issue I have with the patch is that Debian stable, and all the distros based on it, are still on v2, so building for them will now require backporting catch2 from Debian testing.
Probably not a deal-breaker, but another hurdle to be jumped.
Cheers,
Kent.
Quoted 17 lines · Kent Gibson
Quoted 6 lines · Bartosz Golaszewski
Quoted 5 lines · Khem Raj
Catch2 v3.x has API changes which needs to be addressed in the tests themselves, hence this changeset is to fix those.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Khem Raj <[email protected]>Cc Bartosz Golaszewski <[email protected]>---
Thanks for doing this, I recently added it to my TODO. I slightly modified the change - added a version requirement for catch2 to configure.ac (>= 3.0).
Quoted 7 lines
The only issue I have with the patch is that Debian stable, and all the distros based on it, are still on v2, so building for them will now require backporting catch2 from Debian testing.
Probably not a deal-breaker, but another hurdle to be jumped.Cheers,
Kent.
That's alright. It's been 4 years since the release of catch2 v3.0.
Bart
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 5 lines · Khem Raj
Catch2 v3.x has API changes which needs to be addressed in the tests themselves, hence this changeset is to fix those.
Applied, thanks!
[1/1] bindings: cxx: Migrate C++ tests to use Catch2 v3
commit: 95a2eb76bf634264e56523d3215d1be6c42761f0
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>