From 682c59b0bea0bd5ec05958919510b161a8cea2ab Mon Sep 17 00:00:00 2001 From: Johnny Hendriks Date: Thu, 6 Sep 2018 16:02:56 +0200 Subject: [PATCH] Fixes bug: Test durations in Test Explorer are wrong for systems setup with a decimal symbol that is not '.' --- Docs/CHANGELOG.md | 4 ++++ Libraries/Catch2Interface/Reporter/OverallResult.cs | 10 +++++++++- Libraries/Catch2Interface/Reporter/OverallResults.cs | 10 +++++++++- VSIX/VSTestAdapterCatch2/source.extension.vsixmanifest | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Docs/CHANGELOG.md b/Docs/CHANGELOG.md index 3a4f0c8..a56f221 100644 --- a/Docs/CHANGELOG.md +++ b/Docs/CHANGELOG.md @@ -8,6 +8,10 @@ Changes are relative to v1.0.0 - Improve Additional info output with respect to section. Is now more like standard Catch2 output. +### Bug fixes + +- Bug: Test durations in Test Explorer are wrong for systems setup with a decimal symbol that is not '.'. Fixed. + ## Changes for v1.3.0 ### Extended Features diff --git a/Libraries/Catch2Interface/Reporter/OverallResult.cs b/Libraries/Catch2Interface/Reporter/OverallResult.cs index acdfa13..0aad3f6 100644 --- a/Libraries/Catch2Interface/Reporter/OverallResult.cs +++ b/Libraries/Catch2Interface/Reporter/OverallResult.cs @@ -12,6 +12,7 @@ ** Basic Info **/ using System; +using System.Globalization; using System.Xml; namespace Catch2Interface.Reporter @@ -24,6 +25,13 @@ This class is intended to handle the xml "OverallResult" node in a Catch2 Xml re */ public class OverallResult { + #region Fields + + private static NumberStyles _style = NumberStyles.Float; + private static CultureInfo _culture = CultureInfo.CreateSpecificCulture("en-US"); + + #endregion // Fields + #region Properties public TimeSpan Duration { get; private set; } @@ -46,7 +54,7 @@ public OverallResult(XmlNode node) } double duration = 0.0; - if (double.TryParse(node.Attributes["durationInSeconds"]?.Value, out duration)) + if (double.TryParse(node.Attributes["durationInSeconds"]?.Value, _style, _culture, out duration)) { Duration = new TimeSpan((Int64)(duration * TimeSpan.TicksPerSecond)); ; } diff --git a/Libraries/Catch2Interface/Reporter/OverallResults.cs b/Libraries/Catch2Interface/Reporter/OverallResults.cs index 8afad18..2f33d47 100644 --- a/Libraries/Catch2Interface/Reporter/OverallResults.cs +++ b/Libraries/Catch2Interface/Reporter/OverallResults.cs @@ -12,6 +12,7 @@ ** Basic Info **/ using System; +using System.Globalization; using System.Xml; namespace Catch2Interface.Reporter @@ -24,6 +25,13 @@ This class is intended to handle the xml "OverallResults" node in a Catch2 Xml r */ public class OverallResults { + #region Fields + + private static NumberStyles _style = NumberStyles.Float; + private static CultureInfo _culture = CultureInfo.CreateSpecificCulture("en-US"); + + #endregion // Fields + #region Properties public int Successes { get; set; } = 0; @@ -63,7 +71,7 @@ public OverallResults(XmlNode node) } double duration = 0.0; - if (double.TryParse(node.Attributes["durationInSeconds"]?.Value, out duration)) + if (double.TryParse(node.Attributes["durationInSeconds"]?.Value, _style, _culture, out duration)) { Duration = new TimeSpan((Int64)(duration * TimeSpan.TicksPerSecond)); ; } diff --git a/VSIX/VSTestAdapterCatch2/source.extension.vsixmanifest b/VSIX/VSTestAdapterCatch2/source.extension.vsixmanifest index 19a27dc..e2f40e5 100644 --- a/VSIX/VSTestAdapterCatch2/source.extension.vsixmanifest +++ b/VSIX/VSTestAdapterCatch2/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + Test Adapter for Catch2 Test Adapter for use with the Catch2 C++ unit test framework. https://github.com/JohnnyHendriks/TestAdapter_Catch2