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

Skip to content

Commit 60c0097

Browse files
authored
Merge branch 'develop' into feature/cleanup_code_and_tests_a_bit
2 parents ce9f520 + 48ea16a commit 60c0097

6 files changed

Lines changed: 100 additions & 11 deletions

File tree

docs/userguide/annotations.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ We strongly recommend putting package level annotations at the very top of packa
2121
| `--%suitepath(<path>)` | Package | Similar to java package. The annotation allows logical grouping of suites into hierarchies. |
2222
| `--%displayname(<description>)` | Package/procedure | Human-readable and meaningful description of a suite/test. `%displayname(Name of the suite/test)`. The annotation is provided for flexibility and convenience only. It has exactly the same meaning as `<description>` in `test` and `suite` annotations. If description is provided using both `suite`/`test` and `displayname`, then the one defined as last takes precedence. |
2323
| `--%test(<description>)` | Procedure | Denotes that the annotated procedure is a unit test procedure. Optional test description can by provided (see `displayname`). |
24-
| `--%throws(<exception_number>[,<exception_number>[,...]])`| Procedure | Denotes that the annotated procedure must throw one of the exception numbers provided. If no valid numbers were provided as annotation parameters the annotation is ignored. Applicable to test procedures only. |
24+
| `--%throws(<exception|>[,...])`| Procedure | Denotes that the annotated test procedure must throw one of the exceptions provided. Supported forms of exceptions are: numeric literals, numeric contant names, exception constant names, predefined Oracle exception names. |
2525
| `--%beforeall` | Procedure | Denotes that the annotated procedure should be executed once before all elements of the suite. |
2626
| `--%beforeall([[<owner>.]<package>.]<procedure>[,...])` | Package | Denotes that the mentioned procedure(s) should be executed once before all elements of the suite. |
2727
| `--%afterall` | Procedure | Denotes that the annotated procedure should be executed once after all elements of the suite. |
@@ -1081,6 +1081,7 @@ Below test suite defines:
10811081
```sql
10821082
create or replace package test_rooms_management is
10831083

1084+
gc_null_value_exception constant integer := -1400;
10841085
--%suite(Rooms management)
10851086

10861087
--%beforeall
@@ -1104,11 +1105,11 @@ create or replace package test_rooms_management is
11041105
--%description(Add content to a room)
11051106

11061107
--%test(Fails when room name is not valid)
1107-
--%throws(-1403)
1108+
--%throws(no_data_found)
11081109
procedure fails_on_room_name_invalid;
11091110

11101111
--%test(Fails when content name is null)
1111-
--%throws(-1400)
1112+
--%throws(gc_null_value_exception)
11121113
procedure fails_on_content_null;
11131114

11141115
--%test(Adds a content to existing room)
@@ -1170,7 +1171,7 @@ create or replace package body test_rooms_management is
11701171
begin
11711172
--Act
11721173
add_rooms_content('Dining Room',null);
1173-
--Assert by --%throws annotation
1174+
--Assert done by --%throws annotation
11741175
end;
11751176

11761177
procedure add_content_success is

source/check_object_grants.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ declare
22
c_expected_grants constant dbmsoutput_linesarray := dbmsoutput_linesarray('DBMS_LOCK','DBMS_CRYPTO');
33

44
l_missing_grants varchar2(4000);
5+
l_target_table varchar2(128);
6+
l_owner_column varchar2(128);
57

68
function get_view(a_dba_view_name varchar2) return varchar2 is
79
l_invalid_object_name exception;
@@ -16,16 +18,18 @@ declare
1618
end;
1719

1820
begin
21+
l_target_table := get_view('dba_tab_privs');
22+
l_owner_column := case when l_target_table like 'dba%' then 'owner' else 'table_schema' end;
1923
execute immediate q'[
2024
select listagg(' - '||object_name,CHR(10)) within group(order by object_name)
2125
from (
2226
select column_value as object_name
2327
from table(:l_expected_grants)
2428
minus
2529
select table_name as object_name
26-
from ]'||get_view('dba_tab_privs')||q'[
30+
from ]'||l_target_table||q'[
2731
where grantee = SYS_CONTEXT('userenv','current_schema')
28-
and owner = 'SYS')]'
32+
and ]'||l_owner_column||q'[ = 'SYS')]'
2933
into l_missing_grants using c_expected_grants;
3034
if l_missing_grants is not null then
3135
raise_application_error(
@@ -37,4 +41,3 @@ begin
3741
end if;
3842
end;
3943
/
40-

source/core/ut_suite_builder.pkb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ create or replace package body ut_suite_builder is
3737
gc_context constant t_annotation_name := 'context';
3838
gc_endcontext constant t_annotation_name := 'endcontext';
3939

40+
type tt_annotations is table of t_annotation_name;
41+
42+
gc_supported_annotations constant tt_annotations
43+
:= tt_annotations(
44+
gc_suite,
45+
gc_suitepath,
46+
gc_test,
47+
gc_disabled,
48+
gc_displayname,
49+
gc_beforeall,
50+
gc_beforeeach,
51+
gc_beforetest,
52+
gc_afterall,
53+
gc_aftereach,
54+
gc_aftertest,
55+
gc_throws,
56+
gc_rollback,
57+
gc_context,
58+
gc_endcontext
59+
);
60+
4061
gc_placeholder constant varchar2(3) := '\\%';
4162

4263
gc_integer_exception constant varchar2(1) := 'I';
@@ -742,7 +763,27 @@ create or replace package body ut_suite_builder is
742763
end loop;
743764
end if;
744765
end;
745-
766+
767+
procedure warning_on_unknown_annotations(
768+
a_suite in out nocopy ut_suite_item,
769+
a_annotations tt_annotations_by_line
770+
) is
771+
l_line_no t_annotation_position := a_annotations.first;
772+
begin
773+
while l_line_no is not null loop
774+
if a_annotations(l_line_no).name not member of (gc_supported_annotations) then
775+
add_annotation_ignored_warning(
776+
a_suite,
777+
a_annotations(l_line_no).name,
778+
'Unsupported annotation %%%.',
779+
l_line_no,
780+
a_annotations(l_line_no).procedure_name
781+
);
782+
end if;
783+
l_line_no := a_annotations.next(l_line_no);
784+
end loop;
785+
end;
786+
746787
function create_suite(
747788
a_annotations t_annotations_info
748789
) return ut_logical_suite is
@@ -756,6 +797,7 @@ create or replace package body ut_suite_builder is
756797
l_suite := ut_suite(l_annotations.owner, l_annotations.name);
757798
l_annotation_pos := l_annotations.by_name( gc_suite).first;
758799
l_suite.description := l_annotations.by_name( gc_suite)( l_annotation_pos);
800+
warning_on_unknown_annotations(l_suite, l_annotations.by_line);
759801

760802
warning_on_duplicate_annot( l_suite, l_annotations.by_name, gc_suite );
761803

source/core/ut_utils.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ create or replace package ut_utils authid definer is
2121
*
2222
*/
2323

24-
gc_version constant varchar2(50) := 'v3.1.2.2059-develop';
24+
gc_version constant varchar2(50) := 'v3.1.2.2101-develop';
2525

2626
/* Constants: Event names */
2727
subtype t_event_name is varchar2(30);

test/core/test_suite_builder.pkb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,5 +1020,37 @@ create or replace package body test_suite_builder is
10201020
);
10211021
end;
10221022

1023-
end;
1023+
procedure test_bad_procedure_annotation is
1024+
l_actual clob;
1025+
l_annotations ut3.ut_annotations;
1026+
begin
1027+
--Arrange
1028+
l_annotations := ut3.ut_annotations(
1029+
ut3.ut_annotation(1, 'suite','Cool', null),
1030+
ut3.ut_annotation(2, 'bad_procedure_annotation',null, 'some_procedure'),
1031+
ut3.ut_annotation(6, 'test','A test', 'do_stuff')
1032+
);
1033+
--Act
1034+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
1035+
--Assert
1036+
ut.expect(l_actual).to_be_like('%<WARNINGS><VARCHAR2>Unsupported annotation &quot;--\%bad_procedure_annotation&quot;. Annotation ignored.% line 2</VARCHAR2></WARNINGS>%', '\');
1037+
end;
1038+
1039+
procedure test_bad_package_annotation is
1040+
l_actual clob;
1041+
l_annotations ut3.ut_annotations;
1042+
begin
1043+
--Arrange
1044+
l_annotations := ut3.ut_annotations(
1045+
ut3.ut_annotation(1, 'suite','Cool', null),
1046+
ut3.ut_annotation(17, 'bad_package_annotation',null, null),
1047+
ut3.ut_annotation(24, 'test','A test', 'do_stuff')
1048+
);
1049+
--Act
1050+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
1051+
--Assert
1052+
ut.expect(l_actual).to_be_like('%<WARNINGS><VARCHAR2>Unsupported annotation &quot;--\%bad_package_annotation&quot;. Annotation ignored.% line 17</VARCHAR2></WARNINGS>%', '\');
1053+
end;
1054+
1055+
end test_suite_builder;
10241056
/

test/core/test_suite_builder.pks

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,16 @@ create or replace package test_suite_builder is
163163

164164
--%endcontext
165165

166-
end;
166+
--%context(unknown_annotation)
167+
--%displayname(--%bad_annotation)
168+
169+
--%test(Gives warning when unknown procedure level annotation passed)
170+
procedure test_bad_procedure_annotation;
171+
172+
--%test(Gives warning when unknown package level annotation passed)
173+
procedure test_bad_package_annotation;
174+
175+
--%endcontext
176+
177+
end test_suite_builder;
167178
/

0 commit comments

Comments
 (0)