From 2eec4c98cc47835ff410676a00c7e1796ff2da54 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 2 Dec 2015 22:23:32 +0100 Subject: Rename CSTest to MinCTest; is more to-the-point --- Makefile | 4 ++-- README.md | 2 +- cstest.c | 67 ----------------------------------------------------- cstest.h | 78 -------------------------------------------------------------- example.c | 4 ++-- minctest.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ minctest.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 150 insertions(+), 150 deletions(-) delete mode 100644 cstest.c delete mode 100644 cstest.h create mode 100644 minctest.c create mode 100644 minctest.h diff --git a/Makefile b/Makefile index 34edccb..f330bdd 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=gcc CFLAGS=-O3 -DEPS=cstest.h -OBJS=example.o cstest.o +DEPS=minctest.h +OBJS=example.o minctest.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/README.md b/README.md index 56db43d..c2bae4d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CSTest +# MinCTest Minimalistic C unit test framework. diff --git a/cstest.c b/cstest.c deleted file mode 100644 index 1b2a3ef..0000000 --- a/cstest.c +++ /dev/null @@ -1,67 +0,0 @@ -/** - * CSTest - Minimalistic C unit test framework - * Copyright (C) 2015 Camil Staps - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include -#include -#include "cstest.h" - -// Colours for terminal output -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define RESET "\x1B[0m" - -cstester* test_initialize(void) { - cstester* test = malloc(sizeof(cstester)); - if (test == NULL) return NULL; - test->passed = 0; - test->failed = 0; - test->show_pass = true; - return test; -} - -void test_wrapup(cstester* tester) { - if (tester->failed == 0) { - printf(KGRN "\nAll tests passed (%d)\n" RESET, tester->passed); - } else { - printf(KRED "\n%d test%s failed" RESET " (%d passed)\n", - tester->failed, tester->failed > 1 ? "s" : "", tester->passed); - } -} - -void test_destroy(cstester* tester) { - free(tester); -} - -void test_exit(cstester* tester) { - bool all_passed = tester->failed == 0; - test_destroy(tester); - exit(all_passed ? 0 : -1); -} - -void test_true(cstester* tester, bool check, const char* text) { - if (!check || tester->show_pass) { - printf(check ? KGRN : KRED); - printf(check ? "Test passed" : "Test failed"); - if (text != NULL) - printf(": %s", text); - printf("\n" RESET); - } - - *(check ? &tester->passed : &tester->failed) += 1; -} - diff --git a/cstest.h b/cstest.h deleted file mode 100644 index 6fb3280..0000000 --- a/cstest.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * CSTest - Minimalistic C unit test framework - * Copyright (C) 2015 Camil Staps - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include - -typedef struct { - uint16_t passed; // Number of passed tests - uint16_t failed; // Number of failed tests - bool show_pass; // Whether or not to print a message when a test passes -} cstester; - -/** - * Initialize a tester struct - * - * This allocates a cstester on the heap. Don't forget to call test_destroy to - * free that memory. - * - * @return a struct on the heap for use in the other test_* functions - */ -cstester* test_initialize(void); - -/** - * Show summarised data about the tester - * - * Shows a green message when all tests passed, otherwise a red message that - * some failed. Shows passed/failed counts as well. - * - * @param cstester* a pointer to a cstester from test_initialize - */ -void test_wrapup(cstester*); - -/** - * Destroy a cstester struct - * - * Essentially frees the memory that was allocated for the struct. - * - * @param cstester* a pointer to a cstester from test_initialize - */ -void test_destroy(cstester*); - -/** - * Exit the program with an appropriate return value - * - * Returns -1 if one or more tests failed, 0 otherwise. Exits the program. - * - * @param cstester* a pointer to a cstester from test_initialize - * @return don't expect this to return - */ -void test_exit(cstester*); - -/** - * Test for truth on a bool - * - * Outputs a red message for failure, and a green one for passing if - * cstester->show_pass is true. Adds this test to the summarised data in the - * cstester. - * - * @param cstester* a pointer to a cstester from test_initialize - * @param check the boolean that should be true - * @param test a custom message to show - */ -void test_true(cstester* tester, bool check, const char* text); - diff --git a/example.c b/example.c index ffd155a..52f3a49 100644 --- a/example.c +++ b/example.c @@ -16,10 +16,10 @@ * along with this program. If not, see . */ #include -#include "cstest.h" +#include "minctest.h" int main(void) { - cstester* tester = test_initialize(); + tester* tester = test_initialize(); tester->show_pass = false; test_true(tester, 1 == 1, "1 = 1"); diff --git a/minctest.c b/minctest.c new file mode 100644 index 0000000..61a3688 --- /dev/null +++ b/minctest.c @@ -0,0 +1,67 @@ +/** + * MinCTest - Minimalistic C unit test framework + * Copyright (C) 2015 Camil Staps + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include "minctest.h" + +// Colours for terminal output +#define KRED "\x1B[31m" +#define KGRN "\x1B[32m" +#define RESET "\x1B[0m" + +tester* test_initialize(void) { + tester* test = malloc(sizeof(tester)); + if (test == NULL) return NULL; + test->passed = 0; + test->failed = 0; + test->show_pass = true; + return test; +} + +void test_wrapup(tester* tester) { + if (tester->failed == 0) { + printf(KGRN "\nAll tests passed (%d)\n" RESET, tester->passed); + } else { + printf(KRED "\n%d test%s failed" RESET " (%d passed)\n", + tester->failed, tester->failed > 1 ? "s" : "", tester->passed); + } +} + +void test_destroy(tester* tester) { + free(tester); +} + +void test_exit(tester* tester) { + bool all_passed = tester->failed == 0; + test_destroy(tester); + exit(all_passed ? 0 : -1); +} + +void test_true(tester* tester, bool check, const char* text) { + if (!check || tester->show_pass) { + printf(check ? KGRN : KRED); + printf(check ? "Test passed" : "Test failed"); + if (text != NULL) + printf(": %s", text); + printf("\n" RESET); + } + + *(check ? &tester->passed : &tester->failed) += 1; +} + diff --git a/minctest.h b/minctest.h new file mode 100644 index 0000000..260b36e --- /dev/null +++ b/minctest.h @@ -0,0 +1,78 @@ +/** + * MinCTest - Minimalistic C unit test framework + * Copyright (C) 2015 Camil Staps + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include + +typedef struct { + uint16_t passed; // Number of passed tests + uint16_t failed; // Number of failed tests + bool show_pass; // Whether or not to print a message when a test passes +} tester; + +/** + * Initialize a tester struct + * + * This allocates a tester on the heap. Don't forget to call test_destroy to + * free that memory. + * + * @return a struct on the heap for use in the other test_* functions + */ +tester* test_initialize(void); + +/** + * Show summarised data about the tester + * + * Shows a green message when all tests passed, otherwise a red message that + * some failed. Shows passed/failed counts as well. + * + * @param tester* a pointer to a tester from test_initialize + */ +void test_wrapup(tester*); + +/** + * Destroy a tester struct + * + * Essentially frees the memory that was allocated for the struct. + * + * @param tester* a pointer to a tester from test_initialize + */ +void test_destroy(tester*); + +/** + * Exit the program with an appropriate return value + * + * Returns -1 if one or more tests failed, 0 otherwise. Exits the program. + * + * @param tester* a pointer to a tester from test_initialize + * @return don't expect this to return + */ +void test_exit(tester*); + +/** + * Test for truth on a bool + * + * Outputs a red message for failure, and a green one for passing if + * tester->show_pass is true. Adds this test to the summarised data in the + * tester. + * + * @param tester* a pointer to a tester from test_initialize + * @param check the boolean that should be true + * @param test a custom message to show + */ +void test_true(tester* tester, bool check, const char* text); + -- cgit v1.2.3