aboutsummaryrefslogtreecommitdiff
path: root/spec/testUtils.cpp
blob: cea7a3d27ac6286d6ae405175c4e5d7d668b7720 (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
#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;
}