Removed trailing whitespace

This commit is contained in:
Joshua Crowgey
2020-01-08 22:07:32 -08:00
parent 5120609e6e
commit 0edd06ec44
6 changed files with 150 additions and 150 deletions

View File

@@ -35,7 +35,7 @@ enum {
YELLOW = 6,
WHITE = 7,
GRAY = 8,
LIGHT_BLUE = 9,
LIGHT_GREEN = 10,
LIGHT_AQUA = 11,
@@ -43,7 +43,7 @@ enum {
LIGHT_PURPLE = 13,
LIGHT_YELLOW = 14,
LIGHT_WHITE = 15,
DEFAULT = 16
};
@@ -55,16 +55,16 @@ static WORD defaults;
static int defaults_loaded = 0;
static void pt_color(int color) {
HANDLE cnsl = GetStdHandle(STD_OUTPUT_HANDLE);
if (!defaults_loaded) {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(cnsl, &info);
defaults = info.wAttributes;
defaults_loaded = 1;
}
SetConsoleTextAttribute(cnsl, color == DEFAULT ? defaults : color);
}
@@ -90,7 +90,7 @@ static const char* colors[] = {
"\x1B[39m",
};
static void pt_color(int color) {
static void pt_color(int color) {
printf("%s", colors[color]);
}
@@ -107,27 +107,27 @@ static char assert_err_buff[MAX_ERROR];
static int assert_err_num = 0;
void pt_assert_run(int result, const char* expr, const char* file, int line) {
num_asserts++;
test_passing = test_passing && result;
if (result) {
num_assert_passes++;
} else {
sprintf(assert_err_buff,
" %i. Assert [ %s ] (%s:%i)\n",
sprintf(assert_err_buff,
" %i. Assert [ %s ] (%s:%i)\n",
assert_err_num+1, expr, file, line );
strcat(assert_err, assert_err_buff);
assert_err_num++;
num_assert_fails++;
}
}
static void ptest_signal(int sig) {
test_passing = 0;
switch( sig ) {
case SIGFPE: sprintf(assert_err_buff,
" %i. Division by Zero\n", assert_err_num+1);
@@ -140,18 +140,18 @@ static void ptest_signal(int sig) {
break;
default: break;
}
assert_err_num++;
strcat(assert_err, assert_err_buff);
pt_color(RED);
pt_color(RED);
printf("Failed! \n\n%s\n", assert_err);
pt_color(DEFAULT);
puts(" | Stopping Execution.");
fflush(stdout);
exit(0);
}
/* Tests */
@@ -160,27 +160,27 @@ static void pt_title_case(char* output, const char* input) {
int space = 1;
unsigned int i;
strcpy(output, input);
for(i = 0; i < strlen(output); i++) {
if (output[i] == '_' || output[i] == ' ') {
space = 1;
output[i] = ' ';
continue;
}
}
if (space && output[i] >= 'a' && output[i] <= 'z') {
space = 0;
output[i] = output[i] - 32;
continue;
}
space = 0;
}
}
typedef struct {
@@ -200,24 +200,24 @@ void pt_add_test(void (*func)(void), const char* name, const char* suite) {
test_t test;
if (num_tests == MAX_TESTS) {
printf("ERROR: Exceeded maximum test count of %i!\n",
printf("ERROR: Exceeded maximum test count of %i!\n",
MAX_TESTS); abort();
}
if (strlen(name) >= MAX_NAME) {
printf("ERROR: Test name '%s' too long (Maximum is %i characters)\n",
printf("ERROR: Test name '%s' too long (Maximum is %i characters)\n",
name, MAX_NAME); abort();
}
if (strlen(suite) >= MAX_NAME) {
printf("ERROR: Test suite '%s' too long (Maximum is %i characters)\n",
printf("ERROR: Test suite '%s' too long (Maximum is %i characters)\n",
suite, MAX_NAME); abort();
}
test.func = func;
pt_title_case(test.name, name);
pt_title_case(test.suite, suite);
tests[num_tests] = test;
num_tests++;
}
@@ -239,7 +239,7 @@ static clock_t start, end;
static char current_suite[MAX_NAME];
int pt_run(void) {
int i;
double total;
test_t test;
@@ -252,18 +252,18 @@ int pt_run(void) {
puts(" | |");
puts(" | Daniel Holden (contact@theorangeduck.com) |");
puts(" +-------------------------------------------+");
signal(SIGFPE, ptest_signal);
signal(SIGILL, ptest_signal);
signal(SIGSEGV, ptest_signal);
start = clock();
strcpy(current_suite, "");
for(i = 0; i < num_tests; i++) {
test = tests[i];
/* Check for transition to a new suite */
if (strcmp(test.suite, current_suite)) {
@@ -275,25 +275,25 @@ int pt_run(void) {
num_suites_fails++;
}
}
suite_passing = 1;
strcpy(current_suite, test.suite);
printf("\n\n ===== %s =====\n\n", current_suite);
}
/* Run Test */
test_passing = 1;
strcpy(assert_err, "");
strcpy(assert_err_buff, "");
assert_err_num = 0;
printf(" | %s ... ", test.name);
fflush(stdout);
test.func();
suite_passing = suite_passing && test_passing;
if (test_passing) {
num_tests_passes++;
pt_color(GREEN);
@@ -301,56 +301,56 @@ int pt_run(void) {
pt_color(DEFAULT);
} else {
num_tests_fails++;
pt_color(RED);
pt_color(RED);
printf("Failed! \n\n%s\n", assert_err);
pt_color(DEFAULT);
}
}
if (suite_passing) {
num_suites_passes++;
} else {
num_suites_fails++;
}
end = clock();
puts("");
puts(" +---------------------------------------------------+");
puts(" | Summary |");
puts(" +---------++------------+-------------+-------------+");
printf(" | Suites ||");
pt_color(YELLOW); printf(" Total %4d ", num_suites);
pt_color(YELLOW); printf(" Total %4d ", num_suites);
pt_color(DEFAULT); putchar('|');
pt_color(GREEN); printf(" Passed %4d ", num_suites_passes);
pt_color(GREEN); printf(" Passed %4d ", num_suites_passes);
pt_color(DEFAULT); putchar('|');
pt_color(RED); printf(" Failed %4d ", num_suites_fails);
pt_color(RED); printf(" Failed %4d ", num_suites_fails);
pt_color(DEFAULT); puts("|");
printf(" | Tests ||");
pt_color(YELLOW); printf(" Total %4d ", num_tests);
pt_color(YELLOW); printf(" Total %4d ", num_tests);
pt_color(DEFAULT); putchar('|');
pt_color(GREEN); printf(" Passed %4d ", num_tests_passes);
pt_color(GREEN); printf(" Passed %4d ", num_tests_passes);
pt_color(DEFAULT); putchar('|');
pt_color(RED); printf(" Failed %4d ", num_tests_fails);
pt_color(RED); printf(" Failed %4d ", num_tests_fails);
pt_color(DEFAULT); puts("|");
printf(" | Asserts ||");
pt_color(YELLOW); printf(" Total %4d ", num_asserts);
pt_color(YELLOW); printf(" Total %4d ", num_asserts);
pt_color(DEFAULT); putchar('|');
pt_color(GREEN); printf(" Passed %4d ", num_assert_passes);
pt_color(GREEN); printf(" Passed %4d ", num_assert_passes);
pt_color(DEFAULT); putchar('|');
pt_color(RED); printf(" Failed %4d ", num_assert_fails);
pt_color(RED); printf(" Failed %4d ", num_assert_fails);
pt_color(DEFAULT); puts("|");
puts(" +---------++------------+-------------+-------------+");
puts("");
total = (double)(end - start) / CLOCKS_PER_SEC;
printf(" Total Running Time: %0.3fs\n\n", total);
if (num_suites_fails > 0) { return 1; } else { return 0; }
}