Skip to content

Commit a4b9234

Browse files
author
Lukasz Mendakiewicz
committed
Merge remote-tracking branch 'origin/dev15' into dev15loc
2 parents 7f912d5 + 7504f40 commit a4b9234

40 files changed

Lines changed: 944 additions & 94 deletions

GoogleTestAdapter/Core.Tests/Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Compile Include="Helpers\ProcessExecutorTests.cs" />
8989
<Compile Include="Helpers\RegexTraitParserTests.cs" />
9090
<Compile Include="Helpers\TestEnvironmentTests.cs" />
91+
<Compile Include="Helpers\ByteUtilsTests.cs" />
9192
<Compile Include="Helpers\UtilsTests.cs" />
9293
<Compile Include="Runners\CommandLineGeneratorTests.cs" />
9394
<Compile Include="Runners\SequentialTestRunnerTests.cs" />

GoogleTestAdapter/Core.Tests/GoogleTestDiscovererTests.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file has been modified by Microsoft on 8/2017.
1+
// This file has been modified by Microsoft on 9/2017.
22

33
using System;
44
using System.Collections.Generic;
@@ -25,27 +25,6 @@ namespace GoogleTestAdapter
2525
public class GoogleTestDiscovererTests : TestsBase
2626
{
2727

28-
[TestMethod]
29-
[TestCategory(Unit)]
30-
public void IsGoogleTestExecutable_MatchingExamples_AreMatched()
31-
{
32-
AssertIsGoogleTestExecutable("MyGoogleTests.exe", true);
33-
AssertIsGoogleTestExecutable("MyGoogleTests.exe", true);
34-
AssertIsGoogleTestExecutable("MyGoogleTest.exe", true);
35-
AssertIsGoogleTestExecutable("mygoogletests.exe", true);
36-
AssertIsGoogleTestExecutable("mygoogletest.exe", true);
37-
}
38-
39-
[TestMethod]
40-
[TestCategory(Unit)]
41-
public void IsGoogleTestExecutable_NotMatchingExamples_AreNotMatched()
42-
{
43-
AssertIsGoogleTestExecutable("MyGoogleTes.exe", false);
44-
AssertIsGoogleTestExecutable("TotallyWrong.exe", false);
45-
AssertIsGoogleTestExecutable("TestStuff.exe", false);
46-
AssertIsGoogleTestExecutable("TestLibrary.exe", false);
47-
}
48-
4928
[TestMethod]
5029
[TestCategory(Unit)]
5130
public void IsGoogleTestExecutable_WithRegexFromOptions_MatchesCorrectly()
@@ -59,7 +38,7 @@ public void IsGoogleTestExecutable_WithRegexFromOptions_MatchesCorrectly()
5938
[TestCategory(Unit)]
6039
public void IsGoogleTestExecutable_WithUnparsableRegexFromOptions_ProducesErrorMessage()
6140
{
62-
bool result = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options).IsGoogleTestExecutable("my.exe", "d[ddd[");
41+
bool result = GoogleTestDiscoverer.IsGoogleTestExecutable("my.exe", "d[ddd[", TestEnvironment.Logger);
6342

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

7857
result.Should().BeTrue();
7958
}
@@ -86,15 +65,15 @@ public void IsGoogleTestExecutable_WithIndicatorFile_IsRecognizedAsTestExecutabl
8665

8766
[TestMethod]
8867
[TestCategory(Unit)]
89-
public void IsGoogleTestExecutable_WithoutIndicatorFile_IsNotRecognizedAsTestExecutable()
68+
public void IsGoogleTestExecutable_WithoutIndicatorFile_IsRecognizedAsTestExecutable()
9069
{
9170
string testExecutable = SetupIndicatorFileTest(false);
9271
try
9372
{
94-
bool result = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options)
95-
.IsGoogleTestExecutable(testExecutable);
73+
bool result = GoogleTestDiscoverer
74+
.IsGoogleTestExecutable(testExecutable, "", TestEnvironment.Logger);
9675

97-
result.Should().BeFalse();
76+
result.Should().BeTrue();
9877
}
9978
finally
10079
{
@@ -103,6 +82,26 @@ public void IsGoogleTestExecutable_WithoutIndicatorFile_IsNotRecognizedAsTestExe
10382
}
10483
}
10584

85+
[TestMethod]
86+
[TestCategory(Unit)]
87+
public void IsGoogleTestExecutable_DependingOnGtestDll_IsRecognizedAsTestExecutable()
88+
{
89+
bool result = GoogleTestDiscoverer
90+
.IsGoogleTestExecutable(TestResources.FakeGtestDllExe, "", TestEnvironment.Logger);
91+
92+
result.Should().BeTrue();
93+
}
94+
95+
[TestMethod]
96+
[TestCategory(Unit)]
97+
public void IsGoogleTestExecutable_DependingOnGtestDllX64_IsRecognizedAsTestExecutable()
98+
{
99+
bool result = GoogleTestDiscoverer
100+
.IsGoogleTestExecutable(TestResources.FakeGtestDllExeX64, "", TestEnvironment.Logger);
101+
102+
result.Should().BeTrue();
103+
}
104+
106105
[TestMethod]
107106
[TestCategory(Integration)]
108107
public void GetTestsFromExecutable_SampleTestsDebug_FindsTestsWithLocation()
@@ -320,7 +319,7 @@ public void GetTestsFromExecutable_LoadTests_AreFoundInReasonableTime()
320319

321320
private void AssertIsGoogleTestExecutable(string executable, bool isGoogleTestExecutable, string regex = "")
322321
{
323-
new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options).IsGoogleTestExecutable(executable, regex)
322+
GoogleTestDiscoverer.IsGoogleTestExecutable(executable, regex, TestEnvironment.Logger)
324323
.Should()
325324
.Be(isGoogleTestExecutable);
326325
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Text;
2+
using FluentAssertions;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using static GoogleTestAdapter.Tests.Common.TestMetadata.TestCategories;
5+
6+
namespace GoogleTestAdapter.Helpers
7+
{
8+
[TestClass]
9+
public class ByteUtilsTests
10+
{
11+
[TestMethod]
12+
[TestCategory(Unit)]
13+
public void IndexOf_FooEmptyPattern_ReturnsFound()
14+
{
15+
var bytes = Encoding.ASCII.GetBytes("foo");
16+
var pattern = Encoding.ASCII.GetBytes("");
17+
bytes.IndexOf(pattern).Should().Be(0);
18+
}
19+
20+
[TestMethod]
21+
[TestCategory(Unit)]
22+
public void IndexOf_EmptyBytesFoo_ReturnsNotFound()
23+
{
24+
var bytes = Encoding.ASCII.GetBytes("");
25+
var pattern = Encoding.ASCII.GetBytes("foo");
26+
bytes.IndexOf(pattern).Should().Be(-1);
27+
}
28+
29+
[TestMethod]
30+
[TestCategory(Unit)]
31+
public void IndexOf_EmptyBytesEmptyPattern_ReturnsFound()
32+
{
33+
var bytes = Encoding.ASCII.GetBytes("");
34+
var pattern = Encoding.ASCII.GetBytes("");
35+
bytes.IndexOf(pattern).Should().Be(0);
36+
}
37+
38+
[TestMethod]
39+
[TestCategory(Unit)]
40+
public void IndexOf_FooBar_ReturnsNotFound()
41+
{
42+
var bytes = Encoding.ASCII.GetBytes("foofoofoo");
43+
var pattern = Encoding.ASCII.GetBytes("bar");
44+
bytes.IndexOf(pattern).Should().Be(-1);
45+
}
46+
47+
[TestMethod]
48+
[TestCategory(Unit)]
49+
public void IndexOf_FooAtBeginning_ReturnsFound()
50+
{
51+
var bytes = Encoding.ASCII.GetBytes("fooxxx");
52+
var pattern = Encoding.ASCII.GetBytes("foo");
53+
bytes.IndexOf(pattern).Should().Be(0);
54+
}
55+
56+
[TestMethod]
57+
[TestCategory(Unit)]
58+
public void IndexOf_FooAtEnd_ReturnsFound()
59+
{
60+
var bytes = Encoding.ASCII.GetBytes("xxxfoo");
61+
var pattern = Encoding.ASCII.GetBytes("foo");
62+
bytes.IndexOf(pattern).Should().Be(3);
63+
}
64+
65+
[TestMethod]
66+
[TestCategory(Unit)]
67+
public void IndexOf_FooInMiddle_ReturnsFound()
68+
{
69+
var bytes = Encoding.ASCII.GetBytes("xxxfooxxx");
70+
var pattern = Encoding.ASCII.GetBytes("foo");
71+
bytes.IndexOf(pattern).Should().Be(3);
72+
}
73+
74+
}
75+
}

GoogleTestAdapter/Core.Tests/Helpers/UtilsTests.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Text;
45
using System.Threading;
56
using FluentAssertions;
67
using GoogleTestAdapter.Tests.Common;
@@ -12,7 +13,6 @@ namespace GoogleTestAdapter.Helpers
1213
[TestClass]
1314
public class UtilsTests
1415
{
15-
1616
[TestMethod]
1717
[TestCategory(Unit)]
1818
public void DeleteDirectory_CanNotBeDeleted_ReturnsFalseAndMessage()
@@ -45,6 +45,48 @@ public void GetTempDirectory__DirectoryDoesExistAndCanBeDeleted()
4545
Utils.DeleteDirectory(dir, out errorMessage).Should().BeTrue();
4646
}
4747

48+
[TestMethod]
49+
[TestCategory(Unit)]
50+
public void BinaryFileContainsStrings_TestX86Release_ShouldContainGoogleTestIndicator()
51+
{
52+
Utils.BinaryFileContainsStrings(TestResources.Tests_ReleaseX86, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
53+
}
54+
55+
[TestMethod]
56+
[TestCategory(Unit)]
57+
public void BinaryFileContainsStrings_TestX64Release_ShouldContainGoogleTestIndicator()
58+
{
59+
Utils.BinaryFileContainsStrings(TestResources.Tests_ReleaseX64, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
60+
}
61+
62+
[TestMethod]
63+
[TestCategory(Unit)]
64+
public void BinaryFileContainsStrings_TestX86Debug_ShouldContainGoogleTestIndicator()
65+
{
66+
Utils.BinaryFileContainsStrings(TestResources.Tests_DebugX86, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
67+
}
68+
69+
[TestMethod]
70+
[TestCategory(Unit)]
71+
public void BinaryFileContainsStrings_TestX64Debug_ShouldContainGoogleTestIndicator()
72+
{
73+
Utils.BinaryFileContainsStrings(TestResources.Tests_DebugX64, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeTrue();
74+
}
75+
76+
[TestMethod]
77+
[TestCategory(Unit)]
78+
public void BinaryFileContainsStrings_TenSecondsWaiter_ShouldNotContainGoogleTestIndicator()
79+
{
80+
Utils.BinaryFileContainsStrings(TestResources.TenSecondsWaiter, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeFalse();
81+
}
82+
83+
[TestMethod]
84+
[TestCategory(Unit)]
85+
public void BinaryFileContainsStrings_EmptyFile_ShouldNotContainGoogleTestIndicator()
86+
{
87+
Utils.BinaryFileContainsStrings(TestResources.TenSecondsWaiter, Encoding.ASCII, GoogleTestConstants.GoogleTestExecutableMarkers).Should().BeFalse();
88+
}
89+
4890
[TestMethod]
4991
[TestCategory(Unit)]
5092
public void TimestampMessage_MessageIsNullOrEmpty_ResultIsTheSame()

GoogleTestAdapter/Core/Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<Compile Include="Helpers\DebugUtils.cs" />
7171
<Compile Include="Helpers\Extensions.cs" />
7272
<Compile Include="Framework\IDebuggerAttacher.cs" />
73+
<Compile Include="Helpers\ByteUtils.cs" />
7374
<Compile Include="Helpers\ProcessExecutor.cs" />
7475
<Compile Include="Helpers\ProcessLauncher.cs" />
7576
<Compile Include="Helpers\TestProcessLauncher.cs" />

GoogleTestAdapter/Core/GoogleTestConstants.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file has been modified by Microsoft on 6/2017.
1+
// This file has been modified by Microsoft on 9/2017.
22

33
using System;
44

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

26-
public const string ListTestsOption = " --gtest_list_tests";
26+
public const string ListTestsOption = "--gtest_list_tests";
2727
public const string FilterOption = " --gtest_filter=";
2828

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

33+
public const string GoogleTestDllMarker = "gtest.dll";
34+
35+
public static readonly string[] GoogleTestExecutableMarkers =
36+
{
37+
"This program contains tests written using Google Test. You can use the",
38+
"For more information, please read the Google Test documentation at",
39+
"Run only the tests whose name matches one of the positive patterns but",
40+
ListTestsOption
41+
};
42+
3343
public static string GetResultXmlFileOption(string resultXmlFile)
3444
{
3545
return "--gtest_output=\"xml:" + resultXmlFile + "\"";

0 commit comments

Comments
 (0)