-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesttest.erl
833 lines (672 loc) · 26.2 KB
/
testtest.erl
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
%%%----------------------------------------------------------------------------
%%% File : testtest.erl
%%% Description : Test of test functions in erlunit.erl
%%% Type : Internal, for development of Erlunit
%%% Version : 0.2.8.2/alpha
%%% Status : alpha
%%% Copyright : (c) 2010 Eonblast Corporation http://www.eonblast.com
%%% License : MIT - http://www.opensource.org/licenses/mit-license.php
%%% Author : H. Diedrich <[email protected]>
%%% Created : 18 Apr 2010
%%% Changed : 23 Apr 2010 - see CHANGES
%%% Tested on : Erlang R13B01
%%%----------------------------------------------------------------------------
%%%
%%% This program is for development of Erlunit, it tests the test functions.
%%%
%%% It's not part of what is needed to use Erlunit. It is not a regular Erlunit
%%% test either, it can break somewhat less controlled.
%%%
%%% To learn about Erlunit, read sample.erl
%%%
%%%----------------------------------------------------------------------------
%%%
%%% Usage
%%%
%%% # erl
%%% 1> {ok,_} = c(erlunit), {ok,_} = c(testtest), testtest:run().
%%%
%%% Copy and paste, it will break before executing run() if there are errors.
%%%
%%%----------------------------------------------------------------------------
%%%
%%% Mail to [email protected] with questions and suggestions, I will
%%% be happy to answer. - Henning
%%%
%%%----------------------------------------------------------------------------
-module(testtest).
-vsn("0.2.8.2/alpha").
-author("H. Diedrich <[email protected]>").
-license("MIT - http://www.opensource.org/licenses/mit-license.php").
-copyright("(c) 2010 Eonblast Corporation http://www.eonblast.com").
%%%----------------------------------------------------------------------------
-export([run/0]).
-import(erlunit).
-include("erlunit.hrl").
-compile({nowarn_unused_function, [suite_verbose/0]}).
%-export([one/0]).
-define(VERSION, "0.2.8.2/alpha").
-define(PROGRAM, "Test-Test").
%%%****************************************************************************
%%% MAIN FUNCTION
%%%****************************************************************************
run() ->
banner("Testing the test functions"),
erlunit:start(),
erlunit:echo("Testing the test functions, basically by trying them all."),
suite_minimal_seq(),
suite_minimal_msg(),
suite_complete(),
suite_complete_inverted(),
suite_complete_verbose(),
suite_complete_verbose_mp(),
suite_complete_mp(),
suite_macros(),
suite_macros_inverted(),
erlunit:execute().
%%%****************************************************************************
%%% SAMPLE SUITES
%%%****************************************************************************
%%%
%%%----------------------------------------------------------------------------
%%% #1 Minimal
%%%----------------------------------------------------------------------------
suite_minimal_seq() ->
erlunit:suite("#1 minimal - sequential"),
erlunit:true(1 == 1),
erlunit:equal(fun() -> one() end, 1),
erlunit:fail(fun() -> 1 / zero() end).
% using zero() for 0 to avoid Erlang compile time warnings
suite_minimal_msg() ->
Suite = erlunit:suite("#2 minimal - message passing"),
Suite ! { true, 1 == 1 },
Suite ! { equal, 1, 1 }.
% Suite ! { fail, fun() -> 1 / zero() end }.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%----------------------------------------------------------------------------
%%% #3: all types of checks
%%%----------------------------------------------------------------------------
%%%
suite_complete() ->
erlunit:suite("#3 all types of checks - sequential"),
% true and false
% -------------------------------
erlunit:true(true),
erlunit:true(1 == 1),
erlunit:not_true(false),
erlunit:not_true(1 == 2),
erlunit:not_true(x),
erlunit:false(false),
erlunit:false(1 == 0),
erlunit:not_false(true),
erlunit:not_false(1 == 1),
erlunit:not_false(x),
% true and false / with functions
% -------------------------------
erlunit:true(fun() -> true end),
erlunit:not_true(fun() -> x end),
erlunit:not_true(fun() -> false end),
erlunit:false(fun() -> false end),
erlunit:not_false(fun() -> x end),
erlunit:not_false(fun() -> true end),
% equality
% -------------------------------
erlunit:equal(1, 1),
erlunit:equal(a, a),
erlunit:equal("a", "a"),
erlunit:exact(1, 1),
erlunit:exact(a, a),
erlunit:exact("a", "a"),
erlunit:not_equal(1, 0),
erlunit:not_equal(1, true),
erlunit:not_equal(1, false),
erlunit:bigger(2, 1),
erlunit:bigger(a, 1),
erlunit:bigger(self(), a),
erlunit:lesser(1, 2),
erlunit:lesser(1, a),
erlunit:lesser(1, self()),
% equality (with functions)
% -------------------------------
erlunit:equal(fun() -> 1 end, 1),
erlunit:exact(fun() -> 1 end, 1),
erlunit:not_equal(fun() -> 1 end, 0),
erlunit:bigger(2, fun() -> 1 end),
erlunit:lesser(fun() -> 1 end, 2),
% control always (functions)
% -------------------------------
erlunit:pass(fun() -> 1 + 0 end),
erlunit:fail(fun() -> throw(sic) end),
erlunit:fail(fun() -> 1 / zero() end),
erlunit:fail(fun() -> exit(sic) end),
erlunit:throws(fun() -> throw(sic) end),
erlunit:error(fun() -> 1 / zero() end),
erlunit:exits(fun() -> exit(sic) end),
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%----------------------------------------------------------------------------
%%% #4: same as above, but inverted
%%%----------------------------------------------------------------------------
%%%
%%% Inversion is for testing the test functions. Not for normal use of Erlunit.
%%% It switches the suite so that it counts passes as fails and vice versa.
%%% Crashes are still counted as crashes, as it should be. Remember that crashes
%%% are not at all the same as a fail(), error(), exits() or throws(). Those
%%% latter catch failing test cases, if they fail on purpose or not. Crashes are
%%% failures higher up in the Erlunit mechanics that point to an error in
%%% Erlunit or a mistake on the part of the developer using Erlunit.
suite_complete_inverted() ->
erlunit:suite("#4 - All checks/inverted", [inverted]),
% true and false
% -------------------------------
% (inverted)
erlunit:not_true(true),
erlunit:not_true(1 == 1),
erlunit:true(false),
erlunit:true(1 == 2),
erlunit:true(x),
erlunit:not_false(false),
erlunit:not_false(1 == 0),
erlunit:false(true),
erlunit:false(1 == 1),
erlunit:false(x),
% true and false / with functions
% -------------------------------
% (inverted)
erlunit:not_true(fun() -> true end),
erlunit:true(fun() -> x end),
erlunit:true(fun() -> false end),
erlunit:not_false(fun() -> false end),
erlunit:false(fun() -> x end),
erlunit:false(fun() -> true end),
% equality
% -------------------------------
% (inverted)
erlunit:not_equal(1, 1),
erlunit:not_equal(a, a),
erlunit:not_equal("a", "a"),
erlunit:equal(1, 0),
erlunit:equal(1, true),
erlunit:equal(1, false),
erlunit:exact(1, 1.0), % =:= -> not -> pass as inverted.
erlunit:exact(1, true),
erlunit:exact(1, false),
erlunit:lesser(2, 1),
erlunit:lesser(a, 1),
erlunit:lesser(self(), a),
erlunit:bigger(1, 2),
erlunit:bigger(1, a),
erlunit:bigger(1, self()),
% equality (with functions)
% -------------------------------
% (inverted)
erlunit:not_equal(fun() -> 1 end, 1),
erlunit:equal(fun() -> 1 end, 0),
erlunit:exact(fun() -> 1 end, 0),
erlunit:lesser(2, fun() -> 1 end),
erlunit:bigger(fun() -> 1 end, 2),
% control always (functions)
% -------------------------------
% (inverted)
erlunit:fail(fun() -> 1 + 0 end),
erlunit:pass(fun() -> throw(sic) end),
erlunit:pass(fun() -> 1 / zero() end),
erlunit:pass(fun() -> exit(sic) end),
erlunit:error(fun() -> throw(sic) end),
erlunit:exits(fun() -> throw(sic) end),
erlunit:throws(fun() -> 1 / zero() end),
erlunit:exits(fun() -> 1 / zero() end),
erlunit:throws(fun() -> exit(sic) end),
erlunit:error(fun() -> exit(sic) end),
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%----------------------------------------------------------------------------
%%% #5: same as above, with names for individual checks = 'verbose'
%%%----------------------------------------------------------------------------
%%%
suite_complete_verbose() ->
erlunit:suite("#5 - All types, verbose"),
% true and false
% -------------------------------
erlunit:true(true, "True is true!"),
erlunit:true(1 == 1, "1=1 is true!"),
erlunit:not_true(false, "False is not true!"),
erlunit:not_true(1 == 2, "1=2 is not true!"),
erlunit:not_true(x, "x is not true!"),
erlunit:false(false, "False is false :-o"),
erlunit:false(1 == 0, "1=0 is false :-("),
erlunit:not_false(true, "True is not false :-)"),
erlunit:not_false(1 == 1, "1=1 is not false :-)"),
erlunit:not_false(x, "x is not false :-)"),
% true and false / with functions
% -------------------------------
erlunit:true(fun() -> true end, "True is true, w/function"),
erlunit:not_true(fun() -> x end, "X is not true, w/function"),
erlunit:not_true(fun() -> false end, "False is not true, w/function"),
erlunit:false(fun() -> false end, "False is false, w/function"),
erlunit:not_false(fun() -> x end, "X is not false :-) w/function"),
erlunit:not_false(fun() -> true end, "True is not false :-) w/function"),
% equality
% -------------------------------
erlunit:equal(1, 1, "1=1 Equality"),
erlunit:equal(a, a, "Atom Equality"),
erlunit:equal("a", "a", "String Equality"),
erlunit:exact(1, 1, "1=1 Exact Equality"),
erlunit:exact(a, a, "Atom Exact Equality"),
erlunit:exact("a", "a", "String Exact Equality"),
erlunit:not_equal(1, 0, "Numberic Non-Equality"),
erlunit:not_equal(1, true, "Type Inequality"),
erlunit:not_equal(1, false, "Type Inequality"),
erlunit:bigger(2, 1, "Numeric Bigger"),
erlunit:bigger(a, 1, "Bigger By Type"),
erlunit:bigger(self(), a, "Bigger By Type II"),
erlunit:lesser(1, 2, "Numberic Lesser"),
erlunit:lesser(1, a, "Number lesser than Atom"),
erlunit:lesser(1, self(), "Type of Number smaller than Pid"),
% equality (with functions)
% -------------------------------
erlunit:equal(fun() -> 1 end, 1, "1=1 Equality, w/function"),
erlunit:exact(fun() -> 1 end, 1, "1=1 Exact Equality, w/function"),
erlunit:not_equal(fun() -> 1 end, 0, "1=0 Inequality, w/function"),
erlunit:bigger(2, fun() -> 1 end, "2>1, w/function"),
erlunit:lesser(fun() -> 1 end, 2, "1<2, w/function"),
% control always (functions)
% -------------------------------
erlunit:pass(fun() -> 1 + 0 end, "Pass of Calculation, w/function"),
erlunit:fail(fun() -> throw(sic) end, "Fail by throw, w/function"),
erlunit:fail(fun() -> 1 / zero() end, "Fail by error, w/function"),
erlunit:fail(fun() -> exit(sic) end, "Fail by exit, w/function"),
erlunit:throws(fun() -> throw(sic) end, "Control Exception, w/function"),
erlunit:error(fun() -> 1 / zero() end, "Control Error Condition, w/function"),
erlunit:exits(fun() -> exit(sic) end, "Control Exit, w/function"),
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%
%%%----------------------------------------------------------------------------
%%% #6: same as above, names for every check, but message passing style
%%%----------------------------------------------------------------------------
%%%
suite_complete_verbose_mp() ->
Suite = erlunit:suite( "#6 - All types, verbose, message passing style" ),
% true and false
% -------------------------------
Suite ! { true, true, "True is true!" },
Suite ! { true, 1 == 1, "1=1 is true!" },
Suite ! { not_true, false, "False is not true!" },
Suite ! { not_true, 1 == 2, "1=2 is not true!" },
Suite ! { not_true, x, "x is not true!" },
Suite ! { false, false, "False is false :-o" },
Suite ! { false, 1 == 0, "1=0 is false :-(" },
Suite ! { not_false, true, "True is not false :-)" },
Suite ! { not_false, 1 == 1, "1=1 is not false :-)" },
Suite ! { not_false, x, "x is not false :-)" },
% true and false / with functions
% -------------------------------
Suite ! { true, fun() -> true end, "True is true, w/function" },
Suite ! { not_true, fun() -> x end, "X is not true, w/function" },
Suite ! { not_true, fun() -> false end, "False is not true, w/function" },
Suite ! { false, fun() -> false end, "False is false, w/function" },
Suite ! { not_false, fun() -> x end, "X is not false :-) w/function" },
Suite ! { not_false, fun() -> true end, "True is not false :-) w/function" },
% equality
% -------------------------------
Suite ! { equal, 1, 1, "1=1 Equality" },
Suite ! { equal, a, a, "Atom Equality" },
Suite ! { equal, "a", "a", "String Equality" },
Suite ! { exact, 1, 1, "1=1 Exact Equality" },
Suite ! { exact, a, a, "Atom Exact Equality" },
Suite ! { exact, "a", "a", "String Exact Equality" },
Suite ! { not_equal, 1, 0, "Numberic Non-Equality" },
Suite ! { not_equal, 1, true, "Type Inequality" },
Suite ! { not_equal, 1, false, "Type Inequality" },
Suite ! { bigger, 2, 1, "Numeric Bigger" },
Suite ! { bigger, a, 1, "Bigger By Type" },
Suite ! { bigger, self(), a, "Bigger By Type II" },
Suite ! { lesser, 1, 2, "Numberic Lesser" },
Suite ! { lesser, 1, a, "Number lesser than Atom" },
Suite ! { lesser, 1, self(), "Type of Number smaller than Pid" },
% equality (with functions)
% -------------------------------
Suite ! { equal, fun() -> 1 end, 1, "1=1 Equality, w/function" },
Suite ! { exact, fun() -> 1 end, 1, "1=1 Exact Equality, w/function" },
Suite ! { not_equal, fun() -> 1 end, 0, "1=0 Inequality, w/function" },
Suite ! { bigger, 2, fun() -> 1 end, "2>1, w/function" },
Suite ! { lesser, fun() -> 1 end, 2, "1<2, w/function" },
% control always (functions)
% -------------------------------
Suite ! { pass, fun() -> 1 + 0 end, "Pass of Calculation, w/function" },
Suite ! { fail, fun() -> throw(sic) end, "Fail by throw, w/function" },
Suite ! { fail, fun() -> 1 / zero() end, "Fail by error, w/function" },
Suite ! { fail, fun() -> exit(sic) end, "Fail by exit, w/function" },
Suite ! { throws, fun() -> throw(sic) end, "Control Exception, w/function" },
Suite ! { error, fun() -> 1 / zero() end, "Control Error Condition, w/function" },
Suite ! { exits, fun() -> exit(sic) end, "Control Exit, w/function" },
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%
%%%----------------------------------------------------------------------------
%%% #7: same as above, but without text element
%%%----------------------------------------------------------------------------
%%%
suite_complete_mp() ->
Suite = erlunit:suite( "#7 - All types, non-verbose, message passing style" ),
% true and false
% -------------------------------
Suite ! { true, true },
Suite ! { true, 1 == 1 },
Suite ! { not_true, false },
Suite ! { not_true, 1 == 2 },
Suite ! { not_true, x },
Suite ! { false, false },
Suite ! { false, 1 == 0 },
Suite ! { not_false, true },
Suite ! { not_false, 1 == 1 },
Suite ! { not_false, x },
% true and false / with functions
% -------------------------------
Suite ! { true, fun() -> true end },
Suite ! { not_true, fun() -> x end },
Suite ! { not_true, fun() -> false end },
Suite ! { false, fun() -> false end },
Suite ! { not_false, fun() -> x end },
Suite ! { not_false, fun() -> true end },
% equality
% -------------------------------
Suite ! { equal, 1, 1 },
Suite ! { equal, a, a },
Suite ! { equal, "a", "a" },
Suite ! { exact, 1, 1 },
Suite ! { exact, a, a },
Suite ! { exact, "a", "a" },
Suite ! { not_equal, 1, 0 },
Suite ! { not_equal, 1, true },
Suite ! { not_equal, 1, false },
Suite ! { bigger, 2, 1 },
Suite ! { bigger, a, 1 },
Suite ! { bigger, self(), a },
Suite ! { lesser, 1, 2 },
Suite ! { lesser, 1, a },
Suite ! { lesser, 1, self() },
% equality (with functions)
% -------------------------------
Suite ! { equal, fun() -> 1 end, 1 },
Suite ! { exact, fun() -> 1 end, 1 },
Suite ! { not_equal, fun() -> 1 end, 0 },
Suite ! { bigger, 2, fun() -> 1 end },
Suite ! { lesser, fun() -> 1 end, 2 },
% control always (functions)
% -------------------------------
Suite ! { pass, fun() -> 1 + 0 end },
Suite ! { fail, fun() -> throw(sic) end },
Suite ! { fail, fun() -> 1 / zero() end },
Suite ! { fail, fun() -> exit(sic) end },
Suite ! { throws, fun() -> throw(sic) end },
Suite ! { error, fun() -> 1 / zero() end },
Suite ! { exits, fun() -> exit(sic) end },
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%----------------------------------------------------------------------------
%%% #2: same as above, with names for individual checks
%%%----------------------------------------------------------------------------
%%%
%%% NOT YET USED
suite_verbose() ->
erlunit:suite("#2 - Very Simple / verbose"),
erlunit:echo("Suite #2 gives names to individual checks"),
erlunit:true(1 == 1, "One Equals One"),
erlunit:false(1 == 0, "One Equals Zero"),
erlunit:not_true(1 == 2, "One Does Not Equal Two"),
erlunit:not_false(foo, "Foo Is Not True"),
erlunit:not_false(1 == 1, "One Not Not Equals One"),
erlunit:not_false(bar, "Bar Is Not False"),
erlunit:equal(1, 1, "Once More Equality"),
erlunit:not_equal(1, 0, "And Non-Equality"),
erlunit:pass(fun() -> 1 + 0 end, "Trivial Fun"),
erlunit:fail(fun() -> 1 / zero() end, "Div By Zero").
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%----------------------------------------------------------------------------
%%% #8: macros
%%%----------------------------------------------------------------------------
%%%
suite_macros() ->
erlunit:suite("#8 macros"),
?ERLUNIT_TRUE(1 == 1),
?ERLUNIT_TRUE(_A = true), % sic
?ERLUNIT_TRUE(0 < b), % sic
?ERLUNIT_TRUE_MSG(1 == 1, "One equals One"),
?ERLUNIT_TRUE_MSG(_A = true, "A is assigned true"),
?ERLUNIT_TRUE_MSG(0 < b, "A Number Is Smaller Than an Atom"),
?ERLUNIT_NOT_TRUE(1 == 2),
?ERLUNIT_NOT_TRUE(1),
?ERLUNIT_NOT_TRUE(0 > b),
?ERLUNIT_NOT_TRUE_MSG(1 == 2, "One is not Two"),
?ERLUNIT_NOT_TRUE_MSG(1, "One is not True"),
?ERLUNIT_NOT_TRUE_MSG(0 > b, "A Number Is Not Bigger Than an Atom"),
?ERLUNIT_FALSE(1 == 2),
?ERLUNIT_FALSE(false),
?ERLUNIT_FALSE(0 > b),
?ERLUNIT_FALSE_MSG(1 == 2, "One is not Two"),
?ERLUNIT_FALSE_MSG(not true, "Not true is false"),
?ERLUNIT_FALSE_MSG(0 > b, "A Number Is Not Bigger Than an Atom"),
?ERLUNIT_NOT_FALSE(1 == 1),
?ERLUNIT_NOT_FALSE(1),
?ERLUNIT_NOT_FALSE(0 < b),
?ERLUNIT_NOT_FALSE_MSG(1 == 1, "One is One"),
?ERLUNIT_NOT_FALSE_MSG(1, "One is not False"),
?ERLUNIT_NOT_FALSE_MSG(0 < b, "A Number Is Smaller Than an Atom"),
%%% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?ERLUNIT_FAIL(1 / zero()),
?ERLUNIT_FAIL(exit(sic)),
?ERLUNIT_FAIL(throw(sic)),
?ERLUNIT_FAIL_MSG(1 / zero(), "Error: One By Zero"),
?ERLUNIT_FAIL_MSG(exit(sic), "Exit"),
?ERLUNIT_FAIL_MSG(throw(sic), "Throw"),
?ERLUNIT_PASS(1 / 1),
?ERLUNIT_PASS(_A = a),
?ERLUNIT_PASS(0 < b),
?ERLUNIT_PASS_MSG(1 / 1, "One by One"),
?ERLUNIT_PASS_MSG(_A = a, "A Can Become a"),
?ERLUNIT_PASS_MSG(0 < b, "A Number Is Smaller Than an Atom"),
?ERLUNIT_EXITS(exit(sic)),
?ERLUNIT_EXITS_MSG(exit(sic), "Exit"),
?ERLUNIT_THROWS(throw(sic)),
?ERLUNIT_THROWS_MSG(throw(sic), "Throw"),
?ERLUNIT_ERROR(1 / zero()),
?ERLUNIT_ERROR_MSG(1 / zero(), "Error: One By Zero"),
%%% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?ERLUNIT_EQUAL(true, true),
?ERLUNIT_EQUAL(1, 1.0),
?ERLUNIT_EQUAL(0, -0),
?ERLUNIT_EQUAL_MSG(true, true, "True is True"),
?ERLUNIT_EQUAL_MSG(1, 1.0, "One (Integer) is One (Float)"),
?ERLUNIT_EQUAL_MSG(0, -0, "Zero is minus Zero"),
?ERLUNIT_NOT_EQUAL(true, false),
?ERLUNIT_NOT_EQUAL(1, 2),
?ERLUNIT_NOT_EQUAL(true, 1),
?ERLUNIT_NOT_EQUAL_MSG(true, false, "True is not equal False"),
?ERLUNIT_NOT_EQUAL_MSG(1, 2, "One is not equal Two"),
?ERLUNIT_NOT_EQUAL_MSG(true, 1, "True is not equal 1"),
?ERLUNIT_EXACT(true, true),
?ERLUNIT_EXACT(1, 1),
?ERLUNIT_EXACT(true, 1 == 1),
?ERLUNIT_EXACT_MSG(true, true, "True exactly equals True"),
?ERLUNIT_EXACT_MSG(1, 1, "One exactly equals One"),
?ERLUNIT_EXACT_MSG(true, 1==1, "True exactly equals (1==1)"),
?ERLUNIT_BIGGER(2, 1),
?ERLUNIT_BIGGER(a, 0),
?ERLUNIT_BIGGER(true, false),
?ERLUNIT_BIGGER_MSG(2, 1, "Two is bigger than One"),
?ERLUNIT_BIGGER_MSG(a, 0, "An Atom is bigger than Zero"),
?ERLUNIT_BIGGER_MSG(true, false, "True is bigger than false"),
?ERLUNIT_LESSER(1, 2),
?ERLUNIT_LESSER(0, a),
?ERLUNIT_LESSER(1, 1.1),
?ERLUNIT_LESSER_MSG(1, 2, "One is lesser than Two"),
?ERLUNIT_LESSER_MSG(0, a, "Zero is lesser than an Atom"),
?ERLUNIT_LESSER_MSG(1, 1.1, "One is lesser than One point One"),
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%----------------------------------------------------------------------------
%%% #9: macros, inverted
%%%----------------------------------------------------------------------------
%%%
suite_macros_inverted() ->
erlunit:suite("#9 - macros, inverted", [inverted]),
% inverted!
?ERLUNIT_TRUE(1 /= 1),
?ERLUNIT_TRUE(_A = false), % sic
?ERLUNIT_TRUE(0 > b), % sic
% inverted!
?ERLUNIT_TRUE_MSG(1 /= 1, "One equals One"),
?ERLUNIT_TRUE_MSG(_A = false, "A is assigned false"),
?ERLUNIT_TRUE_MSG(0 > b, "A Number Is Bigger Than an Atom"),
% inverted!
?ERLUNIT_NOT_TRUE(1 /= 2),
?ERLUNIT_NOT_TRUE(true),
?ERLUNIT_NOT_TRUE(0 < b),
% inverted!
?ERLUNIT_NOT_TRUE_MSG(1 == 1, "One is One"),
?ERLUNIT_NOT_TRUE_MSG(true, "True is not True"),
?ERLUNIT_NOT_TRUE_MSG(0 < b, "A Number Is Smaller Than an Atom"),
% inverted!
?ERLUNIT_FALSE(1 == 1),
?ERLUNIT_FALSE(true),
?ERLUNIT_FALSE(0 < b),
% inverted!
?ERLUNIT_FALSE_MSG(1 == 1, "One is One"),
?ERLUNIT_FALSE_MSG(not false, "Not false is false"),
?ERLUNIT_FALSE_MSG(0 < b, "A Number Is Smaller Than an Atom"),
% inverted!
?ERLUNIT_NOT_FALSE(1 == 2),
?ERLUNIT_NOT_FALSE(false),
?ERLUNIT_NOT_FALSE(0 > b),
% inverted!
?ERLUNIT_NOT_FALSE_MSG(1 == 2, "One is Two"),
?ERLUNIT_NOT_FALSE_MSG(false, "False is not False"),
?ERLUNIT_NOT_FALSE_MSG(0 > b, "A Number Is Bigger Than an Atom"),
%%% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% inverted!
?ERLUNIT_FAIL(_A = a),
?ERLUNIT_FAIL_MSG(_A = a, "A = a"),
% expected to crash, which will in this inverted suite count as pass:
?ERLUNIT_PASS(1 / zero()),
?ERLUNIT_PASS(exit(sic)),
?ERLUNIT_PASS(throw(sic)),
% inverted!
?ERLUNIT_PASS_MSG(1 / zero(), "One By Zero"),
?ERLUNIT_PASS_MSG(exit(sic), "Exit"),
?ERLUNIT_PASS_MSG(throw(sic), "Throw"),
% inverted!
?ERLUNIT_THROWS(exit(sic)),
?ERLUNIT_THROWS(_A = a),
?ERLUNIT_THROWS(1 / zero()),
% inverted!
?ERLUNIT_THROWS_MSG(exit(sic), "Exit"),
?ERLUNIT_THROWS_MSG(_A = a, "A = a"),
?ERLUNIT_THROWS_MSG(1 / zero(), "Error (1/0)"),
% inverted!
?ERLUNIT_ERROR(exit(sic)),
?ERLUNIT_ERROR(throw(sic)),
?ERLUNIT_ERROR(_A = a),
% inverted!
?ERLUNIT_ERROR_MSG(exit(sic), "Exit"),
?ERLUNIT_ERROR_MSG(throw(sic), "Throw"),
?ERLUNIT_ERROR_MSG(_A = a, "A = a"),
% inverted!
?ERLUNIT_EXITS(_A = a),
?ERLUNIT_EXITS(throw(sic)),
?ERLUNIT_EXITS(1 / zero()),
% inverted!
?ERLUNIT_EXITS_MSG(_A = a, "A = a"),
?ERLUNIT_EXITS_MSG(throw(sic), "Throw"),
?ERLUNIT_EXITS_MSG(1 / zero(), "Error (1/0)"),
%%% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% inverted!
?ERLUNIT_EQUAL(true, false),
?ERLUNIT_EQUAL(1, 2),
?ERLUNIT_EQUAL(a, b),
% inverted!
?ERLUNIT_EQUAL_MSG(true, false, "True is False"),
?ERLUNIT_EQUAL_MSG(1, 2, "One is Two"),
?ERLUNIT_EQUAL_MSG(a, b, "a is b"),
% inverted!
?ERLUNIT_NOT_EQUAL(true, true),
?ERLUNIT_NOT_EQUAL(1, 1),
?ERLUNIT_NOT_EQUAL(true, 1 == 1),
% inverted!
?ERLUNIT_NOT_EQUAL_MSG(true, true, "True is not equal True"),
?ERLUNIT_NOT_EQUAL_MSG(1, 1, "One is not equal One"),
?ERLUNIT_NOT_EQUAL_MSG(true, 1 == 1, "True is equal (1 == 1)"),
% inverted!
?ERLUNIT_EXACT(true, false),
?ERLUNIT_EXACT(1, 1.0),
?ERLUNIT_EXACT(false, 1 == 1),
% inverted!
?ERLUNIT_EXACT_MSG(true, false, "True exactly equals False"),
?ERLUNIT_EXACT_MSG(1, 1.0, "One (Integer) exactly equals One (Integer)"),
?ERLUNIT_EXACT_MSG(false, 1==1, "False exactly equals (1==1)"),
% inverted!
?ERLUNIT_BIGGER(1, 1),
?ERLUNIT_BIGGER(0, a),
?ERLUNIT_BIGGER(false, true),
% inverted!
?ERLUNIT_BIGGER_MSG(1, 2, "One is bigger than Two"),
?ERLUNIT_BIGGER_MSG(0, a, "An Number is bigger than an Atom"),
?ERLUNIT_BIGGER_MSG(falser, truer, "Falser is bigger than Truer"),
% inverted!
?ERLUNIT_LESSER(2, 1),
?ERLUNIT_LESSER(a, 0),
?ERLUNIT_LESSER(1.1, 1),
% inverted!
?ERLUNIT_LESSER_MSG(2, 1, "Two is lesser than One"),
?ERLUNIT_LESSER_MSG(a, 0, "a is lesser than 0"),
?ERLUNIT_LESSER_MSG(1.1, 1, "One point one is lesser than One"),
ok.
% using zero() for 0 to avoid Erlang compile time warnings
%%%
%%%****************************************************************************
%%% UTILITY
%%%****************************************************************************
%%%
%%%----------------------------------------------------------------------------
%%% This is used to avoid Erlang compile time warnings.
%%%----------------------------------------------------------------------------
zero() -> 0.
%%%
%%%----------------------------------------------------------------------------
%%% This is used to test the automatic execution of funs in payload/1.
%%%----------------------------------------------------------------------------
one() -> 1.
%%%****************************************************************************
%%% SCREEN UTILITY
%%%****************************************************************************
%%%
%%% This duplicates utility source in sample.erl
-define(WIDTH, 75).
-define(DASHLINE, string:chars($*, ?WIDTH)).
%%%----------------------------------------------------------------------------
%%% Banner
%%%----------------------------------------------------------------------------
%%%
%%% Centered banner with text only
banner(Text) ->
io:format("~s~n~s~s~n~s~n",[?DASHLINE, center_indent(Text, ?WIDTH), Text,?DASHLINE]).
%%%----------------------------------------------------------------------------
%%% Centering a headline
%%%----------------------------------------------------------------------------
center_indent(Text, Width) ->
string:chars(32, erlang:max(0, trunc((Width - length(Text)) / 2))).
%%%----------------------------------------------------------------------------
%%% Further reading
%%%----------------------------------------------------------------------------
%%%
%%% The actual test functions are in erlunit.erl
%%% View online at http://github.com/Eonblast/Erlunit/blob/master/erlunit.erl