12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Natools.Tests is
function To_Result (Succeeded : Boolean) return Result is
begin
if Succeeded then
return Success;
else
return Fail;
|
>
>
>
>
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Natools.Tests is
------------------------
-- Helper Subprograms --
------------------------
function To_Result (Succeeded : Boolean) return Result is
begin
if Succeeded then
return Success;
else
return Fail;
|
35
36
37
38
39
40
41
42
|
begin
Item (Report, Test_Name, Code);
Info (Report,
"Exception " & Ada.Exceptions.Exception_Name (Ex) & " raised:");
Info (Report, Ada.Exceptions.Exception_Message (Ex));
end Report_Exception;
end Natools.Tests;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
begin
Item (Report, Test_Name, Code);
Info (Report,
"Exception " & Ada.Exceptions.Exception_Name (Ex) & " raised:");
Info (Report, Ada.Exceptions.Exception_Message (Ex));
end Report_Exception;
-----------------
-- Test Object --
-----------------
function Item
(Report : access Reporter'Class;
Name : String;
Default_Outcome : Result := Success)
return Test is
begin
return Test'(Ada.Finalization.Limited_Controlled with
Report => Report,
Name => Ada.Strings.Unbounded.To_Unbounded_String (Name),
Info => Info_Lists.Empty_List,
Outcome => Default_Outcome,
Finalized => False);
end Item;
procedure Set_Result (Object : in out Test; Outcome : in Result) is
begin
Object.Outcome := Outcome;
end Set_Result;
procedure Info (Object : in out Test; Text : in String) is
begin
Object.Info.Append (Text);
end Info;
procedure Report_Exception
(Object : in out Test;
Ex : in Ada.Exceptions.Exception_Occurrence;
Code : in Result := Error) is
begin
Set_Result (Object, Code);
Info
(Object,
"Exception " & Ada.Exceptions.Exception_Name (Ex) & " raised:");
Info (Object, Ada.Exceptions.Exception_Message (Ex));
end Report_Exception;
procedure Fail (Object : in out Test; Text : in String := "") is
begin
Set_Result (Object, Fail);
if Text /= "" then
Info (Object, Text);
end if;
end Fail;
procedure Error (Object : in out Test; Text : in String := "") is
begin
Set_Result (Object, Error);
if Text /= "" then
Info (Object, Text);
end if;
end Error;
procedure Skip (Object : in out Test; Text : in String := "") is
begin
Set_Result (Object, Skipped);
if Text /= "" then
Info (Object, Text);
end if;
end Skip;
overriding procedure Finalize (Object : in out Test) is
Cursor : Info_Lists.Cursor;
begin
if not Object.Finalized then
Object.Finalized := True;
Object.Report.Item
(Ada.Strings.Unbounded.To_String (Object.Name),
Object.Outcome);
Cursor := Object.Info.First;
while Info_Lists.Has_Element (Cursor) loop
Object.Report.Info (Info_Lists.Element (Cursor));
Info_Lists.Next (Cursor);
end loop;
end if;
end Finalize;
end Natools.Tests;
|