-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcspec.c
58 lines (52 loc) · 1.07 KB
/
cspec.c
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
#include "cspec.h"
typedef struct
{
const char * last_name;
int passed;
int failed;
int pending;
} Cspec_struct;
int initialized = 0;
Cspec_struct CSpec;
void CSpec_init()
{
CSpec.passed = 0;
CSpec.failed = 0;
CSpec.pending = 0;
CSpec.last_name = NULL;
initialized = 1;
}
void describe_f(const char * suit_name)
{
if (!initialized) CSpec_init();
}
void it_f(const char * test_name)
{
if (!initialized) CSpec_init();
CSpec.last_name = test_name;
}
//matchers
void should(char * assert, ...)
{
va_list args;
va_start(args, assert);
if (strcmp(assert, "beEqual") == 0) {
int a = va_arg(args, int);
int b = va_arg(args, int);
if (a == b){
printf(".");
}else{
printf("\nFailure: it %s\n\t%i expected to be %i\n", CSpec.last_name, b, a);
}
}else if (strcmp(assert, "beEqualD") == 0) {
double a = va_arg(args, double), b = va_arg(args, double);
if (a == b){
printf(".");
}else{
printf("\nFailure: it %s\n\t%d expected to be %d\n", CSpec.last_name, b, a);
}
}else{
printf("*");
}
va_end(args);
}