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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed issue with NLS settings for decimal numbers in XML reporting.
Resolves #572
Resolves utPLSQL/utPLSQL-cli#61
  • Loading branch information
jgebal committed Feb 3, 2018
commit 0a012f9b7129fea1706f22f3a92a6b6c8fe271a5
6 changes: 5 additions & 1 deletion source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ create or replace package body ut_utils is
commit;
end;


function ut_owner return varchar2 is
begin
return sys_context('userenv','current_schema');
Expand All @@ -462,5 +461,10 @@ create or replace package body ut_utils is
return nvl(trunc(power(10,(floor(log(10,a_cardinality))+1))/3),0);
end;

function to_xml_number_format(a_value number) return varchar2 is
begin
return to_char(a_value, gc_number_format, 'NLS_NUMERIC_CHARACTERS=''. ''');
end;

end ut_utils;
/
6 changes: 6 additions & 0 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,11 @@ create or replace package ut_utils authid definer is
*/
function scale_cardinality(a_cardinality natural) return natural;

/**
* Returns number as string. The value is represented as decimal according to XML standard:
* https://www.w3.org/TR/xmlschema-2/#decimal
*/
function to_xml_number_format(a_value number) return varchar2;

end ut_utils;
/
6 changes: 5 additions & 1 deletion source/reporters/ut_xunit_reporter.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ create or replace type body ut_xunit_reporter is

member function get_common_item_attributes(a_item ut_suite_item) return varchar2 is
begin
return ' skipped="' || a_item.results_count.disabled_count || '" error="' || a_item.results_count.errored_count || '"' || ' failure="' || a_item.results_count.failure_count || '" name="' || dbms_xmlgen.convert(nvl(a_item.description, a_item.name)) || '"' || ' time="' || a_item.execution_time() || '" ';
return ' skipped="' || a_item.results_count.disabled_count
|| '" error="' || a_item.results_count.errored_count
|| '" failure="' || a_item.results_count.failure_count
|| '" name="' || dbms_xmlgen.convert(nvl(a_item.description, a_item.name))
|| '" time="' || ut_utils.to_xml_number_format(a_item.execution_time()) || '" ';
end;

end;
Expand Down
23 changes: 22 additions & 1 deletion test/core/reporters/test_xunit_reporter.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,28 @@ create or replace package body test_xunit_reporter as
from table(ut3.ut.run('check_xunit_reporting',ut3.ut_xunit_reporter()));
l_actual := ut3.ut_utils.table_to_clob(l_results);
--Assert
ut.expect(l_actual).to_be_like('%testcase classname="check_xunit_reporting"%');
ut.expect(l_actual).to_be_like('%testcase classname="check_xunit_reporting"%');
end;

procedure check_nls_number_formatting is
l_results ut3.ut_varchar2_list;
l_actual clob;
l_nls_numeric_characters varchar2(30);
begin
--Arrange
select nsp.value into l_nls_numeric_characters
from nls_session_parameters nsp
where parameter = 'NLS_NUMERIC_CHARACTERS';
execute immediate q'[alter session set NLS_NUMERIC_CHARACTERS=', ']';
--Act
select *
bulk collect into l_results
from table(ut3.ut.run('check_xunit_reporting', ut3.ut_xunit_reporter()));
l_actual := ut3.ut_utils.table_to_clob(l_results);
--Assert
ut.expect(l_actual).to_match('time="[0-9]*\.[0-9]{6}"');
--Cleanup
execute immediate 'alter session set NLS_NUMERIC_CHARACTERS='''||l_nls_numeric_characters||'''';
end;

procedure check_classname_suitepath is
Expand Down
3 changes: 3 additions & 0 deletions test/core/reporters/test_xunit_reporter.pks
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ create or replace package test_xunit_reporter as
--%test(Check that classname is returned correct suitepath)
procedure check_classname_suitepath;

--%test(Reports duration according to XML specification for numbers)
procedure check_nls_number_formatting;

--%afterall
procedure remove_test_package;
end;
Expand Down