summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-08 14:56:22 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-08 14:56:22 +1100
commit9f572cb92738c2f6d435f47fef9bad7344bc6e09 (patch)
treeb7d7145ee3d5ac19a2aea2c17e4e68c1164f02b1 /lib
parente219925fac2d9b0b054445ac9c094d51ae30fd17 (diff)
downloadtangara-fw-9f572cb92738c2f6d435f47fef9bad7344bc6e09.tar.gz
Working test runner!!!
Diffstat (limited to 'lib')
-rw-r--r--lib/catch2/CMakeLists.txt5
-rw-r--r--lib/catch2/catch_runner.cpp28
-rw-r--r--lib/catch2/include/catch_runner.hpp6
3 files changed, 33 insertions, 6 deletions
diff --git a/lib/catch2/CMakeLists.txt b/lib/catch2/CMakeLists.txt
index 2714474e..ac435074 100644
--- a/lib/catch2/CMakeLists.txt
+++ b/lib/catch2/CMakeLists.txt
@@ -1 +1,4 @@
-idf_component_register(SRCS "catch_runner.cpp" INCLUDE_DIRS "include")
+idf_component_register(
+ SRCS "catch_runner.cpp"
+ INCLUDE_DIRS "include"
+ REQUIRES "console")
diff --git a/lib/catch2/catch_runner.cpp b/lib/catch2/catch_runner.cpp
index 8cd5c120..2b8f9678 100644
--- a/lib/catch2/catch_runner.cpp
+++ b/lib/catch2/catch_runner.cpp
@@ -3,8 +3,28 @@
#define CATCH_CONFIG_RUNNER
#include "catch2/catch.hpp"
-void run_catch(void) {
- int argc = 1;
- char *argv = "catch2";
- Catch::Session().run( argc, &argv );
+#include <stdio.h>
+#include <string.h>
+#include "esp_console.h"
+#include "esp_log.h"
+#include "esp_system.h"
+
+// There must be exactly on Session instance at all times; attempting to destroy
+// this will result in memory corruption.
+static Catch::Session sCatchSession;
+
+int exec_catch2(int argc, char** argv) {
+ // Reset the existing configuration before applying a new one. Otherwise we
+ // will get the combination of all configs.
+ sCatchSession.configData() = Catch::ConfigData();
+
+ int result = sCatchSession.applyCommandLine(argc, argv);
+ if (result != 0) {
+ return result;
+ }
+
+ // Returns number of failures.
+ int failures = sCatchSession.run();
+
+ return failures > 0;
}
diff --git a/lib/catch2/include/catch_runner.hpp b/lib/catch2/include/catch_runner.hpp
index 527b7ff6..51e8c1bc 100644
--- a/lib/catch2/include/catch_runner.hpp
+++ b/lib/catch2/include/catch_runner.hpp
@@ -1,3 +1,7 @@
#pragma once
-void run_catch(void);
+/*
+ * Executes the Catch2 test runner as if called from the commandline on a
+ * standard unix-y system.
+ */
+int exec_catch2(int argc, char **argv);