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

Skip to content

Commit 421d3a2

Browse files
committed
The who_called_expectation is now more relaxed on the stacktrace format.
Resolves #401 Resolves issues with stacktrace not getting parsed properly on some machines.
1 parent 93dff9b commit 421d3a2

6 files changed

Lines changed: 77 additions & 15 deletions

File tree

source/core/types/ut_expectation_result.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ create or replace type body ut_expectation_result is
2323
self.description := a_description;
2424
self.message := a_message;
2525
if self.status = ut_utils.tr_failure then
26-
self.caller_info := ut_expectation_processor.who_called_expectation();
26+
self.caller_info := ut_expectation_processor.who_called_expectation(dbms_utility.format_call_stack());
2727
end if;
2828
return;
2929
end;

source/core/ut_expectation_processor.pkb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,28 @@ create or replace package body ut_expectation_processor as
120120

121121
end;
122122

123-
function who_called_expectation return varchar2 is
124-
c_call_stack constant varchar2(32767) := dbms_utility.format_call_stack();
123+
function who_called_expectation(a_call_stack varchar2) return varchar2 is
125124
l_caller_stack_line varchar2(4000);
126-
l_caller_type_and_name varchar2(4000);
127125
l_line_no integer;
128126
l_owner varchar2(1000);
129-
l_object_name varchar2(1000);
127+
l_object_name varchar2(1000);
128+
l_result varchar2(4000);
130129
-- in 12.2 format_call_stack reportes not only package name, but also the procedure name
131130
-- when 11g and 12c reports only package name
132-
c_expectation_search_pattern constant varchar2(500) :=
131+
c_expectation_search_pattern constant varchar2(500) :=
133132
'(.*\.(UT_EXPECTATION[A-Z0-9#_$]*|UT|UTASSERT2?)(\.[A-Z0-9#_$]+)?\s+)+(.*)';
134133
begin
135-
l_caller_stack_line := regexp_substr( c_call_stack, c_expectation_search_pattern, 1, 1, 'm', 4);
136-
l_line_no := to_number( regexp_substr(l_caller_stack_line,'0x[0-9a-f]+\s+(\d+)',subexpression => 1) );
137-
l_caller_type_and_name := trim(regexp_substr(l_caller_stack_line,'0x[0-9a-f]+\s+\d+\s+(.+)',subexpression => 1));
134+
l_caller_stack_line := regexp_substr( a_call_stack, c_expectation_search_pattern, 1, 1, 'm', 4);
138135
if l_caller_stack_line like '%.%' then
136+
l_line_no := to_number( regexp_substr(l_caller_stack_line,'(0x)?[0-9a-f]+\s+(\d+)',subexpression => 2) );
139137
l_owner := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.([A-Za-z0-9$#_]|\.)+',subexpression => 1);
140138
l_object_name := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]|\.)+)',subexpression => 2);
139+
if l_owner is not null and l_object_name is not null and l_line_no is not null then
140+
l_result := 'at "' || l_owner || '.' || l_object_name || '", line '|| l_line_no || ' '
141+
|| ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no);
142+
end if;
141143
end if;
142-
return
143-
case when l_owner is not null and l_object_name is not null and l_line_no is not null then
144-
'at "' || l_owner || '.' || l_object_name || '", line '|| l_line_no || ' ' ||
145-
ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no)
146-
end;
144+
return l_result;
147145
end;
148146
end;
149147
/

source/core/ut_expectation_processor.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ create or replace package ut_expectation_processor authid current_user as
4444
-- if found, it returns a text:
4545
-- at: owner.name:line "source code line text"
4646
-- The text is to be consumed by expectation result
47-
function who_called_expectation return varchar2;
47+
function who_called_expectation(a_call_stack varchar2) return varchar2;
4848

4949
end;
5050
/

tests/RunAll.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ exec ut_coverage.coverage_start_develop();
4848
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithKeyValue.sql
4949
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithMultilineComment.sql
5050
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.spaceBeforeAnnotationParams.sql
51+
@@lib/RunTest.sql ut_expectation_processor/who_called_expectation.parseStackTrace.sql
52+
@@lib/RunTest.sql ut_expectation_processor/who_called_expectation.parseStackTraceWith0x.sql
5153
@@ut_expectations/ut.expect.not_to_be_null.sql
5254
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql
5355
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare
2+
l_stack_trace varchar2(4000);
3+
l_source_line varchar2(4000);
4+
begin
5+
l_stack_trace := q'[----- PL/SQL Call Stack -----
6+
object line object
7+
handle number name
8+
34f88e4420 124 package body SCH_TEST.UT_EXPECTATION_PROCESSOR
9+
353dfeb2f8 26 SCH_TEST.UT_EXPECTATION_RESULT
10+
cba249ce0 112 SCH_TEST.UT_EXPECTATION
11+
3539881cf0 21 SCH_TEST.UT_EXPECTATION_NUMBER
12+
351a608008 28 package body SCH_TEST.TPKG_PRIOR_YEAR_GENERATION
13+
351a6862b8 6 anonymous block
14+
351fe31010 1825 package body SYS.DBMS_SQL
15+
20befbe4d8 129 SCH_TEST.UT_EXECUTABLE
16+
20befbe4d8 65 SCH_TEST.UT_EXECUTABLE
17+
34f8ab7cd8 80 SCH_TEST.UT_TEST
18+
34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM
19+
34f8ab9b10 74 SCH_TEST.UT_SUITE
20+
34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM
21+
cba24bfd0 75 SCH_TEST.UT_LOGICAL_SUITE
22+
353dfecf30 59 SCH_TEST.UT_RUN
23+
34f8ab98f0 48 SCH_TEST.UT_SUITE_ITEM
24+
357f5421e8 77 package body SCH_TEST.UT_RUNNER
25+
357f5421e8 111 package body SCH_TEST.UT_RUNNER
26+
20be951ab0 292 package body SCH_TEST.UT
27+
20be951ab0 320 package body SCH_TEST.UT
28+
]';
29+
l_source_line := ut_expectation_processor.WHO_CALLED_EXPECTATION(l_stack_trace);
30+
if l_source_line like 'at "SCH_TEST.TPKG_PRIOR_YEAR_GENERATION", line 28 %' then
31+
:test_result := ut_utils.tr_success;
32+
end if;
33+
end;
34+
/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
declare
2+
l_stack_trace varchar2(4000);
3+
l_source_line varchar2(4000);
4+
begin
5+
l_stack_trace := q'[----- PL/SQL Call Stack -----
6+
object line object
7+
handle number name
8+
0x80e701d8 26 UT3.UT_EXPECTATION_RESULT
9+
0x85e10150 112 UT3.UT_EXPECTATION
10+
0x8b54bad8 21 UT3.UT_EXPECTATION_NUMBER
11+
0x85cfd238 20 package body UT3.UT_EXAMPLETEST
12+
0x85def380 6 anonymous block
13+
0x85e93750 1825 package body SYS.DBMS_SQL
14+
0x80f4f608 129 UT3.UT_EXECUTABLE
15+
0x80f4f608 65 UT3.UT_EXECUTABLE
16+
0x8a116010 76 UT3.UT_TEST
17+
0x8a3348a0 48 UT3.UT_SUITE_ITEM
18+
0x887e9948 67 UT3.UT_LOGICAL_SUITE
19+
0x8a26de20 59 UT3.UT_RUN
20+
0x8a3348a0 48 UT3.UT_SUITE_ITEM
21+
0x838d17c0 28 anonymous block
22+
]';
23+
l_source_line := ut_expectation_processor.WHO_CALLED_EXPECTATION(l_stack_trace);
24+
if l_source_line like 'at "UT3.UT_EXAMPLETEST", line 20 %' then
25+
:test_result := ut_utils.tr_success;
26+
end if;
27+
end;
28+
/

0 commit comments

Comments
 (0)