blob: 8f348bd7483ec1eb785908418cb53764d6af2a66 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "LuaRuntime.hpp"
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <cstdio>
std::vector<std::function<QObject *()>> &get_qtest_registry() {
static std::vector<std::function<QObject *()>> registry;
return registry;
}
int run_all_tests() {
int exit_code = 0;
QString test_name = getenv("TEST_NAME");
for (const auto &run_test : get_qtest_registry()) {
auto *test = run_test();
if (test_name.isEmpty() || test->objectName().contains(test_name))
exit_code |= QTest::qExec(test);
delete test;
}
get_qtest_registry().clear();
return exit_code;
}
bool wait_for_lua_to_be_true(QString lua_code) {
return QTest::qWaitFor([&lua_code]() {
auto &lua = LuaRuntime::instance();
QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
lua.evaluate(lua_code);
evaluation_completed_spy.wait();
return evaluation_completed_spy.first().first().toBool();
});
}
|