-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from JakeRoggenbuck/testing
Testing
- Loading branch information
Showing
9 changed files
with
130 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
set (CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 11) | ||
project(jccc) | ||
add_compile_options(-O0 -Wall -Wpedantic -g -Wno-gnu-zero-variadic-macro-arguments) | ||
|
||
file(GLOB_RECURSE SOURCES src/*.c) | ||
add_executable(jccc ${SOURCES}) | ||
list(FILTER SOURCES EXCLUDE REGEX ".*\/(driver\/main|testing\/main)\.c$") | ||
|
||
# Create a main file for the actual jccc executable | ||
set(MAIN_DRIVER "src/driver/main.c") | ||
|
||
add_executable(jccc ${SOURCES} ${MAIN_DRIVER}) | ||
target_include_directories(jccc PRIVATE src) | ||
|
||
enable_testing() | ||
|
||
file(GLOB_RECURSE TEST_SOURCES src/test_*.c) | ||
|
||
# Set a main function for testing | ||
set(TEST_MAIN "src/testing/main.c") | ||
|
||
add_executable(test_jccc ${SOURCES} ${TEST_SOURCES} ${TEST_MAIN}) | ||
target_include_directories(test_jccc PRIVATE src) | ||
|
||
add_test(NAME TestJccc COMMAND test_jccc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Run all of the tests at the end of each C file in the lexer module | ||
*/ | ||
|
||
#include "lex.h" | ||
#include <testing/test_utils.h> | ||
|
||
int test_lexer() { | ||
testing_setup(); | ||
|
||
test_ttype_from_string(); | ||
|
||
testing_cleanup(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Run all of the tests at the end of each C file in the lexer module */ | ||
|
||
#include "lex.h" | ||
|
||
int test_lexer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "lexer/test_lexer.h" | ||
|
||
int main() { | ||
test_lexer(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <assert.h> | ||
|
||
#define tassert(e) ((void)((e) ? 0 : __assert(#e, __FILE__, __LINE__))) | ||
#define __assert(e, file, line) \ | ||
((void)printf("%s:%u: failed assertion `%s'\n", file, line, e), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdio.h> | ||
#include <util/out.h> | ||
|
||
void testing_setup_internal(const char *func_name) { | ||
printf("Running test "); | ||
fflush(stdout); | ||
PRINT_WITH_COLOR(CODE_GREEN, "\"%s\"", func_name); | ||
printf(" ...\n"); | ||
} | ||
|
||
void testing_cleanup_internal(const char *func_name) { | ||
printf("Concluded test "); | ||
fflush(stdout); | ||
PRINT_WITH_COLOR(CODE_GREEN, "\"%s\"", func_name); | ||
printf("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* Testing utility | ||
* Here is an example usage of the testing | ||
* | ||
* This is from "lexer/test_lexer.c" | ||
* | ||
* For each module of code, create a test_{module_name} file. | ||
* This file should include a test_{module_name} function that includes the | ||
* testing_setup and the testing_cleanup functions. | ||
#include "lex.h" | ||
#include <testing/test_utils.h> | ||
int test_lexer() { | ||
testing_setup(); | ||
test_ttype_from_string(); | ||
testing_cleanup(); | ||
return 0; | ||
} | ||
* After this, include a call to this function in the "testing/main.c" file like how it's done for test_lexer. | ||
#include "lexer/test_lexer.h" | ||
int main() { | ||
test_lexer(); | ||
return 0; | ||
} | ||
*/ | ||
|
||
#define testing_setup() testing_setup_internal(__func__) | ||
|
||
#define testing_cleanup() testing_cleanup_internal(__func__) | ||
|
||
void testing_setup_internal(const char *func_name); | ||
|
||
void testing_cleanup_internal(const char *func_name); |