Skip to content

Commit 457160a

Browse files
committed
Added reporting of line where assertion has failed.
Addded separate example with demo of ut_documentation_reporter
1 parent 274af66 commit 457160a

4 files changed

Lines changed: 42 additions & 37 deletions

File tree

examples/RunAllExamples.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ prompt RunExampleTestAnnotationsHugePackage
2121
prompt RunExpectations
2222
@@RunExpectations.sql
2323
prompt RunWithDocumentationReporter
24-
RunWithDocumentationReporter.sql
24+
@@RunWithDocumentationReporter.sql

source/core/ut_assert_processor.pkb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,6 @@ create or replace package body ut_assert_processor as
111111

112112
end;
113113

114-
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2 is
115-
l_line varchar2(4000);
116-
begin
117-
execute immediate
118-
q'[select text from dba_source
119-
where owner = :a_owner and name = :a_object_name and line = :a_line_no
120-
-- skip the declarations, consider only definitions
121-
and type not in ('PACKAGE', 'TYPE') ]'
122-
into l_line using a_owner, a_object_name, a_line_no;
123-
return '"'||ltrim(rtrim( lower( l_line ), chr(10) ))||'"';
124-
exception
125-
when no_data_found then
126-
return null;
127-
end;
128-
129114
function who_called_expectation return varchar2 is
130115
l_call_stack varchar2(32767) := dbms_utility.format_call_stack();
131116
l_caller_stack_line varchar2(4000);
@@ -148,7 +133,8 @@ create or replace package body ut_assert_processor as
148133
end if;
149134
return
150135
case when l_owner is not null and l_object_name is not null and l_line_no is not null then
151-
'at "'||l_owner||'.'||l_object_name||'", line '||l_line_no||' '||get_source_definition_line(l_owner, l_object_name, l_line_no)
136+
'at "' || l_owner || '.' || l_object_name || '", line '|| l_line_no || ' ' ||
137+
ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no)
152138
end;
153139
end;
154140
end;

source/core/ut_metadata.pkb

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,14 @@ create or replace package body ut_metadata as
66

77
function get_package_spec_source_cursor(a_owner varchar2 := null, a_object varchar2 := null) return sys_refcursor is
88
l_cur sys_refcursor;
9-
l_object_does_not_exist exception;
10-
pragma exception_init (l_object_does_not_exist, -942);
11-
function get_query return varchar2 is
9+
function get_query return varchar2 is
1210
begin
1311
return 'select t.text from ' || g_source_view ||
1412
' t where t.owner = :a_owner and t.name = :a_object_name and t.type = ''PACKAGE'' order by t.line';
1513
end;
1614
begin
17-
if g_source_view is not null then
18-
open l_cur for get_query
19-
using a_owner, a_object;
20-
else
21-
begin
22-
g_source_view := 'dba_source';
23-
open l_cur for get_query
24-
using a_owner, a_object;
25-
exception
26-
when l_object_does_not_exist then
27-
g_source_view := 'all_source';
28-
29-
open l_cur for get_query
30-
using a_owner, a_object;
31-
end;
32-
end if;
33-
15+
open l_cur for get_query
16+
using a_owner, a_object;
3417
return l_cur;
3518
end;
3619

@@ -149,5 +132,33 @@ create or replace package body ut_metadata as
149132

150133
end get_package_spec_source;
151134

135+
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2 is
136+
l_line varchar2(4000);
137+
begin
138+
execute immediate
139+
'select text from ' || g_source_view || q'[
140+
where owner = :a_owner and name = :a_object_name and line = :a_line_no
141+
-- skip the declarations, consider only definitions
142+
and type != 'PACKAGE' ]'
143+
into l_line using a_owner, a_object_name, a_line_no;
144+
return '"'||ltrim(rtrim( lower( l_line ), chr(10) ))||'"';
145+
exception
146+
when no_data_found then
147+
return null;
148+
end;
149+
150+
begin
151+
declare
152+
l_cursor sys_refcursor;
153+
l_object_does_not_exist exception;
154+
pragma exception_init (l_object_does_not_exist, -942);
155+
begin
156+
g_source_view := 'dba_source';
157+
open l_cursor for 'select 1 from '||g_source_view ||' where rownum = 1';
158+
close l_cursor;
159+
exception
160+
when l_object_does_not_exist then
161+
g_source_view := 'all_source';
162+
end;
152163
end;
153164
/

source/core/ut_metadata.pks

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,13 @@ create or replace package ut_metadata authid definer as
5454
*/
5555
function get_package_spec_source(a_owner varchar2, a_object_name varchar2) return clob;
5656

57+
58+
/*
59+
function: get_source_definition_line
60+
61+
return the text of the souce line for a given object, excludes package spec
62+
*/
63+
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2;
64+
5765
end ut_metadata;
5866
/

0 commit comments

Comments
 (0)