From 0b4d5b76d375bf04e8a129ab8cc5a802397f33a3 Mon Sep 17 00:00:00 2001 From: Spencer Bloom Date: Tue, 7 Apr 2020 16:41:15 -0700 Subject: [PATCH 1/2] check for gtestd.dll import to fix discovery --- GoogleTestAdapter/Core/GoogleTestConstants.cs | 3 ++- GoogleTestAdapter/Core/GoogleTestDiscoverer.cs | 5 +++-- GoogleTestAdapter/DiaResolver/PeParser.cs | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/GoogleTestAdapter/Core/GoogleTestConstants.cs b/GoogleTestAdapter/Core/GoogleTestConstants.cs index 312a0c276..1f1b3b60d 100644 --- a/GoogleTestAdapter/Core/GoogleTestConstants.cs +++ b/GoogleTestAdapter/Core/GoogleTestConstants.cs @@ -1,4 +1,4 @@ -// This file has been modified by Microsoft on 5/2018. +// This file has been modified by Microsoft on 4/2020. using System; @@ -32,6 +32,7 @@ public static class GoogleTestConstants public const string TypedTestMarker = ". # TypeParam = "; public const string GoogleTestDllMarker = "gtest.dll"; + public const string GoogleTestDllMarkerDebug = "gtestd.dll"; public static readonly string[] GoogleTestExecutableMarkers = { diff --git a/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs b/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs index 398eb5149..20a816f87 100644 --- a/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs +++ b/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs @@ -1,4 +1,4 @@ -// This file has been modified by Microsoft on 9/2017. +// This file has been modified by Microsoft on 4/2020. using GoogleTestAdapter.Common; using GoogleTestAdapter.DiaResolver; @@ -104,7 +104,8 @@ public static bool IsGoogleTestExecutable(string executable, string customRegex, if (string.IsNullOrWhiteSpace(customRegex)) { - if (PeParser.FindImport(executable, GoogleTestConstants.GoogleTestDllMarker, StringComparison.OrdinalIgnoreCase, logger) + if (PeParser.FindImport(executable, new List(){ GoogleTestConstants.GoogleTestDllMarker, GoogleTestConstants.GoogleTestDllMarkerDebug }, + StringComparison.OrdinalIgnoreCase, logger) || Utils.BinaryFileContainsStrings(executable, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers)) { return true; diff --git a/GoogleTestAdapter/DiaResolver/PeParser.cs b/GoogleTestAdapter/DiaResolver/PeParser.cs index ac8256fa4..75988e3d9 100644 --- a/GoogleTestAdapter/DiaResolver/PeParser.cs +++ b/GoogleTestAdapter/DiaResolver/PeParser.cs @@ -1,4 +1,4 @@ -// This file has been modified by Microsoft on 11/2017. +// This file has been modified by Microsoft on 4/2020. using GoogleTestAdapter.Common; using Microsoft.Win32.SafeHandles; @@ -277,12 +277,14 @@ public static List ParseImports(string executable, ILogger logger) return imports; } - public static bool FindImport(string executable, string import, StringComparison comparisonType, ILogger logger) + public static bool FindImport(string executable, List imports, StringComparison comparisonType, ILogger logger) { var found = false; ProcessImports(executable, logger, (currentImport) => { - found = String.Compare(import, currentImport, comparisonType) == 0; + foreach (var import in imports) + found = found || String.Compare(import, currentImport, comparisonType) == 0; + return !found; // Continue only if not found yet. }); return found; From 8dd56db505acf360ceacbcd902c86f112abbfdb0 Mon Sep 17 00:00:00 2001 From: Spencer Bloom Date: Wed, 8 Apr 2020 10:31:53 -0700 Subject: [PATCH 2/2] check for gtest_main.dll and gtest_maind.dll as well --- GoogleTestAdapter/Core/GoogleTestConstants.cs | 2 ++ GoogleTestAdapter/Core/GoogleTestDiscoverer.cs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/GoogleTestAdapter/Core/GoogleTestConstants.cs b/GoogleTestAdapter/Core/GoogleTestConstants.cs index 1f1b3b60d..9b5b42ff1 100644 --- a/GoogleTestAdapter/Core/GoogleTestConstants.cs +++ b/GoogleTestAdapter/Core/GoogleTestConstants.cs @@ -33,6 +33,8 @@ public static class GoogleTestConstants public const string GoogleTestDllMarker = "gtest.dll"; public const string GoogleTestDllMarkerDebug = "gtestd.dll"; + public const string GoogleTestMainDllMarker = "gtest_main.dll"; + public const string GoogleTestMainDllMarkerDebug = "gtest_maind.dll"; public static readonly string[] GoogleTestExecutableMarkers = { diff --git a/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs b/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs index 20a816f87..3f9f24355 100644 --- a/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs +++ b/GoogleTestAdapter/Core/GoogleTestDiscoverer.cs @@ -104,8 +104,10 @@ public static bool IsGoogleTestExecutable(string executable, string customRegex, if (string.IsNullOrWhiteSpace(customRegex)) { - if (PeParser.FindImport(executable, new List(){ GoogleTestConstants.GoogleTestDllMarker, GoogleTestConstants.GoogleTestDllMarkerDebug }, - StringComparison.OrdinalIgnoreCase, logger) + List gtestImports = new List() { GoogleTestConstants.GoogleTestDllMarker, GoogleTestConstants.GoogleTestDllMarkerDebug, + GoogleTestConstants.GoogleTestMainDllMarker, GoogleTestConstants.GoogleTestMainDllMarkerDebug }; + + if (PeParser.FindImport(executable, gtestImports, StringComparison.OrdinalIgnoreCase, logger) || Utils.BinaryFileContainsStrings(executable, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers)) { return true;