aboutsummaryrefslogtreecommitdiff
path: root/spec/testUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--spec/testUtils.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/spec/testUtils.cpp b/spec/testUtils.cpp
index 661f6a3..c359e91 100644
--- a/spec/testUtils.cpp
+++ b/spec/testUtils.cpp
@@ -1,8 +1,9 @@
-#include "LuaRuntime.hpp"
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <cstdio>
+#include "LuaRuntime.hpp"
+
std::vector<std::function<QObject *()>> &get_qtest_registry() {
static std::vector<std::function<QObject *()>> registry;
return registry;
@@ -12,6 +13,8 @@ int run_app_tests() {
int exit_code = 0;
QString test_name = getenv("TEST_NAME");
+ if (test_name.startsWith("lua:"))
+ return 0;
for (const auto &run_test : get_qtest_registry()) {
auto *test = run_test();
@@ -24,6 +27,35 @@ int run_app_tests() {
return exit_code;
}
+int run_lua_tests() {
+ QString test_name = getenv("TEST_NAME");
+ if (test_name.startsWith("lua:")) {
+ test_name = test_name.remove(0, 4);
+ } else if (!test_name.isEmpty())
+ return 0;
+
+ QDir dir("../spec/lua"); // TODO: relative to root instead of build/?
+ QStringList spec_files = dir.entryList(QDir::Files);
+ auto &lua = LuaRuntime::instance();
+
+ lua.start_event_loop();
+ lua.require_module("null-browser.test-utils");
+
+ for (auto &file : spec_files) {
+ auto is_spec = file.endsWith("_spec.lua");
+ auto should_run_spec = test_name.isEmpty() || file.contains(test_name);
+ if (is_spec && should_run_spec) {
+ qDebug() << "Running suite: " << file;
+ lua.load_file_sync(dir.filePath(file));
+ }
+ }
+
+ lua.stop_event_loop();
+
+ qDebug() << "Tests ran successfully";
+ return 0;
+}
+
bool wait_for_lua_to_be_true(QString lua_code) {
return QTest::qWaitFor([&lua_code]() {
auto &lua = LuaRuntime::instance();