Decaf Compiler
Macros | Functions
testsuite.h File Reference

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"
#include "p3-analysis.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(NAME)   tcase_add_test (tc, NAME)
 Add a test to the test suite.
 

Functions

ErrorListrun_analysis (char *text)
 Run lexer, parser, and analysis 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...
 

Detailed Description

Testing utility functions.

Macro Definition Documentation

◆ TEST_INVALID

#define TEST_INVALID (   NAME,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert (invalid_program(TEXT)); } \
END_TEST
bool invalid_program(char *text)
Run lexer and parser on given text and verify that it throws an exception.
Definition: testsuite.c:32

Define a test case with an invalid program.

◆ TEST_INVALID_MAIN

#define TEST_INVALID_MAIN (   NAME,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert (invalid_program("def int main () { " TEXT " }")); } \
END_TEST

Define a test case with an invalid main function.

◆ TEST_VALID

#define TEST_VALID (   NAME,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert (valid_program(TEXT)); } \
END_TEST
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.
Definition: testsuite.c:26

Define a test case with a valid program.

◆ TEST_VALID_MAIN

#define TEST_VALID_MAIN (   NAME,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert (valid_program("def int main () { " TEXT " }")); } \
END_TEST

Define a test case with a valid main function.

Function Documentation

◆ invalid_program()

bool invalid_program ( char *  text)

Run lexer and parser on given text and verify that it throws an exception.

Parameters
textCode to lex and parse
Returns
True if and only if the lexer or parser threw an exception

◆ run_analysis()

ErrorList* run_analysis ( char *  text)

Run lexer, parser, and analysis on given text.

Parameters
textCode to lex, parse, and analyze
Returns
AST or NULL if there was an error

◆ valid_program()

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.

Parameters
textCode to lex and parse
Returns
True if and only if the text was lexed and parsed successfully