From 949e1be8cef82616806a9851def13a86318a464c Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 15 Dec 2023 15:10:05 +0100 Subject: [PATCH] Fix tests --- test/expr_arithmetiques.cpp | 7 ++++--- test/include/test.h | 7 ++++--- test/tokenize.cpp | 2 +- test/variables.cpp | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/test/expr_arithmetiques.cpp b/test/expr_arithmetiques.cpp index cc9a0ec..c664c48 100644 --- a/test/expr_arithmetiques.cpp +++ b/test/expr_arithmetiques.cpp @@ -1,8 +1,9 @@ #include "include/test.h" +#include "../src/include/errors.h" #include "../src/include/memory.h" -#include "../src/include/tokenize.h" #include "../src/include/parser.h" +#include "../src/include/tokenize.h" #include "../src/include/interpreter.h" int execute(string s) { @@ -36,13 +37,13 @@ int main() { ); _TEST_ASSERT( - _TEST_IS_EXCEPTION(execute("1 / 0;"), RuntimeError), + _TEST_IS_EXCEPTION(execute("1 / 0;"), ErrorType::DivisionByZero), "Division par 0", true ); _TEST_ASSERT( - _TEST_IS_EXCEPTION(execute("1 % 0;"), RuntimeError), + _TEST_IS_EXCEPTION(execute("1 % 0;"), ErrorType::ModuloByZero), "Modulo par 0", true ); diff --git a/test/include/test.h b/test/include/test.h index 15d27f9..84c15c3 100644 --- a/test/include/test.h +++ b/test/include/test.h @@ -2,6 +2,7 @@ #define DEF_TEST_H #include "../../src/include/colors.h" +#include "../../src/include/errors.h" #define _TEST_PRESENTATION(description) { printf("\n" BLUE "#### %s:" BOLD "%s" RESET BLUE " #####" RESET "\n", __FILE__, description); } @@ -25,13 +26,13 @@ } \ }() -#define _TEST_IS_EXCEPTION(expr, excep) \ +#define _TEST_IS_EXCEPTION(expr, error) \ [&]() -> bool { \ try { \ (expr); \ return false; \ - } catch (const excep& e) { \ - return true; \ + } catch (const UserError& e) { \ + return e.type == error; \ } \ catch (...) { \ return false; \ diff --git a/test/tokenize.cpp b/test/tokenize.cpp index 8063ae3..2919d5d 100644 --- a/test/tokenize.cpp +++ b/test/tokenize.cpp @@ -118,7 +118,7 @@ int main() { string input = "int a = 10 @;"; _TEST_ASSERT( - _TEST_IS_EXCEPTION(tokenize({ input }), SyntaxError), + _TEST_IS_EXCEPTION(tokenize({ input }), ErrorType::UnknownToken), "Token invalide", true ) diff --git a/test/variables.cpp b/test/variables.cpp index 7ce4578..07d3c6b 100644 --- a/test/variables.cpp +++ b/test/variables.cpp @@ -32,13 +32,13 @@ int main() { ); _TEST_ASSERT( - _TEST_IS_EXCEPTION(execute("1 + x;"), RuntimeError), + _TEST_IS_EXCEPTION(execute("1 + x;"), ErrorType::UnknownIdentifier), "Identifieur indéfini", true ); _TEST_ASSERT( - _TEST_IS_EXCEPTION(execute("int x; int x;"), RuntimeError), + _TEST_IS_EXCEPTION(execute("int x; int x;"), ErrorType::AlreadyDefinedIdentifier), "Identifieur déjà défini", true );