Skip to content

Commit eab7ad9

Browse files
authored
Merge pull request #380 from Pazus/issue-378
Fixed stack parsing when test failed with `ut.fail`
2 parents 380ff54 + 6fd6eff commit eab7ad9

File tree

4 files changed

+90
-5
lines changed

4 files changed

+90
-5
lines changed

source/core/ut_expectation_processor.pkb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ create or replace package body ut_expectation_processor as
129129
l_object_name varchar2(1000);
130130
-- in 12.2 format_call_stack reportes not only package name, but also the procedure name
131131
-- when 11g and 12c reports only package name
132-
c_expectation_search_pattern constant varchar2(500) := '(.*\.UT_EXPECTATION_RESULT\s+)(.*\.UT_EXPECTATION[A-Z0-9#_$]*(\.[A-Za-z0-9$#_]+)?.*\s+)+(.*)\s';
132+
c_expectation_search_pattern constant varchar2(500) :=
133+
'(.*\.(UT_EXPECTATION[A-Z0-9#_$]*|UT|UTASSERT2?)(\.[A-Z0-9#_$]+)?\s+)+(.*)';
133134
begin
134135
l_caller_stack_line := regexp_substr( c_call_stack, c_expectation_search_pattern, 1, 1, 'm', 4);
135-
l_line_no := to_number( regexp_substr(l_caller_stack_line,'^\dx[0-9a-f]+\s+(\d+)',subexpression => 1) );
136-
l_caller_type_and_name := substr( l_caller_stack_line, 23 );
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));
137138
if l_caller_stack_line like '%.%' then
138-
l_owner := regexp_substr(l_caller_stack_line,'\s([A-Za-z0-9$#_]+)\.([A-Za-z0-9$#_]|\.)+$',subexpression => 1);
139-
l_object_name := regexp_substr(l_caller_stack_line,'\s([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]|\.)+)$',subexpression => 2);
139+
l_owner := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.([A-Za-z0-9$#_]|\.)+',subexpression => 1);
140+
l_object_name := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]|\.)+)',subexpression => 2);
140141
end if;
141142
return
142143
case when l_owner is not null and l_object_name is not null and l_line_no is not null then

tests/RunAll.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ exec ut_coverage.coverage_start_develop();
102102
@@lib/RunTest.sql ut_expectations/ut.expect.to_match.FailsForUnsupportedDatatype.sql
103103
@@lib/RunTest.sql ut_expectations/ut_data_value_object.compare.Gives0WhenComparingIdenticalObjects.sql
104104
@@lib/RunTest.sql ut_expectations/ut_expectation_processor.nulls_are_equal.raisesExceptionWhenTryingToSetNullValue.sql
105+
@@lib/RunTest.sql ut_expectations/ut_expectation_processor.stackOnFailedTest.sql
106+
@@lib/RunTest.sql ut_expectations/ut_expectation_processor.stackOnUtFail.sql
105107

106108
@@ut_matchers/be_between.sql
107109
@@ut_matchers/be_empty.sql
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
set termout off
2+
create or replace package tst_stack_on_failed_test as
3+
--%suite
4+
5+
--%test
6+
procedure test;
7+
end;
8+
/
9+
10+
create or replace package body tst_stack_on_failed_test as
11+
procedure test is begin ut.expect(1).to_equal(2); end;
12+
end;
13+
/
14+
15+
set termout on
16+
17+
declare
18+
l_test_report ut_varchar2_list;
19+
l_output_data ut_varchar2_list;
20+
l_output varchar2(32767);
21+
l_expected varchar2(32767);
22+
begin
23+
l_expected := q'[%Failures:%at "UT3.TST_STACK_ON_FAIL%", line 2%]';
24+
25+
--act
26+
select *
27+
bulk collect into l_output_data
28+
from table(ut.run('tst_stack_on_failed_test',ut_documentation_reporter()));
29+
30+
l_output := ut_utils.table_to_clob(l_output_data);
31+
32+
--assert
33+
if l_output like l_expected then
34+
:test_result := ut_utils.tr_success;
35+
else
36+
dbms_output.put_line('Actual:"'||l_output||'"');
37+
end if;
38+
end;
39+
/
40+
41+
drop package tst_stack_on_failed_test;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
set termout off
2+
create or replace package tst_stack_on_fail as
3+
--%suite
4+
5+
--%test
6+
procedure test;
7+
end;
8+
/
9+
10+
create or replace package body tst_stack_on_fail as
11+
procedure test is begin ut.fail('test failure'); end;
12+
end;
13+
/
14+
15+
set termout on
16+
17+
declare
18+
l_test_report ut_varchar2_list;
19+
l_output_data ut_varchar2_list;
20+
l_output varchar2(32767);
21+
l_expected varchar2(32767);
22+
begin
23+
l_expected := q'[%Failures:%at "UT3.TST_STACK_ON_FAIL%", line 2%]';
24+
25+
--act
26+
select *
27+
bulk collect into l_output_data
28+
from table(ut.run('tst_stack_on_fail',ut_documentation_reporter()));
29+
30+
l_output := ut_utils.table_to_clob(l_output_data);
31+
32+
--assert
33+
if l_output like l_expected then
34+
:test_result := ut_utils.tr_success;
35+
else
36+
dbms_output.put_line('Actual:"'||l_output||'"');
37+
end if;
38+
end;
39+
/
40+
41+
drop package tst_stack_on_fail;

0 commit comments

Comments
 (0)