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
4 changes: 3 additions & 1 deletion GoogleTestAdapter/Core/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
// This file has been modified by Microsoft on 7/2017.

using System.Collections.Generic;
using GoogleTestAdapter.Model;

namespace GoogleTestAdapter.Helpers
Expand Down
44 changes: 33 additions & 11 deletions GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// This file has been modified by Microsoft on 7/2017.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -57,7 +59,7 @@ public IList<TestCase> CreateTestCases(Action<TestCase> reportTestCase = null)
}

IList<TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_settings.TestNameSeparator).ParseListTestsOutput(standardOutput);
List<TestCaseLocation> testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _settings.GetPathExtension(_executable));
var testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _settings.GetPathExtension(_executable));

IList<TestCase> testCases = new List<TestCase>();
IDictionary<string, ISet<TestCase>> suite2TestCases = new Dictionary<string, ISet<TestCase>>();
Expand Down Expand Up @@ -105,7 +107,7 @@ private IList<TestCase> NewCreateTestcases(Action<TestCase> reportTestCase, List
TestCaseLocation testCaseLocation =
resolver.FindTestCaseLocation(
_signatureCreator.GetTestMethodSignatures(args.TestCaseDescriptor).ToList());
testCase = CreateTestCase(args.TestCaseDescriptor, testCaseLocation.Yield().ToList());
testCase = CreateTestCase(args.TestCaseDescriptor, testCaseLocation);
}
else
{
Expand Down Expand Up @@ -196,12 +198,15 @@ private bool CheckProcessExitCode(int processExitCode, ICollection<string> stand
return true;
}

private List<TestCaseLocation> GetTestCaseLocations(IList<TestCaseDescriptor> testCaseDescriptors, string pathExtension)
private Dictionary<string, TestCaseLocation> GetTestCaseLocations(IList<TestCaseDescriptor> testCaseDescriptors, string pathExtension)
{
var testMethodSignatures = new List<string>();
foreach (TestCaseDescriptor descriptor in testCaseDescriptors)
var testMethodSignatures = new HashSet<string>();
foreach (var descriptor in testCaseDescriptors)
{
testMethodSignatures.AddRange(_signatureCreator.GetTestMethodSignatures(descriptor));
foreach (var signature in _signatureCreator.GetTestMethodSignatures(descriptor))
{
testMethodSignatures.Add(signature);
}
}

string filterString = "*" + GoogleTestConstants.TestBodySignature;
Expand All @@ -217,11 +222,20 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor)
return testCase;
}

private TestCase CreateTestCase(TestCaseDescriptor descriptor, List<TestCaseLocation> testCaseLocations)
private TestCase CreateTestCase(TestCaseDescriptor descriptor, Dictionary<string, TestCaseLocation> testCaseLocations)
{
TestCaseLocation location = testCaseLocations.FirstOrDefault(
l => l != null && _signatureCreator.GetTestMethodSignatures(descriptor).Any(s => Regex.IsMatch(l.Symbol, s)));
var signature = _signatureCreator.GetTestMethodSignatures(descriptor)
.Select(StripTestSymbolNamespace)
.FirstOrDefault(s => testCaseLocations.ContainsKey(s));
TestCaseLocation location = null;
if (signature != null)
testCaseLocations.TryGetValue(signature, out location);

return CreateTestCase(descriptor, location);
}

private TestCase CreateTestCase(TestCaseDescriptor descriptor, TestCaseLocation location)
{
if (location != null)
{
var testCase = new TestCase(
Expand All @@ -235,6 +249,14 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor, List<TestCaseLoca
descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
}

internal static string StripTestSymbolNamespace(string symbol)
{
var suffixLength = GoogleTestConstants.TestBodySignature.Length;
var namespaceEnd = symbol.LastIndexOf("::", symbol.Length - suffixLength - 1);
var nameStart = namespaceEnd >= 0 ? namespaceEnd + 2 : 0;
return symbol.Substring(nameStart);
}

private IList<Trait> GetFinalTraits(string displayName, List<Trait> traits)
{
var afterTraits =
Expand Down Expand Up @@ -272,4 +294,4 @@ private IList<Trait> GetFinalTraits(string displayName, List<Trait> traits)

}

}
}
26 changes: 15 additions & 11 deletions GoogleTestAdapter/Core/TestCases/TestCaseResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// This file has been modified by Microsoft on 7/2017.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -24,10 +26,9 @@ internal TestCaseResolver(IDiaResolverFactory diaResolverFactory, ILogger logger
_logger = logger;
}

internal List<TestCaseLocation> ResolveAllTestCases(string executable, List<string> testMethodSignatures, string symbolFilterString, string pathExtension)
internal Dictionary<string, TestCaseLocation> ResolveAllTestCases(string executable, HashSet<string> testMethodSignatures, string symbolFilterString, string pathExtension)
{
List<TestCaseLocation> testCaseLocationsFound =
FindTestCaseLocationsInBinary(executable, testMethodSignatures, symbolFilterString, pathExtension).ToList();
var testCaseLocationsFound = FindTestCaseLocationsInBinary(executable, testMethodSignatures, symbolFilterString, pathExtension);

if (testCaseLocationsFound.Count == 0)
{
Expand All @@ -41,16 +42,19 @@ internal List<TestCaseLocation> ResolveAllTestCases(string executable, List<stri
string importedBinary = Path.Combine(moduleDirectory, import);
if (File.Exists(importedBinary))
{
testCaseLocationsFound.AddRange(FindTestCaseLocationsInBinary(importedBinary, testMethodSignatures, symbolFilterString, pathExtension));
foreach (var testCaseLocation in FindTestCaseLocationsInBinary(importedBinary, testMethodSignatures, symbolFilterString, pathExtension))
{
testCaseLocationsFound.Add(testCaseLocation.Key, testCaseLocation.Value);
}
}
}
}
return testCaseLocationsFound;
}


private IEnumerable<TestCaseLocation> FindTestCaseLocationsInBinary(
string binary, List<string> testMethodSignatures, string symbolFilterString, string pathExtension)
private Dictionary<string, TestCaseLocation> FindTestCaseLocationsInBinary(
string binary, HashSet<string> testMethodSignatures, string symbolFilterString, string pathExtension)
{
using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, pathExtension, _logger))
{
Expand All @@ -61,14 +65,14 @@ private IEnumerable<TestCaseLocation> FindTestCaseLocationsInBinary(
_logger.DebugInfo($"Found {allTestMethodSymbols.Count} test method symbols and {allTraitSymbols.Count} trait symbols in binary {binary}");

return allTestMethodSymbols
.Where(nsfl => testMethodSignatures.Any(tms => Regex.IsMatch(nsfl.Symbol, tms))) // Contains() instead of == because nsfl might contain namespace
.Where(nsfl => testMethodSignatures.Contains(TestCaseFactory.StripTestSymbolNamespace(nsfl.Symbol)))
.Select(nsfl => ToTestCaseLocation(nsfl, allTraitSymbols))
.ToList(); // we need to force immediate query execution, otherwise our session object will already be released
.ToDictionary(nsfl => TestCaseFactory.StripTestSymbolNamespace(nsfl.Symbol));
}
catch (Exception e)
{
_logger.DebugError($"Exception while resolving test locations and traits in {binary}\n{e}");
return new TestCaseLocation[0];
return new Dictionary<string, TestCaseLocation>();
}
}
}
Expand All @@ -83,4 +87,4 @@ private TestCaseLocation ToTestCaseLocation(SourceFileLocation location, IEnumer

}

}
}