-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinyunit.m4
89 lines (81 loc) · 1.67 KB
/
tinyunit.m4
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
83
84
85
86
87
88
89
// Tiny unittest suite. rlyeh, public domain | wtrmrkrlyeh
// Ported to pascal by Doj
//
// Example:
// ```
//
// // {$I tinyunit.m4} // fallback
// include(tinyunit.m4)
//
// begin
// // orphan test
// test(1<2);
// // grouped tests
// suite('grouped tests 1/1');
// test(1<2);
// test(1<2);
//
// suite('grouped tests 1/2');
// test(1<2);
// test(1<2);
//
// summary;
// end.
//
// '''
//
// Usage:
//
// m4 program.pas > generated.pas
// fpc generated.pas
//
{$IF True}
const
M4_ENABLED_CONST = False;
{$ELSE}
changequote(`<',`>')
changequote(<`>,<&>)
define(`test&,`CurrentFileName := '__file__'; CurrentLine := __line__; writeln_test($*, '$*')&)
define(`M4_ENABLED_CONST&,`True&)
{$ENDIF}
{$IF M4_ENABLED_CONST}
{$DEFINE M4_ENABLED}
{$ENDIF}
var
errno, tst, err: PtrUInt;
ok: Boolean;
CurrentFileName: AnsiString;
CurrentLine: PtrInt;
{$MACRO ON}
{$DEFINE suite := Write('------ '); Writeln}
procedure summary;
begin
suite('summary');
if err > 0 then begin
Write('[FAIL] ');
end else
Write('[ OK ] ');
Writeln(tst, ' tests = ', tst - err, ' passed + ', err, ' errors');
errno := 0;
end;
procedure writeln_test(ok: Boolean; const Condition: AnsiString);
begin
Inc(tst);
if not ok then
Inc(err);
if ok then begin
Write('[ OK ] ');
end else
Write('[FAIL] ');
Writeln(CurrentFileName, ':', CurrentLine, ' ', Condition);
// printf('L%d %s (%s)\n',ok?" OK ":"FAIL",__LINE__,#__VA_ARGS__,strerror(errno))
errno := 0;
end;
{$IF not Defined(M4_ENABLED)}
procedure test(ok: Boolean);
begin
CurrentFileName := '';
CurrentLine := 0;
writeln_test(ok, '');
end;
{$ENDIF}