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

Skip to content

Commit 40ba680

Browse files
committed
Fixed stack parsing when test failed with ut.fail or by broken expectation
1 parent 021eead commit 40ba680

4 files changed

Lines changed: 86 additions & 2 deletions

File tree

source/core/ut_expectation_processor.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ 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) := '(.*\.UT_EXPECTATION_RESULT\s+)(.*\.UT_EXPECTATION[A-Z0-9#_$]*(\.[A-Za-z0-9$#_]+)?.*\s+)+(.*UT\.FAIL\s+)?(.*)\s';
133133
begin
134-
l_caller_stack_line := regexp_substr( c_call_stack, c_expectation_search_pattern, 1, 1, 'm', 4);
134+
l_caller_stack_line := regexp_substr( c_call_stack, c_expectation_search_pattern, 1, 1, 'm', 5);
135135
l_line_no := to_number( regexp_substr(l_caller_stack_line,'^\dx[0-9a-f]+\s+(\d+)',subexpression => 1) );
136136
l_caller_type_and_name := substr( l_caller_stack_line, 23 );
137137
if l_caller_stack_line like '%.%' then

tests/RunAll.sql

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

105107
@@ut_matchers/be_between.sql
106108
@@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)