blob: 0438c9c79443b5378d0ba09d93b73fee718a2d9d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/**
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MINCTEST_MINCTEST_H
#define MINCTEST_MINCTEST_H
#include <inttypes.h>
#include <stdbool.h>
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);
#endif // MINCTEST_MINCTEST_H
|