-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_suite-features.adb
241 lines (188 loc) · 8.05 KB
/
test_suite-features.adb
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
-------------------------------------------------------------------------------
-- XReq -- Behaviour Driven Developpement tool for compiled languages --
-- Copyright (c) 2010, SOGILIS <http://sogilis.com> --
-- --
-- This program is free software: you can redistribute it and/or modify --
-- it under the terms of the GNU Affero General Public License as --
-- published by the Free Software Foundation, either version 3 of the --
-- License, or (at your option) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
-- GNU Affero General Public License for more details. --
-- --
-- You should have received a copy of the GNU Affero General Public License --
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
-- --
-------------------------------------------------------------------------------
with XReq;
with XReqLib;
with XReq.Steps;
with XReq.Steps.Handles;
with XReq.Scenarios.Handles;
with XReq.Features;
with XReq.Features.Files;
with Util.IO;
with Util.Strings;
use XReq;
use XReqLib;
use XReq.Steps;
use XReq.Steps.Handles;
use XReq.Scenarios.Handles;
use XReq.Features;
use XReq.Features.Files;
use Util.IO;
use Util.Strings;
package body Test_Suite.Features is
procedure Add_Tests (
Ret : in AUnit.Test_Suites.Access_Test_Suite)
is
begin
Ret.Add_Test (new Test_1);
Ret.Add_Test (new Test_2);
end Add_Tests;
-- Test_1 ----------------------------------------------------------------
function Name (T : in Test_1) return String is
pragma Unreferenced (T);
begin
return ("XReq.Features simplest.feature");
end Name;
procedure Run (T : in out Test_1) is
use Text_IO;
Feature : Feature_File_Type := Null_Feature_File;
File : constant String := "tests/features/simplest.feature";
Scenario : Scenario_Handle;
Stanza : Step_Handle;
CRLF : constant String := "" & ASCII.LF;
Canonical_Feature_Text : constant String :=
"# File: " & File & CRLF &
"Feature: Sample" & CRLF &
"" & CRLF &
" Background: " & CRLF &
" Given this step works" & CRLF &
"" & CRLF &
" Scenario: Run a good step" & CRLF &
" Given this step works" & CRLF &
"" & CRLF;
begin
T.Assert (not Parsed (Feature),
"Feature has been parsed without invoking Make");
declare
procedure P;
procedure P is
S : constant String := To_String (Feature);
pragma Unreferenced (S);
begin
null;
end P;
procedure Assert_Exception_Raised is new Assert_Except (Test_1, P);
begin
Assert_Exception_Raised (T,
"1:To_String should raise Unparsed_Feature",
Unparsed_Feature'Identity);
end;
Make (Feature, File);
T.Assert (File_Name (Feature) = File,
"Feature filename (" & File_Name (Feature) & ") is incorrect");
T.Assert (not Parsed (Feature),
"Feature has been parsed without invoking Parse");
declare
procedure P;
procedure P is
S : constant String := To_String (Feature);
pragma Unreferenced (S);
begin
null;
end P;
procedure Assert_Exception_Raised is new Assert_Except (Test_1, P);
begin
Assert_Exception_Raised (T,
"2:To_String should raise Unparsed_Feature",
Unparsed_Feature'Identity);
end;
Parse (Feature, Std_Logger);
T.Assert (Parsed (Feature),
"Feature has not been parsed after invoking Parse");
Put_Line (To_String (Feature));
T.Assert (Feature.Name = "Sample",
"Feature name incorrect");
T.Assert (Feature.Description = "",
"Feature description while there is none");
T.Assert (Feature.Background.R.Name = "",
"Background name while there is none");
T.Assert (Feature.Background.R.Step_Count /= 0,
"No background stanzas");
T.Assert (Feature.Background.R.Step_Count = 1,
"More than one line of background");
Stanza := Feature.Background.R.Step_Element (0);
T.Assert (Stanza.R.Kind = Step_Given,
"The first step of the background is not a Given");
T.Assert (Stanza.R.Stanza = "this step works",
"Text of the first given of background incorrect");
T.Assert (Feature.Scenario_Count /= 0,
"No scenario");
T.Assert (Feature.Scenario_Count = 1,
"More than one scenario");
Scenario := Feature.Scenario_Element (0);
T.Assert (Scenario.R.Name = "Run a good step",
"Name of the scenario incorrect");
T.Assert (Scenario.R.Step_Count = 1,
"No or more than one stanza in the scenario");
Stanza := Scenario.R.Step_Element (0);
T.Assert (Stanza.R.Kind = Step_Given,
"The first step of the scenario is not a Given");
T.Assert (Stanza.R.Stanza = "this step works",
"Text of the first given of scenario incorrect");
T.Assert (Feature.To_String = Canonical_Feature_Text,
"To_String do not match the canonical text." & ASCII.LF &
"Got: " & Ada_String (Feature.To_String) & ASCII.LF &
"Expected: " & Ada_String (Canonical_Feature_Text));
end Run;
-- Test_2 ----------------------------------------------------------------
function Name (T : in Test_2) return String is
pragma Unreferenced (T);
begin
return ("XReq.Features.Same simplest2.feature");
end Name;
procedure Run (T : in out Test_2) is
use Text_IO;
Feature1 : Feature_Type := Null_Feature;
Feature2 : Feature_File_Type;
File : constant String := "tests/features/simplest2.feature";
Scenario : Scenario_Handle;
begin
Make (Feature1, "Sample2");
T.Assert (Feature1.Name = "Sample2", "Incorrect feature name");
T.Assert (Feature1.Parsed, "Feature_Type is always parsed");
Scenario := Create;
Scenario.R.Make ("Background");
Scenario.R.Step_Append (Stanza_Given ("this step works"));
Feature1.Set_Background (Scenario);
Scenario := Create;
Scenario.R.Make ("Run a good step");
Scenario.R.Step_Append (Stanza_Given ("this step works"));
Scenario.R.Step_Append (Stanza_Given
("I am in front of a cake machine"));
Scenario.R.Step_Append (Stanza_When ("I insert money"));
Scenario.R.Step_Append (Stanza_When ("I push the button"));
Scenario.R.Step_Append (Stanza_Then ("I get a cake"));
Feature1.Scenario_Append (Scenario);
Scenario := Create;
Scenario.R.Make ("Another good step");
Scenario.R.Step_Append (Stanza_Given ("this step works"));
Feature1.Scenario_Append (Scenario);
Make (Feature2, File);
Parse (Feature2, Std_Logger);
Put_Line ("Feature1:");
Put_Line (Feature1.To_String);
Put_Line ("Feature2:");
Put_Line (Feature2.To_String);
T.Assert (Feature1.To_String = Feature_Type (Feature2).To_String,
"The two features text representation must be the same");
exception
when Error : others =>
Put_Line (Exception_Information (Error));
Reraise_Occurrence (Error);
end Run;
end Test_Suite.Features;