diff --git a/.gitmodules b/.gitmodules index 6f998139..9ccddfaa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -44,3 +44,6 @@ [submodule "dep/simde"] path = dep/simde url = https://github.com/simd-everywhere/simde.git +[submodule "dep/Catch2"] + path = dep/Catch2 + url = https://github.com/catchorg/Catch2.git diff --git a/dep/Catch2 b/dep/Catch2 new file mode 160000 index 00000000..914aeecf --- /dev/null +++ b/dep/Catch2 @@ -0,0 +1 @@ +Subproject commit 914aeecfe23b1e16af6ea675a4fb5dbd5a5b8d0a diff --git a/include/runtests.hpp b/include/runtests.hpp new file mode 100644 index 00000000..c0dc5d4c --- /dev/null +++ b/include/runtests.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace rack { +namespace runtests { + +extern std::string testArgs; +int runTests(); + +} // namespace runtests +} // namespace rack diff --git a/src/tests/runtests.cpp b/src/tests/runtests.cpp new file mode 100644 index 00000000..0d04da4f --- /dev/null +++ b/src/tests/runtests.cpp @@ -0,0 +1,38 @@ +#include "runtests.hpp" +#include "logger.hpp" +#include "catch2/catch_session.hpp" +#include + +namespace rack { +namespace runtests { + +std::string testArgs = ""; + +int runTests() { + DEBUG("Running Catch2 tests"); + // Create Catch2 session + Catch::Session session; + + // Parse testArgs into argc, argv + std::istringstream iss(testArgs); + std::vector args; + for (std::string s; iss >> s;) + args.push_back(s); + std::vector argv; + argv.push_back("Rack"); + for (const auto& arg : args) + argv.push_back(arg.c_str()); + argv.push_back(nullptr); + int returnCode = session.applyCommandLine(args.size() + 1, argv.data()); + if (returnCode != 0) { + WARN("Catch2 command line error %d", returnCode); + return returnCode; + } + + // Run Catch2 tests + int numFailed = session.run(); + return numFailed; +} + +} // namespace runtests +} // namespace rack