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"
#include "p4-codegen.h"

Go to the source code of this file.

Macros

#define ERROR_RETURN_CODE   (-9999)
 Return value indicating an error.
 
#define TEST_PROGRAM(NAME, RVAL, TEXT)
 Define a test case with an entire program. More...
 
#define TEST_MAIN(NAME, RVAL, TEXT)
 Define a test case with only a 'main' function. More...
 
#define TEST_EXPRESSION(NAME, RVAL, TEXT)
 Define a test case with a single expression. More...
 
#define TEST(NAME)   tcase_add_test (tc, NAME)
 Add a test to the test suite.
 

Functions

int run_program (char *text)
 Run lexer, parser, analysis, and code generation on given program. More...
 
int run_main (char *text)
 Run lexer, parser, analysis, and code generation on given 'main' function. More...
 
int run_expression (char *text)
 Run lexer, parser, analysis, and code generation on given expression. More...
 

Detailed Description

Testing utility functions.

Macro Definition Documentation

◆ TEST_EXPRESSION

#define TEST_EXPRESSION (   NAME,
  RVAL,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert_int_eq (run_expression(TEXT), RVAL); } \
END_TEST

Define a test case with a single expression.

◆ TEST_MAIN

#define TEST_MAIN (   NAME,
  RVAL,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert_int_eq (run_main(TEXT), RVAL); } \
END_TEST

Define a test case with only a 'main' function.

◆ TEST_PROGRAM

#define TEST_PROGRAM (   NAME,
  RVAL,
  TEXT 
)
Value:
START_TEST (NAME) \
{ ck_assert_int_eq (run_program(TEXT), RVAL); } \
END_TEST

Define a test case with an entire program.

Function Documentation

◆ run_expression()

int run_expression ( char *  text)

Run lexer, parser, analysis, and code generation on given expression.

Parameters
textExpression to lex, parse, analyze, and generate
Returns
Return value or ERROR_RETURN_CODE if there was an error

◆ run_main()

int run_main ( char *  text)

Run lexer, parser, analysis, and code generation on given 'main' function.

Parameters
textFunction code to lex, parse, analyze, and generate
Returns
Return value or ERROR_RETURN_CODE if there was an error

◆ run_program()

int run_program ( char *  text)

Run lexer, parser, analysis, and code generation on given program.

Parameters
textCode to lex, parse, analyze, and generate
Returns
Return value or ERROR_RETURN_CODE if there was an error
run_main
int run_main(char *text)
Run lexer, parser, analysis, and code generation on given 'main' function.
Definition: testsuite.c:33
run_program
int run_program(char *text)
Run lexer, parser, analysis, and code generation on given program.
Definition: testsuite.c:10
run_expression
int run_expression(char *text)
Run lexer, parser, analysis, and code generation on given expression.
Definition: testsuite.c:40