Skip to content

Commit f152863

Browse files
author
Elizabeth Morrow
committed
Adding source file mapping for user overrides of fixture methods
1 parent a22011c commit f152863

7 files changed

Lines changed: 59 additions & 38 deletions

File tree

GoogleTestAdapter/Core/GoogleTestConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static class GoogleTestConstants
2828
public const string FilterOption = " --gtest_filter=";
2929

3030
public const string TestBodySignature = "::TestBody";
31+
public const string SetUpFixtureMethod = "SetUpTestSuite";
32+
public const string TearDownFixtureMethod = "TearDownTestSuite";
3133
public const string ParameterizedTestMarker = " # GetParam() = ";
3234
public const string TypedTestMarker = ". # TypeParam = ";
3335

GoogleTestAdapter/Core/Resources.Designer.cs

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoogleTestAdapter/Core/Resources.resx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@
273273
<value>No Google Test indicator file found for executable {0}</value>
274274
<comment>{0} represents an unlocalized name of executable (e.g. cmd.exe) file</comment>
275275
</data>
276-
<data name="FixtureMethodDisplayName" xml:space="preserve">
277-
<value>SetUpOrTearDownTestSuite</value>
278-
</data>
279276
<data name="FoundTestMethod" xml:space="preserve">
280277
<value>Found {0} test method symbols and {1} trait symbols in binary {2}</value>
281278
<comment>{0} represents a number (e.g. 5), {1} represents a number (e.g. 5), {2} represents an unlocalized binary name (e.g notepad.exe)</comment>
@@ -439,7 +436,7 @@ Google Test option: {0}</value>
439436
<value>Show fixture method node</value>
440437
</data>
441438
<data name="OptionShowFixtureMethodNodeDescription" xml:space="preserve">
442-
<value>Show placeholder node in test explorer representing status of fixture methods. </value>
439+
<value>Show placeholder nodes in test explorer representing status of fixture methods. </value>
443440
</data>
444441
<data name="OptionShowReleaseNotes" xml:space="preserve">
445442
<value>Show release notes after update</value>

GoogleTestAdapter/Core/TestCases/MethodSignatureCreator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ internal IEnumerable<string> GetTestMethodSignatures(TestCaseDescriptor descript
1919
case TestCaseDescriptor.TestTypes.Parameterized:
2020
return GetParameterizedTestMethodSignature(descriptor).Yield();
2121
case TestCaseDescriptor.TestTypes.Simple:
22+
return GetTestMethodSignature(descriptor.Suite, descriptor.Name).Yield();
2223
case TestCaseDescriptor.TestTypes.Fixture:
23-
return GetTestMethodSignature(descriptor.Suite, descriptor.Name).Yield();
24+
return GetFixtureMethodSignature(descriptor.Suite, descriptor.Name).Yield();
2425
default:
2526
throw new InvalidOperationException(String.Format(Resources.UnknownLiteral, descriptor.TestType));
2627
}
@@ -70,6 +71,11 @@ private string GetTestMethodSignature(string suite, string testCase, string type
7071
return suite + "_" + testCase + "_Test" + typeParam + GoogleTestConstants.TestBodySignature;
7172
}
7273

74+
private string GetFixtureMethodSignature(string suite, string testCase)
75+
{
76+
return suite + "::" + testCase;
77+
}
78+
7379
}
7480

7581
}

GoogleTestAdapter/Core/TestCases/NewTestCaseResolver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal TestCaseLocation FindTestCaseLocation(List<string> testMethodSignatures
5151
result = DoFindTestCaseLocation(testMethodSignatures);
5252
}
5353
return result;
54-
}
54+
}
5555

5656
private void LoadSymbolsFromImports()
5757
{
@@ -73,6 +73,8 @@ private void AddSymbolsFromBinary(string binary)
7373
try
7474
{
7575
_allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*" + GoogleTestConstants.TestBodySignature));
76+
_allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*::" + GoogleTestConstants.SetUpFixtureMethod));
77+
_allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*::" + GoogleTestConstants.TearDownFixtureMethod));
7678
_allTraitSymbols.AddRange(diaResolver.GetFunctions("*" + TraitAppendix));
7779

7880
_logger.DebugInfo(String.Format(Resources.FoundTestMethod, _allTestMethodSymbols.Count, _allTraitSymbols.Count, binary));

GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,9 @@ private IList<TestCase> NewCreateTestcases(Action<TestCase> reportTestCase, List
129129
suite2TestCases.Add(args.TestCaseDescriptor.Suite, testCasesOfSuite = new HashSet<TestCase>());
130130
if (_settings.ShowFixtureMethodNode)
131131
{
132-
string fullyQualifiedNameWithNamespace;
133-
string fullyQualifiedName = $"{args.TestCaseDescriptor.Suite}.{Resources.FixtureMethodDisplayName}";
134-
if (testCase.FullyQualifiedName.Equals(testCase.FullyQualifiedNameWithNamespace))
135-
{
136-
fullyQualifiedNameWithNamespace = fullyQualifiedName;
137-
}
138-
else
139-
{
140-
string ns = testCase.FullyQualifiedNameWithNamespace.Substring(0, testCase.FullyQualifiedNameWithNamespace.IndexOf('.'));
141-
fullyQualifiedNameWithNamespace = $"{ns}.{fullyQualifiedName}";
142-
}
143-
144-
var test = new TestCase(fullyQualifiedName, fullyQualifiedNameWithNamespace, _executable, Resources.FixtureMethodDisplayName, "", 0);
145-
test.Traits.Add(new Trait(TestCaseDescriptor.TestTypeTraitName, TestCaseDescriptor.TestTypes.Fixture.ToString()));
146-
testCasesOfSuite.Add(test);
132+
AddFixtureMethodTestCases(
133+
new string[] {GoogleTestConstants.SetUpFixtureMethod, GoogleTestConstants.TearDownFixtureMethod },
134+
args.TestCaseDescriptor.Suite, testCase, testCasesOfSuite, resolver);
147135
}
148136
}
149137
testCasesOfSuite.Add(testCase);
@@ -249,6 +237,34 @@ private Dictionary<string, TestCaseLocation> GetTestCaseLocations(IList<TestCase
249237
return resolver.ResolveAllTestCases(_executable, testMethodSignatures, filterString, pathExtension);
250238
}
251239

240+
private void AddFixtureMethodTestCases(string[] methodNames, string suite, TestCase testCase, ISet<TestCase> testCasesOfSuite, NewTestCaseResolver resolver)
241+
{
242+
string nameSpace = "";
243+
if (!testCase.FullyQualifiedName.Equals(testCase.FullyQualifiedNameWithNamespace))
244+
{
245+
nameSpace = testCase.FullyQualifiedNameWithNamespace.Substring(0, testCase.FullyQualifiedNameWithNamespace.IndexOf('.'));
246+
}
247+
248+
foreach(string name in methodNames)
249+
{
250+
string fullyQualifiedName = $"{suite}.{name}";
251+
string fullyQualifiedNameWithNamespace = string.IsNullOrEmpty(nameSpace) ? fullyQualifiedName : $"{nameSpace}.{fullyQualifiedName}";
252+
var location = resolver.FindTestCaseLocation(new List<string> { fullyQualifiedNameWithNamespace.Replace(".", "::") });
253+
TestCase testCaseToAdd;
254+
if(location != null)
255+
{
256+
testCaseToAdd = new TestCase(fullyQualifiedName, fullyQualifiedNameWithNamespace, _executable, name, location.Sourcefile, (int)location.Line);
257+
}
258+
else
259+
{
260+
testCaseToAdd = new TestCase(fullyQualifiedName, fullyQualifiedNameWithNamespace, _executable, name, "", 0);
261+
262+
}
263+
testCaseToAdd.Traits.Add(new Trait(TestCaseDescriptor.TestTypeTraitName, TestCaseDescriptor.TestTypes.Fixture.ToString()));
264+
testCasesOfSuite.Add(testCaseToAdd);
265+
}
266+
}
267+
252268
private TestCase CreateTestCase(TestCaseDescriptor descriptor)
253269
{
254270
var testCase = new TestCase(

GoogleTestAdapter/Core/TestResults/StreamingStandardOutputTestResultParser.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,23 @@ private void ReportTestResult()
107107

108108
private void ReportFixtureMethodFailure(string line)
109109
{
110+
// Google test reports fixture method failures ambiguously with the output:
111+
// [ FAILED ] TestMe: SetUpTestSuite or TearDownTestSuite
112+
// For V1, we fail both SetUp and TearDown nodes if a failure is reported.
110113
string suite = FixtureMethodResultRegex.Match(line).Groups[1].Value;
111-
string qualifiedTestName = $"{suite}.{Resources.FixtureMethodDisplayName}";
112-
TestCase testCase = StandardOutputTestResultParser.FindTestcase(qualifiedTestName, _testCasesRun);
113-
if(testCase != null)
114+
string[] supportedFixtureMethods = { GoogleTestConstants.SetUpFixtureMethod, GoogleTestConstants.TearDownFixtureMethod };
115+
foreach (string fixtureMethodName in supportedFixtureMethods)
114116
{
115-
TestResult result = StandardOutputTestResultParser.CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0),"","");
116-
if (result != null)
117+
string qualifiedTestName = $"{suite}.{fixtureMethodName}";
118+
TestCase testCase = StandardOutputTestResultParser.FindTestcase(qualifiedTestName, _testCasesRun);
119+
if(testCase != null)
117120
{
118-
_reporter.ReportTestResults(result.Yield());
119-
TestResults.Add(result);
121+
TestResult result = StandardOutputTestResultParser.CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0),"","");
122+
if (result != null)
123+
{
124+
_reporter.ReportTestResults(result.Yield());
125+
TestResults.Add(result);
126+
}
120127
}
121128
}
122129
}

0 commit comments

Comments
 (0)