From 1baa65cc9536838ceacb14335833d307e9a5d993 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 19 Oct 2022 23:34:15 +0100 Subject: [PATCH] Removed annoying assertion test messages from test output --- scripts/test/panic-within-functions.toy | 2 +- {test => scripts/test}/sample_code.toy | 0 test/test_call_from_host.c | 2 ++ test/test_compiler.c | 2 +- test/test_interpreter.c | 23 ++++++++++++++++++++++- test/test_parser.c | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) rename {test => scripts/test}/sample_code.toy (100%) diff --git a/scripts/test/panic-within-functions.toy b/scripts/test/panic-within-functions.toy index 0c369df..bcf7bed 100644 --- a/scripts/test/panic-within-functions.toy +++ b/scripts/test/panic-within-functions.toy @@ -1,7 +1,7 @@ fn panic() { - assert false, "This should only be seen once"; + assert false, "!ignore panicking within a function"; } panic(); diff --git a/test/sample_code.toy b/scripts/test/sample_code.toy similarity index 100% rename from test/sample_code.toy rename to scripts/test/sample_code.toy diff --git a/test/test_call_from_host.c b/test/test_call_from_host.c index 2b2c6ee..da4fe19 100644 --- a/test/test_call_from_host.c +++ b/test/test_call_from_host.c @@ -281,6 +281,8 @@ int main() { { interpreter.printOutput("Testing assertion failure"); + setInterpreterAssert(&interpreter, noPrintFn); + LiteralArray arguments; initLiteralArray(&arguments); LiteralArray returns; diff --git a/test/test_compiler.c b/test/test_compiler.c index 763f47c..92c17c4 100644 --- a/test/test_compiler.c +++ b/test/test_compiler.c @@ -84,7 +84,7 @@ int main() { { //source size_t sourceLength = 0; - char* source = readFile("sample_code.toy", &sourceLength); + char* source = readFile("../scripts/test/sample_code.toy", &sourceLength); //test basic compilation & collation Lexer lexer; diff --git a/test/test_interpreter.c b/test/test_interpreter.c index 403b04f..516ef5c 100644 --- a/test/test_interpreter.c +++ b/test/test_interpreter.c @@ -16,6 +16,18 @@ static void noPrintFn(const char* output) { //NO OP } +int ignoredAssertions = 0; +static void noAssertFn(const char* output) { + if (strncmp(output, "!ignore", 7) == 0) { + ignoredAssertions++; + } + else { + fprintf(stderr, ERROR "Assertion failure: "); + fprintf(stderr, "%s", output); + fprintf(stderr, "\n" RESET); //default new line + } +} + //compilation functions char* readFile(char* path, size_t* fileSize) { FILE* file = fopen(path, "rb"); @@ -94,6 +106,7 @@ void runBinary(unsigned char* tb, size_t size) { //NOTE: suppress print output for testing setInterpreterPrint(&interpreter, noPrintFn); + setInterpreterAssert(&interpreter, noAssertFn); runInterpreter(&interpreter, tb, size); freeInterpreter(&interpreter); @@ -147,8 +160,9 @@ int main() { int size = 0; unsigned char* bytecode = collateCompiler(&compiler, &size); - //NOTE: supress print output for testing + //NOTE: suppress print output for testing setInterpreterPrint(&interpreter, noPrintFn); + setInterpreterAssert(&interpreter, noAssertFn); //run runInterpreter(&interpreter, bytecode, size); @@ -213,6 +227,7 @@ int main() { //NOTE: supress print output for testing setInterpreterPrint(&interpreter, noPrintFn); + setInterpreterAssert(&interpreter, noAssertFn); runInterpreter(&interpreter, exportBinary, exportSize); //automatically frees the binary data @@ -227,6 +242,12 @@ int main() { free((void*)importSource); } + //1, to allow for the assertion test + if (ignoredAssertions > 1) { + fprintf(stderr, ERROR "Assertions hidden: %d\n", ignoredAssertions); + return -1; + } + printf(NOTICE "All good\n" RESET); return 0; } diff --git a/test/test_parser.c b/test/test_parser.c index cd76041..5a7922c 100644 --- a/test/test_parser.c +++ b/test/test_parser.c @@ -90,7 +90,7 @@ int main() { { //get the source file size_t size = 0; - char* source = readFile("sample_code.toy", &size); + char* source = readFile("../scripts/test/sample_code.toy", &size); //test parsing a chunk of junk (valgrind will find leaks) Lexer lexer;