Skip to content

Commit

Permalink
added option to replace / character in display names to avoid truncat…
Browse files Browse the repository at this point in the history
…ion by VS (#23)
  • Loading branch information
csoltenborn committed Mar 17, 2016
1 parent bfc4ee1 commit 2dfbdc1
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ virtual public void SetUp()
{
MockOptions.Setup(o => o.TraitsRegexesBefore).Returns(new List<RegexTraitPair>());
MockOptions.Setup(o => o.TraitsRegexesAfter).Returns(new List<RegexTraitPair>());
MockOptions.Setup(o => o.TestNameSeparator).Returns(Options.OptionTestNameSeparatorDefaultValue);
MockOptions.Setup(o => o.NrOfTestRepetitions).Returns(Options.OptionNrOfTestRepetitionsDefaultValue);
MockOptions.Setup(o => o.PrintTestOutput).Returns(Options.OptionPrintTestOutputDefaultValue);
MockOptions.Setup(o => o.CatchExceptions).Returns(Options.OptionCatchExceptionsDefaultValue);
Expand Down
1 change: 1 addition & 0 deletions GoogleTestAdapter/Core.Tests/Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Helpers\UtilsTests.cs" />
<Compile Include="Runners\CommandLineGeneratorTests.cs" />
<Compile Include="Runners\SequentialTestRunnerTests.cs" />
<Compile Include="TestCases\ListTestsParserTests.cs" />
<Compile Include="TestResults\StandardOutputTestResultParserTests.cs" />
<Compile Include="TestResults\ErrorMessageParserTests.cs" />
<Compile Include="TestResults\XmlTestResultParserTests.cs" />
Expand Down
24 changes: 24 additions & 0 deletions GoogleTestAdapter/Core.Tests/OptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,30 @@ public void TestDiscoveryRegex__ReturnsValueOrDefault()
Assert.AreEqual("FooBar", result);
}

[TestMethod]
public void TestNameSeparator__ReturnsValueOrDefault()
{
MockXmlOptions.Setup(o => o.TestNameSeparator).Returns((string)null);
string result = TheOptions.TestNameSeparator;
Assert.AreEqual(Options.OptionTestNameSeparatorDefaultValue, result);

MockXmlOptions.Setup(o => o.TestNameSeparator).Returns("FooBar");
result = TheOptions.TestNameSeparator;
Assert.AreEqual("FooBar", result);
}

[TestMethod]
public void PathExtension__ReturnsValueOrDefault()
{
MockXmlOptions.Setup(o => o.PathExtension).Returns((string)null);
string result = TheOptions.PathExtension;
Assert.AreEqual(Options.OptionPathExtensionDefaultValue, result);

MockXmlOptions.Setup(o => o.PathExtension).Returns("FooBar");
result = TheOptions.PathExtension;
Assert.AreEqual("FooBar", result);
}

[TestMethod]
public void BatchForTestTeardown__ReturnsValueOrDefault()
{
Expand Down
98 changes: 98 additions & 0 deletions GoogleTestAdapter/Core.Tests/TestCases/ListTestsParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GoogleTestAdapter.TestCases
{

[TestClass]
public class ListTestsParserTests : AbstractGoogleTestExtensionTests
{

[TestMethod]
public void ParseListTestsOutput_SimpleTest_CorrectSuiteAndName()
{
var consoleOutput = new List<string>
{
"MySuite.",
" MyTestCase"
};

IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
.ParseListTestsOutput(consoleOutput);

Assert.AreEqual(1, descriptors.Count);
Assert.AreEqual("MySuite", descriptors[0].Suite);
Assert.AreEqual("MyTestCase", descriptors[0].Name);
Assert.IsNull(descriptors[0].Param);
Assert.IsNull(descriptors[0].TypeParam);
Assert.AreEqual("MySuite.MyTestCase", descriptors[0].DisplayName);
Assert.AreEqual("MySuite.MyTestCase", descriptors[0].FullyQualifiedName);
}

[TestMethod]
public void ParseListTestsOutput_TestWithParam_CorrectParsing()
{
var consoleOutput = new List<string>
{
"InstantiationName/ParameterizedTests.",
" Simple/0 # GetParam() = (1,)",
};

IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
.ParseListTestsOutput(consoleOutput);

Assert.AreEqual(1, descriptors.Count);
Assert.AreEqual("InstantiationName/ParameterizedTests", descriptors[0].Suite);
Assert.AreEqual("Simple/0", descriptors[0].Name);
Assert.AreEqual("(1,)", descriptors[0].Param);
Assert.IsNull(descriptors[0].TypeParam);
Assert.AreEqual("InstantiationName/ParameterizedTests.Simple/0", descriptors[0].FullyQualifiedName);
Assert.AreEqual("InstantiationName/ParameterizedTests.Simple/0 [(1,)]", descriptors[0].DisplayName);
}

[TestMethod]
public void ParseListTestsOutput_TestWithTypeParam_CorrectParsing()
{
var consoleOutput = new List<string>
{
"TypedTests/0. # TypeParam = class std::vector<int,class std::allocator<int> >",
" CanIterate",
};

IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
.ParseListTestsOutput(consoleOutput);

Assert.AreEqual(1, descriptors.Count);
Assert.AreEqual("TypedTests/0", descriptors[0].Suite);
Assert.AreEqual("CanIterate", descriptors[0].Name);
Assert.IsNull(descriptors[0].Param);
Assert.AreEqual("std::vector<int,std::allocator<int> >", descriptors[0].TypeParam);
Assert.AreEqual("TypedTests/0.CanIterate", descriptors[0].FullyQualifiedName);
Assert.AreEqual("TypedTests/0.CanIterate<std::vector<int,std::allocator<int> > >", descriptors[0].DisplayName);
}

[TestMethod]
public void ParseListTestsOutput_TestWithParamAndTestNameSeparator_CorrectParsing()
{
MockOptions.Setup(o => o.TestNameSeparator).Returns("::");
var consoleOutput = new List<string>
{
"InstantiationName/ParameterizedTests.",
" Simple/0 # GetParam() = (1,)",
};

IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
.ParseListTestsOutput(consoleOutput);

Assert.AreEqual(1, descriptors.Count);
Assert.AreEqual("InstantiationName/ParameterizedTests", descriptors[0].Suite);
Assert.AreEqual("Simple/0", descriptors[0].Name);
Assert.AreEqual("(1,)", descriptors[0].Param);
Assert.IsNull(descriptors[0].TypeParam);
Assert.AreEqual("InstantiationName/ParameterizedTests.Simple/0", descriptors[0].FullyQualifiedName);
Assert.AreEqual("InstantiationName::ParameterizedTests.Simple::0 [(1,)]", descriptors[0].DisplayName);
}

}

}
3 changes: 3 additions & 0 deletions GoogleTestAdapter/Core/Helpers/XmlOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- add Options UI integration to one of the classes in GoogleTestAdapter.VsPackage.OptionsPages.*
- handle property in method GoogleTestAdapter.VsPackage.GoogleTestExtensionOptionsPage.GetRunSettingsFromOptionPages()
- add new option to Resources/AllTestSettings.gta.runsettings
- add default mock configuration in method AbstractGoogleTestExtensionTests.SetUp()
*/
public interface IXmlOptions
{
Expand All @@ -29,6 +30,7 @@ public interface IXmlOptions
string BatchForTestTeardown { get; set; }
string TraitsRegexesAfter { get; set; }
string TraitsRegexesBefore { get; set; }
string TestNameSeparator { get; set; }
bool? DebugMode { get; set; }
}

Expand All @@ -52,6 +54,7 @@ public static void GetUnsetValuesFrom(this IXmlOptions self, IXmlOptions other)
self.BatchForTestTeardown = self.BatchForTestTeardown ?? other.BatchForTestTeardown;
self.TraitsRegexesAfter = self.TraitsRegexesAfter ?? other.TraitsRegexesAfter;
self.TraitsRegexesBefore = self.TraitsRegexesBefore ?? other.TraitsRegexesBefore;
self.TestNameSeparator = self.TestNameSeparator ?? other.TestNameSeparator;
self.DebugMode = self.DebugMode ?? other.DebugMode;
}
}
Expand Down
8 changes: 8 additions & 0 deletions GoogleTestAdapter/Core/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ public virtual List<RegexTraitPair> TraitsRegexesAfter
}


public const string OptionTestNameSeparator = "Test name separator";
public const string OptionTestNameSeparatorDefaultValue = "";
public const string OptionTestNameSeparatorDescription =
"Test names produced by Google Test might contain the character '/', which makes VS cut the name after the '/' if the test explorer window is not wide enough. This option's value, if non-empty, will replace the '/' character to avoid that behavior. Note that '\\', ' ', '|', and '-' produce the same behavior ('.', '_', ':', and '::' are known to work - there might be more). Note also that traits regexes are evaluated against the tests' display names (and must thus be consistent with this option).";

public virtual string TestNameSeparator => XmlOptions.TestNameSeparator ?? OptionTestNameSeparatorDefaultValue;


public const string OptionDebugMode = "Debug mode";
public const bool OptionDebugModeDefaultValue = false;
public const string OptionDebugModeDescription =
Expand Down
20 changes: 9 additions & 11 deletions GoogleTestAdapter/Core/TestCases/ListTestsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,22 @@
namespace GoogleTestAdapter.TestCases
{

internal class ListTestsParser
public class ListTestsParser
{
private TestEnvironment TestEnvironment { get; }
private string TestNameSeparator { get; }

internal ListTestsParser(TestEnvironment testEnvironment)
public ListTestsParser(TestEnvironment testEnvironment)
{
TestEnvironment = testEnvironment;
TestNameSeparator = TestEnvironment.Options.TestNameSeparator;
}

internal IList<TestCaseDescriptor> ParseListTestsOutput(string executable)
{
var launcher = new ProcessLauncher(TestEnvironment, TestEnvironment.Options.PathExtension);
List<string> consoleOutput = launcher.GetOutputOfCommand("", executable, GoogleTestConstants.ListTestsOption.Trim(), false, false);
return ParseConsoleOutput(consoleOutput);
}

private List<TestCaseDescriptor> ParseConsoleOutput(List<string> output)
public IList<TestCaseDescriptor> ParseListTestsOutput(List<string> consoleOutput)
{
var testCaseDescriptors = new List<TestCaseDescriptor>();
string currentSuite = "";
foreach (string trimmedLine in output.Select(line => line.Trim('.', '\n', '\r')))
foreach (string trimmedLine in consoleOutput.Select(line => line.Trim('.', '\n', '\r')))
{
if (trimmedLine.StartsWith(" "))
{
Expand Down Expand Up @@ -63,7 +58,10 @@ private TestCaseDescriptor CreateDescriptor(string suiteLine, string testCaseLin
}

string fullyQualifiedName = $"{suite}.{name}";

string displayName = GetDisplayName(fullyQualifiedName, typeParam, param);
if (!string.IsNullOrEmpty(TestNameSeparator))
displayName = displayName.Replace("/", TestNameSeparator);

return new TestCaseDescriptor(suite, name, typeParam, param, fullyQualifiedName, displayName);
}
Expand Down
14 changes: 7 additions & 7 deletions GoogleTestAdapter/Core/TestCases/TestCaseDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace GoogleTestAdapter.TestCases
{
internal class TestCaseDescriptor
public class TestCaseDescriptor
{
internal string Suite { get; }
internal string Name { get; }
internal string Param { get; }
internal string TypeParam { get; }
public string Suite { get; }
public string Name { get; }
public string Param { get; }
public string TypeParam { get; }

internal string FullyQualifiedName { get; }
internal string DisplayName { get; }
public string FullyQualifiedName { get; }
public string DisplayName { get; }

internal TestCaseDescriptor(string suite, string name, string typeParam, string param, string fullyQualifiedName, string displayName)
{
Expand Down
4 changes: 3 additions & 1 deletion GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public TestCaseFactory(string executable, TestEnvironment testEnvironment)

public IList<TestCase> CreateTestCases()
{
IList<TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(TestEnvironment).ParseListTestsOutput(Executable);
var launcher = new ProcessLauncher(TestEnvironment, TestEnvironment.Options.PathExtension);
List<string> consoleOutput = launcher.GetOutputOfCommand("", Executable, GoogleTestConstants.ListTestsOption.Trim(), false, false);
IList<TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(TestEnvironment).ParseListTestsOutput(consoleOutput);
List<TestCaseLocation> testCaseLocations = GetTestCaseLocations(testCaseDescriptors, TestEnvironment.Options.PathExtension);

return testCaseDescriptors.Select(descriptor => CreateTestCase(descriptor, testCaseLocations)).ToList();
Expand Down
3 changes: 2 additions & 1 deletion GoogleTestAdapter/Resources/AllTestSettings.gta.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<ShuffleTestsSeed>0</ShuffleTestsSeed>
<TestDiscoveryRegex>.*Tests.*.exe</TestDiscoveryRegex>
<PathExtension>C:\fooDir;C:\barDir</PathExtension>
<TraitsRegexesAfter></TraitsRegexesAfter>
<TraitsRegexesAfter />
<TraitsRegexesBefore />
<TestNameSeparator />
</GoogleTestAdapter>
</RunSettings>
3 changes: 3 additions & 0 deletions GoogleTestAdapter/TestAdapter/Settings/RunSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public RunSettings()
public string TraitsRegexesAfter { get; set; }
public bool ShouldSerializeTraitsRegexesAfter() { return TraitsRegexesAfter != null; }

public string TestNameSeparator { get; set; }
public bool ShouldSerializeTestNameSeparator() { return TestNameSeparator != null; }

public bool? DebugMode { get; set; }
public bool ShouldSerializeDebugMode() { return DebugMode != null; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private RunSettings GetRunSettingsFromOptionPages()
runSettings.PathExtension = generalOptions.PathExtension;
runSettings.TraitsRegexesBefore = generalOptions.TraitsRegexesBefore;
runSettings.TraitsRegexesAfter = generalOptions.TraitsRegexesAfter;
runSettings.TestNameSeparator = generalOptions.TestNameSeparator;
runSettings.DebugMode = generalOptions.DebugMode;
runSettings.AdditionalTestExecutionParam = generalOptions.AdditionalTestExecutionParams;
runSettings.BatchForTestSetup = generalOptions.BatchForTestSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public string TraitsRegexesAfter
}
private string traitsRegexesAfter = Options.OptionTraitsRegexesDefaultValue;

[Category(Options.CategoryName)]
[DisplayName(Options.OptionTestNameSeparator)]
[Description(Options.OptionTestNameSeparatorDescription)]
public string TestNameSeparator
{
get { return testNameSeparator; }
set { SetAndNotify(ref testNameSeparator, value); }
}
private string testNameSeparator = Options.OptionTestNameSeparatorDefaultValue;

[Category(Options.CategoryName)]
[DisplayName(Options.OptionAdditionalTestExecutionParams)]
[Description(Options.OptionAdditionalTestExecutionParamsDescription)]
Expand Down

0 comments on commit 2dfbdc1

Please sign in to comment.