Removed annoying assertion test messages from test output

This commit is contained in:
2022-10-19 23:34:15 +01:00
parent e01e096188
commit 1baa65cc95
6 changed files with 27 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
fn panic() { fn panic() {
assert false, "This should only be seen once"; assert false, "!ignore panicking within a function";
} }
panic(); panic();

View File

@@ -281,6 +281,8 @@ int main() {
{ {
interpreter.printOutput("Testing assertion failure"); interpreter.printOutput("Testing assertion failure");
setInterpreterAssert(&interpreter, noPrintFn);
LiteralArray arguments; LiteralArray arguments;
initLiteralArray(&arguments); initLiteralArray(&arguments);
LiteralArray returns; LiteralArray returns;

View File

@@ -84,7 +84,7 @@ int main() {
{ {
//source //source
size_t sourceLength = 0; size_t sourceLength = 0;
char* source = readFile("sample_code.toy", &sourceLength); char* source = readFile("../scripts/test/sample_code.toy", &sourceLength);
//test basic compilation & collation //test basic compilation & collation
Lexer lexer; Lexer lexer;

View File

@@ -16,6 +16,18 @@ static void noPrintFn(const char* output) {
//NO OP //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 //compilation functions
char* readFile(char* path, size_t* fileSize) { char* readFile(char* path, size_t* fileSize) {
FILE* file = fopen(path, "rb"); FILE* file = fopen(path, "rb");
@@ -94,6 +106,7 @@ void runBinary(unsigned char* tb, size_t size) {
//NOTE: suppress print output for testing //NOTE: suppress print output for testing
setInterpreterPrint(&interpreter, noPrintFn); setInterpreterPrint(&interpreter, noPrintFn);
setInterpreterAssert(&interpreter, noAssertFn);
runInterpreter(&interpreter, tb, size); runInterpreter(&interpreter, tb, size);
freeInterpreter(&interpreter); freeInterpreter(&interpreter);
@@ -147,8 +160,9 @@ int main() {
int size = 0; int size = 0;
unsigned char* bytecode = collateCompiler(&compiler, &size); unsigned char* bytecode = collateCompiler(&compiler, &size);
//NOTE: supress print output for testing //NOTE: suppress print output for testing
setInterpreterPrint(&interpreter, noPrintFn); setInterpreterPrint(&interpreter, noPrintFn);
setInterpreterAssert(&interpreter, noAssertFn);
//run //run
runInterpreter(&interpreter, bytecode, size); runInterpreter(&interpreter, bytecode, size);
@@ -213,6 +227,7 @@ int main() {
//NOTE: supress print output for testing //NOTE: supress print output for testing
setInterpreterPrint(&interpreter, noPrintFn); setInterpreterPrint(&interpreter, noPrintFn);
setInterpreterAssert(&interpreter, noAssertFn);
runInterpreter(&interpreter, exportBinary, exportSize); //automatically frees the binary data runInterpreter(&interpreter, exportBinary, exportSize); //automatically frees the binary data
@@ -227,6 +242,12 @@ int main() {
free((void*)importSource); 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); printf(NOTICE "All good\n" RESET);
return 0; return 0;
} }

View File

@@ -90,7 +90,7 @@ int main() {
{ {
//get the source file //get the source file
size_t size = 0; 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) //test parsing a chunk of junk (valgrind will find leaks)
Lexer lexer; Lexer lexer;