Skip to content

Commit

Permalink
Merge pull request #59 from Microsoft/dev/lukaszme/test_discovery
Browse files Browse the repository at this point in the history
Improve Google Test executables discovery
  • Loading branch information
Łukasz Mendakiewicz committed Sep 29, 2017
2 parents 9f3efe7 + 0318762 commit 7504f40
Show file tree
Hide file tree
Showing 26 changed files with 768 additions and 92 deletions.
1 change: 1 addition & 0 deletions GoogleTestAdapter/Core.Tests/Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Helpers\ProcessExecutorTests.cs" />
<Compile Include="Helpers\RegexTraitParserTests.cs" />
<Compile Include="Helpers\TestEnvironmentTests.cs" />
<Compile Include="Helpers\ByteUtilsTests.cs" />
<Compile Include="Helpers\UtilsTests.cs" />
<Compile Include="Runners\CommandLineGeneratorTests.cs" />
<Compile Include="Runners\SequentialTestRunnerTests.cs" />
Expand Down
59 changes: 29 additions & 30 deletions GoogleTestAdapter/Core.Tests/GoogleTestDiscovererTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file has been modified by Microsoft on 8/2017.
// This file has been modified by Microsoft on 9/2017.

using System;
using System.Collections.Generic;
Expand All @@ -25,27 +25,6 @@ namespace GoogleTestAdapter
public class GoogleTestDiscovererTests : TestsBase
{

[TestMethod]
[TestCategory(Unit)]
public void IsGoogleTestExecutable_MatchingExamples_AreMatched()
{
AssertIsGoogleTestExecutable("MyGoogleTests.exe", true);
AssertIsGoogleTestExecutable("MyGoogleTests.exe", true);
AssertIsGoogleTestExecutable("MyGoogleTest.exe", true);
AssertIsGoogleTestExecutable("mygoogletests.exe", true);
AssertIsGoogleTestExecutable("mygoogletest.exe", true);
}

[TestMethod]
[TestCategory(Unit)]
public void IsGoogleTestExecutable_NotMatchingExamples_AreNotMatched()
{
AssertIsGoogleTestExecutable("MyGoogleTes.exe", false);
AssertIsGoogleTestExecutable("TotallyWrong.exe", false);
AssertIsGoogleTestExecutable("TestStuff.exe", false);
AssertIsGoogleTestExecutable("TestLibrary.exe", false);
}

[TestMethod]
[TestCategory(Unit)]
public void IsGoogleTestExecutable_WithRegexFromOptions_MatchesCorrectly()
Expand All @@ -59,7 +38,7 @@ public void IsGoogleTestExecutable_WithRegexFromOptions_MatchesCorrectly()
[TestCategory(Unit)]
public void IsGoogleTestExecutable_WithUnparsableRegexFromOptions_ProducesErrorMessage()
{
bool result = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options).IsGoogleTestExecutable("my.exe", "d[ddd[");
bool result = GoogleTestDiscoverer.IsGoogleTestExecutable("my.exe", "d[ddd[", TestEnvironment.Logger);

result.Should().BeFalse();
MockLogger.Verify(l => l.LogError(It.Is<string>(s => s.Contains("'d[ddd['"))), Times.Exactly(1));
Expand All @@ -72,8 +51,8 @@ public void IsGoogleTestExecutable_WithIndicatorFile_IsRecognizedAsTestExecutabl
string testExecutable = SetupIndicatorFileTest(true);
try
{
bool result = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options)
.IsGoogleTestExecutable(testExecutable);
bool result = GoogleTestDiscoverer
.IsGoogleTestExecutable(testExecutable, "", TestEnvironment.Logger);

result.Should().BeTrue();
}
Expand All @@ -86,15 +65,15 @@ public void IsGoogleTestExecutable_WithIndicatorFile_IsRecognizedAsTestExecutabl

[TestMethod]
[TestCategory(Unit)]
public void IsGoogleTestExecutable_WithoutIndicatorFile_IsNotRecognizedAsTestExecutable()
public void IsGoogleTestExecutable_WithoutIndicatorFile_IsRecognizedAsTestExecutable()
{
string testExecutable = SetupIndicatorFileTest(false);
try
{
bool result = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options)
.IsGoogleTestExecutable(testExecutable);
bool result = GoogleTestDiscoverer
.IsGoogleTestExecutable(testExecutable, "", TestEnvironment.Logger);

result.Should().BeFalse();
result.Should().BeTrue();
}
finally
{
Expand All @@ -103,6 +82,26 @@ public void IsGoogleTestExecutable_WithoutIndicatorFile_IsNotRecognizedAsTestExe
}
}

[TestMethod]
[TestCategory(Unit)]
public void IsGoogleTestExecutable_DependingOnGtestDll_IsRecognizedAsTestExecutable()
{
bool result = GoogleTestDiscoverer
.IsGoogleTestExecutable(TestResources.FakeGtestDllExe, "", TestEnvironment.Logger);

result.Should().BeTrue();
}

[TestMethod]
[TestCategory(Unit)]
public void IsGoogleTestExecutable_DependingOnGtestDllX64_IsRecognizedAsTestExecutable()
{
bool result = GoogleTestDiscoverer
.IsGoogleTestExecutable(TestResources.FakeGtestDllExeX64, "", TestEnvironment.Logger);

result.Should().BeTrue();
}

[TestMethod]
[TestCategory(Integration)]
public void GetTestsFromExecutable_SampleTestsDebug_FindsTestsWithLocation()
Expand Down Expand Up @@ -320,7 +319,7 @@ public void GetTestsFromExecutable_LoadTests_AreFoundInReasonableTime()

private void AssertIsGoogleTestExecutable(string executable, bool isGoogleTestExecutable, string regex = "")
{
new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options).IsGoogleTestExecutable(executable, regex)
GoogleTestDiscoverer.IsGoogleTestExecutable(executable, regex, TestEnvironment.Logger)
.Should()
.Be(isGoogleTestExecutable);
}
Expand Down
75 changes: 75 additions & 0 deletions GoogleTestAdapter/Core.Tests/Helpers/ByteUtilsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Text;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static GoogleTestAdapter.Tests.Common.TestMetadata.TestCategories;

namespace GoogleTestAdapter.Helpers
{
[TestClass]
public class ByteUtilsTests
{
[TestMethod]
[TestCategory(Unit)]
public void IndexOf_FooEmptyPattern_ReturnsFound()
{
var bytes = Encoding.ASCII.GetBytes("foo");
var pattern = Encoding.ASCII.GetBytes("");
bytes.IndexOf(pattern).Should().Be(0);
}

[TestMethod]
[TestCategory(Unit)]
public void IndexOf_EmptyBytesFoo_ReturnsNotFound()
{
var bytes = Encoding.ASCII.GetBytes("");
var pattern = Encoding.ASCII.GetBytes("foo");
bytes.IndexOf(pattern).Should().Be(-1);
}

[TestMethod]
[TestCategory(Unit)]
public void IndexOf_EmptyBytesEmptyPattern_ReturnsFound()
{
var bytes = Encoding.ASCII.GetBytes("");
var pattern = Encoding.ASCII.GetBytes("");
bytes.IndexOf(pattern).Should().Be(0);
}

[TestMethod]
[TestCategory(Unit)]
public void IndexOf_FooBar_ReturnsNotFound()
{
var bytes = Encoding.ASCII.GetBytes("foofoofoo");
var pattern = Encoding.ASCII.GetBytes("bar");
bytes.IndexOf(pattern).Should().Be(-1);
}

[TestMethod]
[TestCategory(Unit)]
public void IndexOf_FooAtBeginning_ReturnsFound()
{
var bytes = Encoding.ASCII.GetBytes("fooxxx");
var pattern = Encoding.ASCII.GetBytes("foo");
bytes.IndexOf(pattern).Should().Be(0);
}

[TestMethod]
[TestCategory(Unit)]
public void IndexOf_FooAtEnd_ReturnsFound()
{
var bytes = Encoding.ASCII.GetBytes("xxxfoo");
var pattern = Encoding.ASCII.GetBytes("foo");
bytes.IndexOf(pattern).Should().Be(3);
}

[TestMethod]
[TestCategory(Unit)]
public void IndexOf_FooInMiddle_ReturnsFound()
{
var bytes = Encoding.ASCII.GetBytes("xxxfooxxx");
var pattern = Encoding.ASCII.GetBytes("foo");
bytes.IndexOf(pattern).Should().Be(3);
}

}
}
44 changes: 43 additions & 1 deletion GoogleTestAdapter/Core.Tests/Helpers/UtilsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using FluentAssertions;
using GoogleTestAdapter.Tests.Common;
Expand All @@ -12,7 +13,6 @@ namespace GoogleTestAdapter.Helpers
[TestClass]
public class UtilsTests
{

[TestMethod]
[TestCategory(Unit)]
public void DeleteDirectory_CanNotBeDeleted_ReturnsFalseAndMessage()
Expand Down Expand Up @@ -45,6 +45,48 @@ public void GetTempDirectory__DirectoryDoesExistAndCanBeDeleted()
Utils.DeleteDirectory(dir, out errorMessage).Should().BeTrue();
}

[TestMethod]
[TestCategory(Unit)]
public void BinaryFileContainsStrings_TestX86Release_ShouldContainGoogleTestIndicator()
{
Utils.BinaryFileContainsStrings(TestResources.Tests_ReleaseX86, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
}

[TestMethod]
[TestCategory(Unit)]
public void BinaryFileContainsStrings_TestX64Release_ShouldContainGoogleTestIndicator()
{
Utils.BinaryFileContainsStrings(TestResources.Tests_ReleaseX64, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
}

[TestMethod]
[TestCategory(Unit)]
public void BinaryFileContainsStrings_TestX86Debug_ShouldContainGoogleTestIndicator()
{
Utils.BinaryFileContainsStrings(TestResources.Tests_DebugX86, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
}

[TestMethod]
[TestCategory(Unit)]
public void BinaryFileContainsStrings_TestX64Debug_ShouldContainGoogleTestIndicator()
{
Utils.BinaryFileContainsStrings(TestResources.Tests_DebugX64, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
}

[TestMethod]
[TestCategory(Unit)]
public void BinaryFileContainsStrings_TenSecondsWaiter_ShouldNotContainGoogleTestIndicator()
{
Utils.BinaryFileContainsStrings(TestResources.TenSecondsWaiter, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeFalse();
}

[TestMethod]
[TestCategory(Unit)]
public void BinaryFileContainsStrings_EmptyFile_ShouldNotContainGoogleTestIndicator()
{
Utils.BinaryFileContainsStrings(TestResources.TenSecondsWaiter, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeFalse();
}

[TestMethod]
[TestCategory(Unit)]
public void TimestampMessage_MessageIsNullOrEmpty_ResultIsTheSame()
Expand Down
1 change: 1 addition & 0 deletions GoogleTestAdapter/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Helpers\DebugUtils.cs" />
<Compile Include="Helpers\Extensions.cs" />
<Compile Include="Framework\IDebuggerAttacher.cs" />
<Compile Include="Helpers\ByteUtils.cs" />
<Compile Include="Helpers\ProcessExecutor.cs" />
<Compile Include="Helpers\ProcessLauncher.cs" />
<Compile Include="Helpers\TestProcessLauncher.cs" />
Expand Down
14 changes: 12 additions & 2 deletions GoogleTestAdapter/Core/GoogleTestConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file has been modified by Microsoft on 6/2017.
// This file has been modified by Microsoft on 9/2017.

using System;

Expand All @@ -23,13 +23,23 @@ public static class GoogleTestConstants
public const int ShuffleTestsSeedMinValue = 0;
public static readonly int ShuffleTestsSeedMaxValue = int.Parse(ShuffleTestsSeedMaxValueAsString);

public const string ListTestsOption = " --gtest_list_tests";
public const string ListTestsOption = "--gtest_list_tests";
public const string FilterOption = " --gtest_filter=";

public const string TestBodySignature = "::TestBody";
public const string ParameterizedTestMarker = " # GetParam() = ";
public const string TypedTestMarker = ". # TypeParam = ";

public const string GoogleTestDllMarker = "gtest.dll";

public static readonly string[] GoogleTestExecutableMarkers =
{
"This program contains tests written using Google Test. You can use the",
"For more information, please read the Google Test documentation at",
"Run only the tests whose name matches one of the positive patterns but",
ListTestsOption
};

public static string GetResultXmlFileOption(string resultXmlFile)
{
return "--gtest_output=\"xml:" + resultXmlFile + "\"";
Expand Down

0 comments on commit 7504f40

Please sign in to comment.