From 0a012f9b7129fea1706f22f3a92a6b6c8fe271a5 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Sat, 3 Feb 2018 16:28:41 +0000 Subject: [PATCH] Fixed issue with NLS settings for decimal numbers in XML reporting. Resolves #572 Resolves utPLSQL/utPLSQL-cli#61 --- source/core/ut_utils.pkb | 6 +++++- source/core/ut_utils.pks | 6 ++++++ source/reporters/ut_xunit_reporter.tpb | 6 +++++- test/core/reporters/test_xunit_reporter.pkb | 23 ++++++++++++++++++++- test/core/reporters/test_xunit_reporter.pks | 3 +++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/source/core/ut_utils.pkb b/source/core/ut_utils.pkb index 727618aa4..eed9ff0c4 100644 --- a/source/core/ut_utils.pkb +++ b/source/core/ut_utils.pkb @@ -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'); @@ -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; / diff --git a/source/core/ut_utils.pks b/source/core/ut_utils.pks index a690dc222..c93a7c727 100644 --- a/source/core/ut_utils.pks +++ b/source/core/ut_utils.pks @@ -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; / diff --git a/source/reporters/ut_xunit_reporter.tpb b/source/reporters/ut_xunit_reporter.tpb index 68e16f14f..bc3dd0d5b 100644 --- a/source/reporters/ut_xunit_reporter.tpb +++ b/source/reporters/ut_xunit_reporter.tpb @@ -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; diff --git a/test/core/reporters/test_xunit_reporter.pkb b/test/core/reporters/test_xunit_reporter.pkb index fea620b68..fde0591d2 100644 --- a/test/core/reporters/test_xunit_reporter.pkb +++ b/test/core/reporters/test_xunit_reporter.pkb @@ -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 diff --git a/test/core/reporters/test_xunit_reporter.pks b/test/core/reporters/test_xunit_reporter.pks index e5cfa029a..c3ed3e4bb 100644 --- a/test/core/reporters/test_xunit_reporter.pks +++ b/test/core/reporters/test_xunit_reporter.pks @@ -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;