Skip to content

Commit

Permalink
allow thousands separators in test duration (fixes #143)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgefele committed May 10, 2017
1 parent e6f4d84 commit ecc1751
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public class StandardOutputTestResultParserTests : TestsBase
@"[ FAILED ] TestMath.AddFails (3 s)"
};

private string[] ConsoleOutput1WithThousandsSeparatorInDuration { get; } = {
@"[==========] Running 3 tests from 1 test case.",
@"[----------] Global test environment set-up.",
@"[----------] 3 tests from TestMath",
@"[ RUN ] TestMath.AddFails",
@"c:\users\chris\documents\visual studio 2015\projects\consoleapplication1\consoleapplication1tests\source.cpp(6): error: Value of: Add(10, 10)",
@" Actual: 20",
@"Expected: 1000",
@"[ FAILED ] TestMath.AddFails (4,656 ms)",
};

private string[] ConsoleOutput2 { get; } = {
@"[ OK ] TestMath.AddPasses(0 ms)",
@"[ RUN ] TestMath.Crash",
Expand Down Expand Up @@ -94,6 +105,7 @@ public class StandardOutputTestResultParserTests : TestsBase
private List<string> CrashesAfterErrorMsg { get; set; }
private List<string> Complete { get; set; }
private List<string> WrongDurationUnit { get; set; }
private List<string> ThousandsSeparatorInDuration { get; set; }
private List<string> PassingTestProducesConsoleOutput { get; set; }
private List<string> CompleteStandardOutput { get; set; }

Expand All @@ -113,6 +125,8 @@ public override void SetUp()

WrongDurationUnit = new List<string>(ConsoleOutput1WithInvalidDuration);

ThousandsSeparatorInDuration = new List<string>(ConsoleOutput1WithThousandsSeparatorInDuration);

PassingTestProducesConsoleOutput = new List<string>(ConsoleOutputWithOutputOfExe);

CompleteStandardOutput = new List<string>(File.ReadAllLines(TestResources.Tests_ReleaseX64_Output, Encoding.Default));
Expand Down Expand Up @@ -207,6 +221,17 @@ public void GetTestResults_OutputWithInvalidDurationUnit_DefaultDurationIsUsedAn
It.Is<string>(s => s.Contains("'[ FAILED ] TestMath.AddFails (3 s)'"))), Times.Exactly(1));
}

[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_OutputWithThousandsSeparatorInDuration_ParsedCorrectly()
{
List<TestResult> results = ComputeTestResults(ThousandsSeparatorInDuration);

results.Count.Should().Be(1);
results[0].TestCase.FullyQualifiedName.Should().Be("TestMath.AddFails");
results[0].Duration.Should().Be(TimeSpan.FromMilliseconds(4656));
}

[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_OutputWithConsoleOutput_ConsoleOutputIsIgnored()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using GoogleTestAdapter.Common;
Expand Down Expand Up @@ -118,12 +119,12 @@ public static TimeSpan ParseDuration(string line, ILogger logger)
int durationInMs = 1;
try
{
// TODO check format in gtest code, replace with regex
// duration is a 64-bit number (no decimals) in the user's locale
int indexOfOpeningBracket = line.LastIndexOf('(');
int lengthOfDurationPart = line.Length - indexOfOpeningBracket - 2;
string durationPart = line.Substring(indexOfOpeningBracket + 1, lengthOfDurationPart);
durationPart = durationPart.Replace("ms", "").Trim();
durationInMs = int.Parse(durationPart);
durationInMs = int.Parse(durationPart, NumberStyles.Number);
}
catch (Exception)
{
Expand Down

0 comments on commit ecc1751

Please sign in to comment.