Fix tests

This commit is contained in:
augustin64 2023-12-15 15:10:05 +01:00
parent 5fed47367d
commit 949e1be8ce
4 changed files with 11 additions and 9 deletions

View File

@ -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
);

View File

@ -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; \

View File

@ -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
)

View File

@ -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
);