Decaf Compiler
|
Testing utility functions. More...
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <time.h>
#include <check.h>
#include "p1-lexer.h"
#include "p2-parser.h"
Go to the source code of this file.
Macros | |
#define | TEST_VALID(NAME, TEXT) |
Define a test case with a valid program. More... | |
#define | TEST_INVALID(NAME, TEXT) |
Define a test case with an invalid program. More... | |
#define | TEST_VALID_MAIN(NAME, TEXT) |
Define a test case with a valid main function. More... | |
#define | TEST_INVALID_MAIN(NAME, TEXT) |
Define a test case with an invalid main function. More... | |
#define | TEST_VALID_EXPR(NAME, TEXT) |
Define a test case with a valid main function returning an expression. More... | |
#define | TEST_INVALID_EXPR(NAME, TEXT) |
Define a test case with an invalid main function returning an expression. More... | |
#define | TEST_INT_LITERAL(NAME, TEXT, VALUE) |
Define a test case for an integer literal. More... | |
#define | TEST_STR_LITERAL(NAME, TEXT, VALUE) |
Define a test case for a string literal. More... | |
#define | TEST(NAME) tcase_add_test (tc, NAME) |
Add a test to the test suite. | |
Functions | |
ASTNode * | run_parser (char *text) |
Run lexer and parser on given text. More... | |
bool | invalid_program (char *text) |
Run lexer and parser on given text and verify that it throws an exception. More... | |
bool | valid_program (char *text) |
Run lexer and parser on given text and verify that it returns an AST and does not throw an exception. More... | |
Testing utility functions.
#define TEST_INT_LITERAL | ( | NAME, | |
TEXT, | |||
VALUE | |||
) |
#define TEST_INVALID | ( | NAME, | |
TEXT | |||
) |
Define a test case with an invalid program.
#define TEST_INVALID_EXPR | ( | NAME, | |
TEXT | |||
) |
Define a test case with an invalid main function returning an expression.
#define TEST_INVALID_MAIN | ( | NAME, | |
TEXT | |||
) |
Define a test case with an invalid main function.
#define TEST_STR_LITERAL | ( | NAME, | |
TEXT, | |||
VALUE | |||
) |
#define TEST_VALID | ( | NAME, | |
TEXT | |||
) |
Define a test case with a valid program.
#define TEST_VALID_EXPR | ( | NAME, | |
TEXT | |||
) |
Define a test case with a valid main function returning an expression.
#define TEST_VALID_MAIN | ( | NAME, | |
TEXT | |||
) |
Define a test case with a valid main function.
bool invalid_program | ( | char * | text | ) |
Run lexer and parser on given text and verify that it throws an exception.
text | Code to lex and parse |
ASTNode* run_parser | ( | char * | text | ) |
Run lexer and parser on given text.
The difference between this and the main parse() function is that this version catches exceptions and returns NULL
instead of propogating the exception.
text | Code to lex and parse |
NULL
if there was an error bool valid_program | ( | char * | text | ) |
Run lexer and parser on given text and verify that it returns an AST and does not throw an exception.
text | Code to lex and parse |