tkoskine / Ahven (http://ahven.sourceforge.net/)

Unit test library for Ada 95

Clone this repository (size: 587.3 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/tkoskine/ahven/
commit 511: 09b78395059d
parent 510: af9ebf5dbff1
branch: default
Backed out changeset af9ebf5dbff1. It isn't necessary for Janus/Ada 3.1.2beta and it is not worth supporting 3.1.1 since it has so many bugs compared to 3.1.2beta.
Tero Koskinen / tkoskine
2 months ago

Changed (Δ5.0 KB):

raw changeset »

src/ahven-listeners-basic.adb (0 lines added, 1 lines removed)

src/ahven-results.adb (0 lines added, 97 lines removed)

src/ahven-results.ads (1 lines added, 61 lines removed)

test/results_tests.adb (0 lines added, 14 lines removed)

Up to file-list src/ahven-listeners-basic.adb:

@@ -64,7 +64,6 @@ package body Ahven.Listeners.Basic is
64
64
   begin
65
65
      if Info.Test_Kind = CONTAINER then
66
66
         R := new Result_Collection;
67
         Init_Collection (R.all);
68
67
         Set_Name (R.all, Info.Test_Name);
69
68
         Set_Parent (R.all, Listener.Current_Result);
70
69

Up to file-list src/ahven-results.adb:

@@ -114,17 +114,6 @@ package body Ahven.Results is
114
114
      return Info.Output_File;
115
115
   end Get_Output_File;
116
116
117
   procedure Init_Collection (Collection : in out Result_Collection)
118
   is
119
   begin
120
      Init_List (Collection.Children);
121
      Collection.Passes := Result_Info_List.Empty_List;
122
      Collection.Failures := Result_Info_List.Empty_List;
123
      Collection.Errors := Result_Info_List.Empty_List;
124
      Collection.Parent := null;
125
      Collection.Test_Name := Empty_VString;
126
   end Init_Collection;
127
128
117
   procedure Add_Child (Collection : in out Result_Collection;
129
118
                        Child      :        Result_Collection_Access) is
130
119
   begin
@@ -392,90 +381,4 @@ package body Ahven.Results is
392
381
      return Child_Depth_Impl (Collection, 0);
393
382
   end Child_Depth;
394
383
395
   package body Result_List is
396
      procedure Init_List (Target : in out List) is
397
      begin
398
         Target.First := null;
399
         Target.Last := null;
400
         Target.Size := 0;
401
      end Init_List;
402
403
      procedure Remove (Ptr : Node_Access) is
404
         procedure Free is
405
           new Ada.Unchecked_Deallocation (Object => Node,
406
                                           Name   => Node_Access);
407
         My_Ptr : Node_Access := Ptr;
408
      begin
409
         Ptr.Next := null;
410
         Free (My_Ptr);
411
      end Remove;
412
413
      procedure Append (Target    : in out List;
414
                        Node_Data :        Result_Collection_Wrapper) is
415
         New_Node : Node_Access  := null;
416
      begin
417
         if Target.Size = Count_Type'Last then
418
            raise List_Full;
419
         end if;
420
421
         New_Node := new Node'(Data => Node_Data, Next => null);
422
423
         if Target.Last = null then
424
            Target.First := New_Node;
425
         else
426
            Target.Last.Next := New_Node;
427
         end if;
428
         Target.Last := New_Node;
429
430
         Target.Size := Target.Size + 1;
431
      end Append;
432
433
      procedure Clear (Target : in out List) is
434
         Current_Node : Node_Access := Target.First;
435
         Next_Node : Node_Access := null;
436
      begin
437
         while Current_Node /= null loop
438
            Next_Node := Current_Node.Next;
439
            Remove (Current_Node);
440
            Current_Node := Next_Node;
441
         end loop;
442
443
         Target.First := null;
444
         Target.Last := null;
445
         Target.Size := 0;
446
      end Clear;
447
448
      function First (Target : List) return Cursor is
449
      begin
450
         return Cursor (Target.First);
451
      end First;
452
453
      function Next (Position : Cursor) return Cursor is
454
      begin
455
         if Position = null then
456
            raise Invalid_Cursor;
457
         end if;
458
         return Cursor (Position.Next);
459
      end Next;
460
461
      function Data (Position : Cursor) return Result_Collection_Wrapper is
462
      begin
463
         if Position = null then
464
            raise Invalid_Cursor;
465
         end if;
466
467
         return Position.Data;
468
      end Data;
469
470
      function Is_Valid (Position : Cursor) return Boolean is
471
      begin
472
         return Position /= null;
473
      end Is_Valid;
474
475
      function Length (Target : List) return Count_Type is
476
      begin
477
         return Target.Size;
478
      end Length;
479
   end Result_List;
480
481
384
end Ahven.Results;

Up to file-list src/ahven-results.ads:

@@ -99,9 +99,6 @@ package Ahven.Results is
99
99
100
100
   type Result_Collection_Access is access Result_Collection;
101
101
102
   procedure Init_Collection (Collection : in out Result_Collection);
103
   -- Initialize the collection, must be called before other actions.
104
105
102
   procedure Add_Child (Collection : in out Result_Collection;
106
103
                        Child      :        Result_Collection_Access);
107
104
   -- Add a child collection to the collection.
@@ -237,64 +234,7 @@ private
237
234
   -- Work around for Janus/Ada 3.1.1d/3.1.2beta generic bug.
238
235
239
236
   package Result_List is
240
      type List is limited private;
241
      type Cursor is private;
242
243
      subtype Count_Type is Natural;
244
245
      Invalid_Cursor : exception;
246
247
      List_Full : exception;
248
      -- Thrown when the size of the list exceeds Count_Type'Last.
249
250
      procedure Init_List (Target : in out List);
251
      -- Initialize the list. Must be called before other actions.
252
253
      procedure Append (Target    : in out List;
254
                        Node_Data :        Result_Collection_Wrapper);
255
      -- Append an element at the end of the list.
256
      --
257
      -- Raises List_Full if the list has already Count_Type'Last items.
258
259
      procedure Clear (Target : in out List);
260
      -- Remove all elements from the list.
261
262
      function First (Target : List) return Cursor;
263
      -- Return a cursor to the first element of the list.
264
265
      function Next (Position : Cursor) return Cursor;
266
      -- Move the cursor to point to the next element on the list.
267
268
      function Data (Position : Cursor) return Result_Collection_Wrapper;
269
      -- Return element pointed by the cursor.
270
271
      function Is_Valid (Position : Cursor) return Boolean;
272
      -- Tell the validity of the cursor. The cursor
273
      -- will become invalid when you iterate it over
274
      -- the last item.
275
276
      function Length (Target : List) return Count_Type;
277
      -- Return the length of the list.
278
279
   private
280
      type Node;
281
      type Node_Access is access Node;
282
      type Cursor is new Node_Access;
283
284
      procedure Remove (Ptr : Node_Access);
285
      -- A procedure to release memory pointed by Ptr.
286
287
      type Node is record
288
         Next : Node_Access := null;
289
         Data : Result_Collection_Wrapper;
290
      end record;
291
292
      type List is limited record
293
         First : Node_Access := null;
294
         Last  : Node_Access := null;
295
         Size  : Count_Type  := 0;
296
      end record;
297
   end Result_List;
237
     new Ahven.SList (Element_Type => Result_Collection_Wrapper);
298
238
299
239
   type Result_Info_Cursor is new Result_Info_List.Cursor;
300
240

Up to file-list test/results_tests.adb:

@@ -44,14 +44,11 @@ package body Results_Tests is
44
44
      Info     : constant Result_Info := Empty_Result_Info;
45
45
   begin
46
46
      Coll_Dyn := new Result_Collection;
47
      Init_Collection (Coll);
48
      Init_Collection (Coll_Dyn.all);
49
47
      Add_Error (Coll, Info);
50
48
      Add_Pass (Coll_Dyn.all, Info);
51
49
52
50
      Add_Child (Coll, Coll_Dyn);
53
51
      Assert (2 = Test_Count (Coll), "Invalid test count");
54
      Release (Coll);
55
52
   end Test_Count_Children;
56
53
57
54
   procedure Test_Direct_Count is
@@ -63,8 +60,6 @@ package body Results_Tests is
63
60
      Expected_Test_Count : constant := 3;
64
61
   begin
65
62
      Coll_Dyn := new Result_Collection;
66
      Init_Collection (Coll);
67
      Init_Collection (Coll_Dyn.all);
68
63
      Add_Error (Coll, Info);
69
64
      Add_Failure (Coll, Info);
70
65
      Add_Pass (Coll, Info);
@@ -78,7 +73,6 @@ package body Results_Tests is
78
73
              & Integer'Image (Direct_Test_Count (Coll)));
79
74
      Assert (1 = Direct_Test_Count (Coll_Dyn.all), "Invalid test count: "
80
75
              & Integer'Image (Direct_Test_Count (Coll_Dyn.all)));
81
      Release (Coll);
82
76
   end Test_Direct_Count;
83
77
84
78
   procedure Test_Result_Iterator is
@@ -90,7 +84,6 @@ package body Results_Tests is
90
84
      Msg  : constant VString := +"hello";
91
85
      Count : Natural;
92
86
   begin
93
      Init_Collection (Coll);
94
87
      Set_Message (Info, Msg);
95
88
      Add_Error (Coll, Info);
96
89
      Add_Failure (Coll, Info);
@@ -128,7 +121,6 @@ package body Results_Tests is
128
121
         Count := Count + 1;
129
122
      end loop;
130
123
      Assert (Count = 1, "Invalid amount of errors");
131
      Release (Coll);
132
124
   end Test_Result_Iterator;
133
125
134
126
   procedure Test_Add_Pass is
@@ -137,10 +129,8 @@ package body Results_Tests is
137
129
      Coll : Result_Collection;
138
130
      Info : constant Result_Info := Empty_Result_Info;
139
131
   begin
140
      Init_Collection (Coll);
141
132
      Add_Pass (Coll, Info);
142
133
      Assert (Pass_Count (Coll) = 1, "Pass was not added!");
143
      Release (Coll);
144
134
   end Test_Add_Pass;
145
135
146
136
   procedure Test_Add_Failure is
@@ -149,10 +139,8 @@ package body Results_Tests is
149
139
      Coll : Result_Collection;
150
140
      Info : constant Result_Info := Empty_Result_Info;
151
141
   begin
152
      Init_Collection (Coll);
153
142
      Add_Failure (Coll, Info);
154
143
      Assert (Failure_Count (Coll) = 1, "Failure was not added!");
155
      Release (Coll);
156
144
   end Test_Add_Failure;
157
145
158
146
   procedure Test_Add_Error is
@@ -161,10 +149,8 @@ package body Results_Tests is
161
149
      Coll : Result_Collection;
162
150
      Info : constant Result_Info := Empty_Result_Info;
163
151
   begin
164
      Init_Collection (Coll);
165
152
      Add_Error (Coll, Info);
166
153
      Assert (Error_Count (Coll) = 1, "Error was not added!");
167
      Release (Coll);
168
154
   end Test_Add_Error;
169
155
170
156
end Results_Tests;