Add _TEST_NO_EXCEPTION macro
This commit is contained in:
parent
fcd0c34885
commit
430ac2be09
@ -15,11 +15,20 @@ int execute(string s) {
|
||||
int main() {
|
||||
_TEST_PRESENTATION("Expressions Arithmétiques");
|
||||
|
||||
_TEST_ASSERT(execute("10 + 3 * (7 - 2);") == 25, "Priorités");
|
||||
_TEST_ASSERT(
|
||||
_TEST_NO_EXCEPTION(execute("10 + 3 * (7 - 2);") == 25),
|
||||
"Priorités"
|
||||
);
|
||||
|
||||
_TEST_ASSERT(execute("12 - 4 - 20;") == -12, "Ordre de soustraction");
|
||||
_TEST_ASSERT(
|
||||
_TEST_NO_EXCEPTION(execute("12 - 4 - 20;") == -12),
|
||||
"Ordre de soustraction"
|
||||
);
|
||||
|
||||
_TEST_ASSERT(execute("-7 + 13 + -6;") == 0, "Opérateurs unaires");
|
||||
_TEST_ASSERT(
|
||||
_TEST_NO_EXCEPTION(execute("-7 + 13 + -6;") == 0),
|
||||
"Opérateurs unaires"
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
@ -19,5 +19,15 @@
|
||||
}
|
||||
|
||||
|
||||
#define _TEST_NO_EXCEPTION(expr) \
|
||||
[&]() -> bool { \
|
||||
try { \
|
||||
bool result = (expr); \
|
||||
return result; \
|
||||
} catch (...) { \
|
||||
return false; \
|
||||
} \
|
||||
}()
|
||||
|
||||
|
||||
#endif
|
@ -15,9 +15,15 @@ int execute(string s) {
|
||||
int main() {
|
||||
_TEST_PRESENTATION("Variables");
|
||||
|
||||
_TEST_ASSERT(execute("int uneVariableFarfelue__ = 12;") == 12, "Déclaration avec assignement");
|
||||
_TEST_ASSERT(
|
||||
_TEST_NO_EXCEPTION(execute("int uneVariableFarfelue__ = 12;") == 12),
|
||||
"Déclaration avec assignement"
|
||||
);
|
||||
|
||||
_TEST_ASSERT(execute("int x = 5; x + 3;") == 8, "Déclaration puis assignement");
|
||||
_TEST_ASSERT(
|
||||
_TEST_NO_EXCEPTION(execute("int x = 5; x = x + 3;") == 8),
|
||||
"Déclaration puis assignement"
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user