@@ -111,5 +111,45 @@ 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+
129+ function who_called_expectation return varchar2 is
130+ l_call_stack varchar2(32767) := dbms_utility.format_call_stack();
131+ l_caller_stack_line varchar2(4000);
132+ l_caller_type_and_name varchar2(4000);
133+ l_line_no integer;
134+ l_owner varchar2(100);
135+ l_object_name varchar2(100);
136+ l_last_space_pos integer;
137+ l_object_delimiter_pos integer;
138+ c_expectation_search_pattern constant varchar2(50) := '(.*\.UT_EXPECTATION[A-Z0-9#_$]*\s)+(.*)\s';
139+ begin
140+ l_caller_stack_line := regexp_substr( l_call_stack, c_expectation_search_pattern, 1, 1, 'm', 2);
141+ l_line_no := to_number( trim( substr( l_caller_stack_line, 11, 10 ) ) );
142+ l_caller_type_and_name := substr( l_caller_stack_line, 23 );
143+ l_last_space_pos := instr( l_caller_type_and_name, ' ', -1 );
144+ l_object_delimiter_pos := instr( l_caller_type_and_name, '.' );
145+ if l_object_delimiter_pos > 0 then
146+ l_owner := substr( l_caller_type_and_name, l_last_space_pos + 1, l_object_delimiter_pos - l_last_space_pos - 1 );
147+ l_object_name := substr( l_caller_type_and_name, l_object_delimiter_pos + 1 );
148+ end if;
149+ return
150+ 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)
152+ end;
153+ end;
114154end;
115155/
0 commit comments