tests: Make tests compile with latest PatternLanguage update

This commit is contained in:
WerWolv
2022-08-07 22:55:00 +02:00
parent 0b15299980
commit 8d3c94be8f
3 changed files with 27 additions and 19 deletions

View File

@@ -1,5 +1,8 @@
#include <pl.hpp>
#include <helpers/file.hpp>
#include <pl/helpers/file.hpp>
#include <pl/core/errors/preprocessor_errors.hpp>
#include <pl/core/errors/evaluator_errors.hpp>
#include <fmt/format.h>
#include <cstdlib>
@@ -19,17 +22,20 @@ int main(int argc, char **argv) {
fmt::print("Running test {} on test file {}\n", includeName, includeFilePath.filename().string());
// Open pattern file
pl::fs::File patternFile(includeFilePath, pl::fs::File::Mode::Read);
pl::hlp::fs::File patternFile(includeFilePath, pl::hlp::fs::File::Mode::Read);
if (!patternFile.isValid())
return EXIT_FAILURE;
// Setup Pattern Language Runtime
pl::PatternLanguage runtime;
{
constexpr auto DummyPragmaHandler = [](const auto&, const auto&){ pl::LogConsole::abortEvaluation("Include files should never use this pragma!"); return true; };
constexpr auto DummyPragmaHandler = [](const auto&, const auto&){
pl::core::err::M0006.throwError("Include files should never use this pragma!");
return false;
};
runtime.setDataSource([&](pl::u64 address, pl::u8 *data, size_t size) {
pl::LogConsole::abortEvaluation("Include files should never read from memory directly!");
pl::core::err::E0011.throwError("Include files should never read from memory directly!");
}, 0x00, 0x100000);
runtime.setDangerousFunctionCallHandler([]{ return true; });
runtime.setIncludePaths({ includePath });
@@ -47,14 +53,15 @@ int main(int argc, char **argv) {
fmt::print("Error during execution!\n");
if (const auto &hardError = runtime.getError(); hardError.has_value())
fmt::print("Hard error: {}\n\n", hardError.value().what());
fmt::print("Hard error: {}:{} - {}\n\n", hardError->line, hardError->column, hardError->message);
for (const auto &[level, message] : runtime.getConsoleLog()) {
switch (level) {
case pl::LogConsole::Level::Debug: fmt::print(" [DEBUG] "); break;
case pl::LogConsole::Level::Info: fmt::print(" [INFO] "); break;
case pl::LogConsole::Level::Warning: fmt::print(" [WARN] "); break;
case pl::LogConsole::Level::Error: fmt::print(" [ERROR] "); break;
using enum pl::core::LogConsole::Level;
case Debug: fmt::print(" [DEBUG] "); break;
case Info: fmt::print(" [INFO] "); break;
case Warning: fmt::print(" [WARN] "); break;
case Error: fmt::print(" [ERROR] "); break;
}
fmt::print("{}\n", message);

View File

@@ -1,5 +1,5 @@
#include <helpers/file.hpp>
#include <helpers/guards.hpp>
#include <pl/helpers/file.hpp>
#include <pl/helpers/guards.hpp>
#include <fmt/format.h>
#include <cstdlib>

View File

@@ -1,5 +1,5 @@
#include <pl.hpp>
#include <helpers/file.hpp>
#include <pl/helpers/file.hpp>
#include <fmt/format.h>
#include <cstdlib>
@@ -27,12 +27,12 @@ int main(int argc, char **argv) {
fmt::print("Running test {} on test file {}\n", patternName, testFilePath.stem().string());
// Open pattern file
pl::fs::File patternFile(patternFilePath, pl::fs::File::Mode::Read);
pl::hlp::fs::File patternFile(patternFilePath, pl::hlp::fs::File::Mode::Read);
if (!patternFile.isValid())
return EXIT_FAILURE;
// Open test file
pl::fs::File testFile(testFilePath, pl::fs::File::Mode::Read);
pl::hlp::fs::File testFile(testFilePath, pl::hlp::fs::File::Mode::Read);
if (!testFile.isValid())
return EXIT_FAILURE;
@@ -55,14 +55,15 @@ int main(int argc, char **argv) {
fmt::print("Error during execution!\n");
if (const auto &hardError = runtime.getError(); hardError.has_value())
fmt::print("Hard error: {}\n\n", hardError.value().what());
fmt::print("Hard error: {}:{} - {}\n\n", hardError->line, hardError->column, hardError->message);
for (const auto &[level, message] : runtime.getConsoleLog()) {
switch (level) {
case pl::LogConsole::Level::Debug: fmt::print(" [DEBUG] "); break;
case pl::LogConsole::Level::Info: fmt::print(" [INFO] "); break;
case pl::LogConsole::Level::Warning: fmt::print(" [WARN] "); break;
case pl::LogConsole::Level::Error: fmt::print(" [ERROR] "); break;
using enum pl::core::LogConsole::Level;
case Debug: fmt::print(" [DEBUG] "); break;
case Info: fmt::print(" [INFO] "); break;
case Warning: fmt::print(" [WARN] "); break;
case Error: fmt::print(" [ERROR] "); break;
}
fmt::print("{}\n", message);