Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1ff0fc

Browse files
committed
Updates to documentation.
Added additional warnings.
1 parent 4346b57 commit b1ff0fc

4 files changed

Lines changed: 158 additions & 46 deletions

File tree

docs/userguide/annotations.md

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ create or replace package test_package as
136136
end;
137137
/
138138
create or replace package body test_package as
139-
procedure some_test is
140-
begin
141-
null;
142-
end;
139+
procedure some_test is begin null; end;
143140
end;
144141
/
145142
```
@@ -164,10 +161,7 @@ create or replace package test_package as
164161
end;
165162
/
166163
create or replace package body test_package as
167-
procedure some_test is
168-
begin
169-
null;
170-
end;
164+
procedure some_test is begin null; end;
171165
end;
172166
/
173167
```
@@ -194,10 +188,7 @@ create or replace package test_package as
194188
end;
195189
/
196190
create or replace package body test_package as
197-
procedure some_test is
198-
begin
199-
null;
200-
end;
191+
procedure some_test is begin null; end;
201192
end;
202193
/
203194
```
@@ -237,14 +228,10 @@ create or replace package test_package as
237228
end;
238229
/
239230
create or replace package body test_package as
240-
procedure some_test is
241-
begin
242-
null;
243-
end;
244-
procedure other_test is
245-
begin
246-
null;
247-
end;
231+
232+
procedure some_test is begin null; end;
233+
234+
procedure other_test is begin null; end;
248235
end;
249236
/
250237
```
@@ -275,14 +262,10 @@ create or replace package test_package as
275262
end;
276263
/
277264
create or replace package body test_package as
278-
procedure some_test is
279-
begin
280-
null;
281-
end;
282-
procedure other_test is
283-
begin
284-
null;
285-
end;
265+
266+
procedure some_test is begin null; end;
267+
268+
procedure other_test is begin null; end;
286269
end;
287270
/
288271
```
@@ -324,14 +307,10 @@ create or replace package body test_package as
324307
begin
325308
dbms_output.put_line('--- SETUP_STUFF invoked ---');
326309
end;
327-
procedure some_test is
328-
begin
329-
null;
330-
end;
331-
procedure other_test is
332-
begin
333-
null;
334-
end;
310+
311+
procedure some_test is begin null; end;
312+
313+
procedure other_test is begin null; end;
335314
end;
336315
/
337316
```
@@ -351,7 +330,8 @@ Finished in .012292 seconds
351330

352331

353332
When you define multiple beforeall procedures, all of them will get executed before invoking any test in package.
354-
Order of execution for beforeall procedures is defined by the position of the `--%beforeall` annotation in the package specification.
333+
Order of execution for beforeall procedures is defined by the position of the `--%beforeall` annotation in the package specification.
334+
Note that procedure `another_setup` is also invoked before any test, though it's located at the end of package specification.
355335
```sql
356336
create or replace package test_package as
357337
--%suite(Tests for a package)
@@ -375,18 +355,62 @@ Order of execution for beforeall procedures is defined by the position of the `-
375355
begin
376356
dbms_output.put_line('--- ANOTHER_SETUP invoked ---');
377357
end;
358+
378359
procedure initial_setup is
379360
begin
380361
dbms_output.put_line('--- INITIAL_SETUP invoked ---');
381362
end;
382-
procedure some_test is
383-
begin
384-
null;
385-
end;
386-
procedure other_test is
363+
364+
procedure some_test is begin null; end;
365+
366+
procedure other_test is begin null; end;
367+
end;
368+
/
369+
```
370+
371+
```sql
372+
exec ut.run('test_package');
373+
```
374+
```
375+
Tests for a package
376+
--- INITIAL_SETUP invoked ---
377+
--- ANOTHER_SETUP invoked ---
378+
Description of tesed behavior [.004 sec]
379+
Description of another behavior [.004 sec]
380+
381+
Finished in .016672 seconds
382+
2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)
383+
```
384+
385+
When multiple `--%beforeall` annotations are specified for a procedure, the first annotation will be used and a warning message will appear indicating duplicate annotation.
386+
When procedure is annotated as both `--%beforeall` and `--%test`, the procedure will become a test and a warning message will appear indicating invalid annotation combination.
387+
```sql
388+
create or replace package test_package as
389+
--%suite(Tests for a package)
390+
391+
--%beforeall
392+
--%beforeall
393+
procedure initial_setup;
394+
395+
--%test(Description of tesed behavior)
396+
--%beforeall
397+
procedure some_test;
398+
399+
--%test(Description of another behavior)
400+
procedure other_test;
401+
402+
end;
403+
/
404+
create or replace package body test_package as
405+
406+
procedure initial_setup is
387407
begin
388-
null;
408+
dbms_output.put_line('--- INITIAL_SETUP invoked ---');
389409
end;
410+
411+
procedure some_test is begin null; end;
412+
413+
procedure other_test is begin null; end;
390414
end;
391415
/
392416
```

source/core/ut_suite_builder.pkb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,6 @@ create or replace package body ut_suite_builder is
289289
begin
290290
l_test := ut_test(a_suite.object_owner, a_suite.object_name, a_procedure_name);
291291

292-
warning_on_duplicate_annot(a_suite, a_procedure_name, a_annotations, 'test');
293-
-- warning_on_duplicate_annot(a_suite, a_procedure_name, a_annotations, 'displayname');
294-
-- warning_on_duplicate_annot(a_suite, a_procedure_name, a_annotations, 'rollback');
295292
if a_annotations.exists('displayname') then
296293
l_annotation_texts := a_annotations('displayname');
297294
--take the last definition if more than one was provided
@@ -360,6 +357,13 @@ create or replace package body ut_suite_builder is
360357
a_after_each_list in out nocopy ut_executables
361358
) is
362359
begin
360+
warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'test');
361+
-- warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'displayname');
362+
-- warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'rollback');
363+
warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'beforeall');
364+
warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'beforeeach');
365+
warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'afterall');
366+
warning_on_duplicate_annot(a_suite, a_procedure_name, a_proc_annotations, 'aftereach');
363367
if a_proc_annotations.exists('test') then
364368
add_test( a_suite, a_procedure_name, a_proc_annotations);
365369

test/core/test_suite_builder.pkb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,78 @@ create or replace package body test_suite_builder is
168168
);
169169
end;
170170

171+
procedure beforeall_annot_duplicated is
172+
l_actual clob;
173+
l_annotations ut3.ut_annotations;
174+
begin
175+
--Arrange
176+
l_annotations := ut3.ut_annotations(
177+
ut3.ut_annotation(2, 'suite','Cool', null),
178+
ut3.ut_annotation(8, 'beforeall', null, 'test_procedure'),
179+
ut3.ut_annotation(9, 'beforeall', null, 'test_procedure')
180+
);
181+
--Act
182+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
183+
--Assert
184+
ut.expect(l_actual).to_be_like(
185+
'%<DESCRIPTION>Cool</DESCRIPTION>%<WARNINGS>%&quot;--%beforeall&quot;%UT3_TESTER.SOME_PACKAGE.TEST_PROCEDURE%line 9%</WARNINGS>%'
186+
);
187+
end;
188+
189+
procedure beforeeach_annot_duplicated is
190+
l_actual clob;
191+
l_annotations ut3.ut_annotations;
192+
begin
193+
--Arrange
194+
l_annotations := ut3.ut_annotations(
195+
ut3.ut_annotation(2, 'suite','Cool', null),
196+
ut3.ut_annotation(8, 'beforeeach', null, 'test_procedure'),
197+
ut3.ut_annotation(9, 'beforeeach', null, 'test_procedure')
198+
);
199+
--Act
200+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
201+
--Assert
202+
ut.expect(l_actual).to_be_like(
203+
'%<DESCRIPTION>Cool</DESCRIPTION>%<WARNINGS>%&quot;--%beforeeach&quot;%UT3_TESTER.SOME_PACKAGE.TEST_PROCEDURE%line 9%</WARNINGS>%'
204+
);
205+
end;
206+
207+
procedure afterall_annot_duplicated is
208+
l_actual clob;
209+
l_annotations ut3.ut_annotations;
210+
begin
211+
--Arrange
212+
l_annotations := ut3.ut_annotations(
213+
ut3.ut_annotation(2, 'suite','Cool', null),
214+
ut3.ut_annotation(8, 'afterall', null, 'test_procedure'),
215+
ut3.ut_annotation(9, 'afterall', null, 'test_procedure')
216+
);
217+
--Act
218+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
219+
--Assert
220+
ut.expect(l_actual).to_be_like(
221+
'%<DESCRIPTION>Cool</DESCRIPTION>%<WARNINGS>%&quot;--%afterall&quot;%UT3_TESTER.SOME_PACKAGE.TEST_PROCEDURE%line 9%</WARNINGS>%'
222+
);
223+
end;
224+
225+
procedure aftereach_annot_duplicated is
226+
l_actual clob;
227+
l_annotations ut3.ut_annotations;
228+
begin
229+
--Arrange
230+
l_annotations := ut3.ut_annotations(
231+
ut3.ut_annotation(2, 'suite','Cool', null),
232+
ut3.ut_annotation(8, 'aftereach', null, 'test_procedure'),
233+
ut3.ut_annotation(9, 'aftereach', null, 'test_procedure')
234+
);
235+
--Act
236+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
237+
--Assert
238+
ut.expect(l_actual).to_be_like(
239+
'%<DESCRIPTION>Cool</DESCRIPTION>%<WARNINGS>%&quot;--%aftereach&quot;%UT3_TESTER.SOME_PACKAGE.TEST_PROCEDURE%line 9%</WARNINGS>%'
240+
);
241+
end;
242+
171243
procedure suitepath_annot_duplicated is
172244
l_actual clob;
173245
l_annotations ut3.ut_annotations;

test/core/test_suite_builder.pks

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ create or replace package test_suite_builder is
2626
--%test(Gives warning if more than one --%test annotation used)
2727
procedure test_annot_duplicated;
2828

29+
--%test(Gives warning if more than one --%beforeall annotation used)
30+
procedure beforeall_annot_duplicated;
31+
32+
--%test(Gives warning if more than one --%beforeeach annotation used)
33+
procedure beforeeach_annot_duplicated;
34+
35+
--%test(Gives warning if more than one --%afterall annotation used)
36+
procedure afterall_annot_duplicated;
37+
38+
--%test(Gives warning if more than one --%aftereach annotation used)
39+
procedure aftereach_annot_duplicated;
40+
2941
--%test(Gives warning if more than one --%suitepath annotation used)
3042
procedure suitepath_annot_duplicated;
3143

0 commit comments

Comments
 (0)