1
0
mirror of synced 2024-12-11 23:46:00 +01:00
ImHex/tests/common/source/main.cpp

54 lines
1.2 KiB
C++
Raw Normal View History

#include <hex.hpp>
2024-01-30 21:24:26 +01:00
#include <hex/api/event_manager.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp>
2024-01-30 21:24:26 +01:00
#include <hex/test/tests.hpp>
#include <cstdlib>
int test(int argc, char **argv) {
// Check if a test to run has been provided
if (argc != 2) {
hex::log::fatal("Invalid number of arguments specified! {}", argc);
return EXIT_FAILURE;
}
// Check if that test exists
std::string testName = argv[1];
if (!hex::test::Tests::get().contains(testName)) {
hex::log::fatal("No test with name {} found!", testName);
return EXIT_FAILURE;
}
auto test = hex::test::Tests::get()[testName];
auto result = test.function();
if (test.shouldFail) {
switch (result) {
2022-02-01 22:09:44 +01:00
case EXIT_SUCCESS:
return EXIT_FAILURE;
case EXIT_FAILURE:
return EXIT_SUCCESS;
default:
return result;
}
} else {
return result;
}
}
int main(int argc, char **argv) {
2022-01-29 21:49:12 +01:00
int result = test(argc, argv);
if (result == EXIT_SUCCESS)
hex::log::info("Success!");
else
hex::log::info("Failed!");
2024-01-30 21:24:26 +01:00
hex::EventManager::clear();
return result;
}