diff --git a/GoogleTestAdapter/Core/Helpers/Extensions.cs b/GoogleTestAdapter/Core/Helpers/Extensions.cs index ba95e9161..71f3f4339 100644 --- a/GoogleTestAdapter/Core/Helpers/Extensions.cs +++ b/GoogleTestAdapter/Core/Helpers/Extensions.cs @@ -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 diff --git a/GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs b/GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs index fde1c4dc4..fb15aa08d 100644 --- a/GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs +++ b/GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs @@ -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; @@ -57,7 +59,7 @@ public IList CreateTestCases(Action reportTestCase = null) } IList testCaseDescriptors = new ListTestsParser(_settings.TestNameSeparator).ParseListTestsOutput(standardOutput); - List testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _settings.GetPathExtension(_executable)); + var testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _settings.GetPathExtension(_executable)); IList testCases = new List(); IDictionary> suite2TestCases = new Dictionary>(); @@ -105,7 +107,7 @@ private IList NewCreateTestcases(Action reportTestCase, List TestCaseLocation testCaseLocation = resolver.FindTestCaseLocation( _signatureCreator.GetTestMethodSignatures(args.TestCaseDescriptor).ToList()); - testCase = CreateTestCase(args.TestCaseDescriptor, testCaseLocation.Yield().ToList()); + testCase = CreateTestCase(args.TestCaseDescriptor, testCaseLocation); } else { @@ -196,12 +198,15 @@ private bool CheckProcessExitCode(int processExitCode, ICollection stand return true; } - private List GetTestCaseLocations(IList testCaseDescriptors, string pathExtension) + private Dictionary GetTestCaseLocations(IList testCaseDescriptors, string pathExtension) { - var testMethodSignatures = new List(); - foreach (TestCaseDescriptor descriptor in testCaseDescriptors) + var testMethodSignatures = new HashSet(); + foreach (var descriptor in testCaseDescriptors) { - testMethodSignatures.AddRange(_signatureCreator.GetTestMethodSignatures(descriptor)); + foreach (var signature in _signatureCreator.GetTestMethodSignatures(descriptor)) + { + testMethodSignatures.Add(signature); + } } string filterString = "*" + GoogleTestConstants.TestBodySignature; @@ -217,11 +222,20 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor) return testCase; } - private TestCase CreateTestCase(TestCaseDescriptor descriptor, List testCaseLocations) + private TestCase CreateTestCase(TestCaseDescriptor descriptor, Dictionary 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( @@ -235,6 +249,14 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor, List= 0 ? namespaceEnd + 2 : 0; + return symbol.Substring(nameStart); + } + private IList GetFinalTraits(string displayName, List traits) { var afterTraits = @@ -272,4 +294,4 @@ private IList GetFinalTraits(string displayName, List traits) } -} \ No newline at end of file +} diff --git a/GoogleTestAdapter/Core/TestCases/TestCaseResolver.cs b/GoogleTestAdapter/Core/TestCases/TestCaseResolver.cs index cbd721211..3c4f8ba14 100644 --- a/GoogleTestAdapter/Core/TestCases/TestCaseResolver.cs +++ b/GoogleTestAdapter/Core/TestCases/TestCaseResolver.cs @@ -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; @@ -24,10 +26,9 @@ internal TestCaseResolver(IDiaResolverFactory diaResolverFactory, ILogger logger _logger = logger; } - internal List ResolveAllTestCases(string executable, List testMethodSignatures, string symbolFilterString, string pathExtension) + internal Dictionary ResolveAllTestCases(string executable, HashSet testMethodSignatures, string symbolFilterString, string pathExtension) { - List testCaseLocationsFound = - FindTestCaseLocationsInBinary(executable, testMethodSignatures, symbolFilterString, pathExtension).ToList(); + var testCaseLocationsFound = FindTestCaseLocationsInBinary(executable, testMethodSignatures, symbolFilterString, pathExtension); if (testCaseLocationsFound.Count == 0) { @@ -41,7 +42,10 @@ internal List ResolveAllTestCases(string executable, List ResolveAllTestCases(string executable, List FindTestCaseLocationsInBinary( - string binary, List testMethodSignatures, string symbolFilterString, string pathExtension) + private Dictionary FindTestCaseLocationsInBinary( + string binary, HashSet testMethodSignatures, string symbolFilterString, string pathExtension) { using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, pathExtension, _logger)) { @@ -61,14 +65,14 @@ private IEnumerable 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(); } } } @@ -83,4 +87,4 @@ private TestCaseLocation ToTestCaseLocation(SourceFileLocation location, IEnumer } -} \ No newline at end of file +}