Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#271 reorganize options #272

Merged
merged 16 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GoogleTestAdapter/Common/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace GoogleTestAdapter.Common
{

public enum Severity { Info, Warning, Error }
public enum OutputMode { None = 0, Info = 10, Debug = 20, Verbose = 30 }

public interface ILogger
{
Expand All @@ -13,6 +14,7 @@ public interface ILogger
void DebugInfo(string message);
void DebugWarning(string message);
void DebugError(string message);
void VerboseInfo(string message);

IList<string> GetMessages(params Severity[] severities);

Expand Down
33 changes: 21 additions & 12 deletions GoogleTestAdapter/Common/LoggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ protected class LogEntry

private readonly IList<LogEntry> _messages = new List<LogEntry>();

private readonly Func<bool> _inDebugMode;
private readonly Func<OutputMode> _outputMode;

protected LoggerBase(Func<bool> inDebugMode)
protected LoggerBase(Func<OutputMode> outputMode)
{
_inDebugMode = inDebugMode;
_outputMode = outputMode;
}

public abstract void Log(Severity severity, string message);
Expand All @@ -45,35 +45,44 @@ public IList<string> GetMessages(params Severity[] severities)

public virtual void LogInfo(string message)
{
Log(Severity.Info, message);
if (_outputMode() >= OutputMode.Info)
Log(Severity.Info, message);
}

public virtual void LogWarning(string message)
{
Log(Severity.Warning, message);
if (_outputMode() >= OutputMode.Info)
Log(Severity.Warning, message);
}

public virtual void LogError(string message)
{
Log(Severity.Error, message);
if (_outputMode() >= OutputMode.Info)
Log(Severity.Error, message);
}

public void DebugInfo(string message)
{
if (_inDebugMode())
LogInfo(message);
if (_outputMode() >= OutputMode.Debug)
Log(Severity.Info, message);
}

public void DebugWarning(string message)
{
if (_inDebugMode())
LogWarning(message);
if (_outputMode() >= OutputMode.Debug)
Log(Severity.Warning, message);
}

public void DebugError(string message)
{
if (_inDebugMode())
LogError(message);
if (_outputMode() >= OutputMode.Debug)
Log(Severity.Error, message);
}

public void VerboseInfo(string message)
{
if (_outputMode() >= OutputMode.Verbose)
Log(Severity.Info, message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion GoogleTestAdapter/Core.Tests/GoogleTestDiscovererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void GetTestsFromExecutable_WithPathExtension_FindsTestsWithLocation()
try
{
string targetExe = Path.Combine(baseDir, "exe", Path.GetFileName(TestResources.DllTests_ReleaseX86));
MockOptions.Setup(o => o.PathExtension).Returns(SettingsWrapper.ExecutableDirPlaceholder + @"\..\dll");
MockOptions.Setup(o => o.PathExtension).Returns(PlaceholderReplacer.ExecutableDirPlaceholder + @"\..\dll");

var discoverer = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options);
IList<TestCase> testCases = discoverer.GetTestsFromExecutable(targetExe);
Expand Down
7 changes: 4 additions & 3 deletions GoogleTestAdapter/Core.Tests/Helpers/TestEnvironmentTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GoogleTestAdapter.Tests.Common;
using GoogleTestAdapter.Common;
using GoogleTestAdapter.Tests.Common;
using GoogleTestAdapter.Tests.Common.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down Expand Up @@ -42,15 +43,15 @@ public void LogError_ProducesErrorOnLogger()
[TestCategory(Unit)]
public void DebugInfo_InDebugMode_ProducesInfoOnLogger()
{
MockOptions.Setup(o => o.DebugMode).Returns(true);
MockOptions.Setup(o => o.OutputMode).Returns(OutputMode.Verbose);
_environment.Logger.DebugInfo("bar");
MockLogger.Verify(l => l.DebugInfo(It.Is<string>(s => s.Contains("bar"))), Times.Exactly(1));
}
[TestMethod]
[TestCategory(Unit)]
public void DebugInfo_NotInDebugMode_DoesNotProduceLogging()
{
MockOptions.Setup(o => o.DebugMode).Returns(false);
MockOptions.Setup(o => o.OutputMode).Returns(OutputMode.Info);
_environment.Logger.DebugInfo("bar");
MockLogger.Verify(l => l.LogInfo(It.Is<string>(s => s.Contains("bar"))), Times.Never());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void RunTests_WorkingDirNotSet_TestFails()
public void RunTests_WorkingDirSetForSolution_TestPasses()
{
var testCase = TestDataCreator.GetTestCases("WorkingDir.IsSolutionDirectory").First();
var settings = CreateSettings(SettingsWrapper.SolutionDirPlaceholder, null);
var settings = CreateSettings(PlaceholderReplacer.SolutionDirPlaceholder, null);
var runner = new SequentialTestRunner("", 0, "", MockFrameworkReporter.Object, TestEnvironment.Logger, settings, new SchedulingAnalyzer(TestEnvironment.Logger));

runner.RunTests(testCase.Yield(), false, ProcessExecutorFactory);
Expand All @@ -73,7 +73,7 @@ public void RunTests_WorkingDirSetForSolution_TestPasses()
public void RunTests_WorkingDirSetForProject_TestPasses()
{
TestCase testCase = TestDataCreator.GetTestCases("WorkingDir.IsSolutionDirectory").First();
var settings = CreateSettings("foo", SettingsWrapper.SolutionDirPlaceholder);
var settings = CreateSettings("foo", PlaceholderReplacer.SolutionDirPlaceholder);
var runner = new SequentialTestRunner("", 0, "", MockFrameworkReporter.Object, TestEnvironment.Logger, settings, new SchedulingAnalyzer(TestEnvironment.Logger));

runner.RunTests(testCase.Yield(), false, ProcessExecutorFactory);
Expand Down
33 changes: 17 additions & 16 deletions GoogleTestAdapter/Core.Tests/Settings/SettingsWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using FluentAssertions;
using GoogleTestAdapter.Common;
using GoogleTestAdapter.Helpers;
using GoogleTestAdapter.Tests.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -91,28 +92,28 @@ public void MaxNrOfThreads_InvalidValue_ReturnsDefaultValue()
[TestCategory(Unit)]
public void AdditionalTestExecutionParam__PlaceholdersAreTreatedCorrectly()
{
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(SettingsWrapper.TestDirPlaceholder);
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(PlaceholderReplacer.TestDirPlaceholder);
string result = TheOptions.GetUserParametersForExecution("SomeExecutable.exe", "mydir", 0);
result.Should().Be("mydir");

MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(SettingsWrapper.TestDirPlaceholder + " " + SettingsWrapper.TestDirPlaceholder);
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(PlaceholderReplacer.TestDirPlaceholder + " " + PlaceholderReplacer.TestDirPlaceholder);
result = TheOptions.GetUserParametersForExecution("SomeExecutable.exe", "mydir", 0);
result.Should().Be("mydir mydir");

MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(SettingsWrapper.TestDirPlaceholder.ToLower());
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(PlaceholderReplacer.TestDirPlaceholder.ToLower());
result = TheOptions.GetUserParametersForExecution("SomeExecutable.exe", "mydir", 0);
result.Should().Be(SettingsWrapper.TestDirPlaceholder.ToLower());
result.Should().Be(PlaceholderReplacer.TestDirPlaceholder.ToLower());

MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(SettingsWrapper.ThreadIdPlaceholder);
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(PlaceholderReplacer.ThreadIdPlaceholder);
result = TheOptions.GetUserParametersForExecution("SomeExecutable.exe", "mydir", 4711);
result.Should().Be("4711");

MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(SettingsWrapper.TestDirPlaceholder + ", " + SettingsWrapper.ThreadIdPlaceholder);
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(PlaceholderReplacer.TestDirPlaceholder + ", " + PlaceholderReplacer.ThreadIdPlaceholder);
result = TheOptions.GetUserParametersForExecution("SomeExecutable.exe", "mydir", 4711);
result.Should().Be("mydir, 4711");

MockXmlOptions.Setup(o => o.SolutionDir).Returns(@"C:\\TheSolutionDir");
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(SettingsWrapper.TestDirPlaceholder + ", " + SettingsWrapper.ThreadIdPlaceholder + ", " + SettingsWrapper.SolutionDirPlaceholder + ", " + SettingsWrapper.ExecutablePlaceholder);
MockXmlOptions.Setup(o => o.AdditionalTestExecutionParam).Returns(PlaceholderReplacer.TestDirPlaceholder + ", " + PlaceholderReplacer.ThreadIdPlaceholder + ", " + PlaceholderReplacer.SolutionDirPlaceholder + ", " + PlaceholderReplacer.ExecutablePlaceholder);
result = TheOptions.GetUserParametersForExecution("SomeExecutable.exe", "mydir", 4711);
result.Should().Be(@"mydir, 4711, C:\\TheSolutionDir, SomeExecutable.exe");
}
Expand Down Expand Up @@ -199,13 +200,13 @@ public void ShuffleTests__ReturnsValueOrDefault()
[TestCategory(Unit)]
public void DebugMode__ReturnsValueOrDefault()
{
MockXmlOptions.Setup(o => o.DebugMode).Returns((bool?)null);
bool result = TheOptions.DebugMode;
result.Should().Be(SettingsWrapper.OptionDebugModeDefaultValue);
MockXmlOptions.Setup(o => o.OutputMode).Returns((OutputMode?)null);
OutputMode result = TheOptions.OutputMode;
result.Should().Be(SettingsWrapper.OptionOutputModeDefaultValue);

MockXmlOptions.Setup(o => o.DebugMode).Returns(!SettingsWrapper.OptionDebugModeDefaultValue);
result = TheOptions.DebugMode;
result.Should().Be(!SettingsWrapper.OptionDebugModeDefaultValue);
MockXmlOptions.Setup(o => o.OutputMode).Returns(OutputMode.Verbose);
result = TheOptions.OutputMode;
result.Should().Be(OutputMode.Verbose);
}

[TestMethod]
Expand Down Expand Up @@ -264,7 +265,7 @@ public void PathExtension__ReturnsValueOrDefault()
[TestCategory(Unit)]
public void GetPathExtension__PlaceholderIsReplaced()
{
MockXmlOptions.Setup(o => o.PathExtension).Returns("Foo;" + SettingsWrapper.ExecutableDirPlaceholder + ";Bar");
MockXmlOptions.Setup(o => o.PathExtension).Returns("Foo;" + PlaceholderReplacer.ExecutableDirPlaceholder + ";Bar");
string result = TheOptions.GetPathExtension(TestResources.Tests_DebugX86);

// ReSharper disable once PossibleNullReferenceException
Expand Down Expand Up @@ -295,7 +296,7 @@ public void GetPathExtension__PlatformAndConfigurationNamePlaceholdersAreReplace
MockXmlOptions.Setup(o => o.PlatformName).Returns("Debug");
MockXmlOptions.Setup(o => o.ConfigurationName).Returns("x86");
MockXmlOptions.Setup(o => o.PathExtension).Returns(
$"P:{SettingsWrapper.PlatformNamePlaceholder}, C:{SettingsWrapper.ConfigurationNamePlaceholder}");
$"P:{PlaceholderReplacer.PlatformNamePlaceholder}, C:{PlaceholderReplacer.ConfigurationNamePlaceholder}");

string result = TheOptions.GetPathExtension(TestResources.LoadTests_ReleaseX86);

Expand Down Expand Up @@ -520,7 +521,7 @@ public void ToString_PrintsCorrectly()
optionsString.Should().Contain("TraitsRegexesAfter: {}");
optionsString.Should().Contain("TestNameSeparator: ''");
optionsString.Should().Contain("ParseSymbolInformation: True");
optionsString.Should().Contain("DebugMode: False");
optionsString.Should().Contain("OutputMode: Info");
optionsString.Should().Contain("TimestampOutput: False");
optionsString.Should().Contain("AdditionalTestExecutionParam: ''");
optionsString.Should().Contain("BatchForTestSetup: 'C:\\\\myfolder\\myfile.xml'");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using FluentAssertions;
using GoogleTestAdapter.Common;
using GoogleTestAdapter.DiaResolver;
using GoogleTestAdapter.Helpers;
using GoogleTestAdapter.Tests.Common;
Expand All @@ -18,7 +19,7 @@ public class TestCaseResolverTests : TestsBase
[TestInitialize]
public void Setup()
{
_fakeLogger = new FakeLogger(() => true, false);
_fakeLogger = new FakeLogger(() => OutputMode.Verbose, false);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using GoogleTestAdapter.Common;
using GoogleTestAdapter.Helpers;
using GoogleTestAdapter.Tests.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void GetTestResults_InvalidFile_WarningAndEmptyResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001",
"GoogleTestSuiteName1.TestMethod_002");
MockOptions.Setup(o => o.DebugMode).Returns(true);
MockOptions.Setup(o => o.OutputMode).Returns(OutputMode.Verbose);

var parser = new XmlTestResultParser(testCases, "someexecutable", TestResources.XmlFileBroken, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
Expand All @@ -48,7 +49,7 @@ public void GetTestResults_FileWithInvalidStatusAttribute_WarningAndEmptyResult(
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001",
"GoogleTestSuiteName1.TestMethod_002");
MockOptions.Setup(o => o.DebugMode).Returns(true);
MockOptions.Setup(o => o.OutputMode).Returns(OutputMode.Verbose);

var parser = new XmlTestResultParser(testCases, "someexecutable", TestResources.XmlFileBroken_InvalidStatusAttibute, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
Expand Down
3 changes: 3 additions & 0 deletions GoogleTestAdapter/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
<Compile Include="Runners\TestResultCollector.cs" />
<Compile Include="Scheduling\SchedulingAnalyzer.cs" />
<Compile Include="Settings\IGoogleTestAdapterSettingsContainer.cs" />
<Compile Include="Settings\PlaceholderReplacer.cs" />
<Compile Include="Settings\RegexTraitPair.cs" />
<Compile Include="Settings\RunSettings.cs" />
<Compile Include="Settings\SettingsPrinter.cs" />
<Compile Include="Settings\SettingsSerializationContainer.cs" />
<Compile Include="TestCases\StreamingListTestsParser.cs" />
<Compile Include="TestCases\ListTestsParser.cs" />
Expand Down
4 changes: 2 additions & 2 deletions GoogleTestAdapter/Core/GoogleTestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void DiscoverTests(string executable, ITestFrameworkReporter repo
void ReportTestCases(TestCase testCase)
{
reporter.ReportTestsFound(testCase.Yield());
logger.DebugInfo("Added testcase " + testCase.DisplayName);
logger.VerboseInfo("Added testcase " + testCase.DisplayName);
nrOfTestCases++;
}

Expand All @@ -73,7 +73,7 @@ public IList<TestCase> GetTestsFromExecutable(string executable)

foreach (TestCase testCase in testCases)
{
_logger.DebugInfo("Added testcase " + testCase.DisplayName);
_logger.VerboseInfo("Added testcase " + testCase.DisplayName);
}
_logger.LogInfo("Found " + testCases.Count + " tests in executable " + executable);

Expand Down
6 changes: 6 additions & 0 deletions GoogleTestAdapter/Core/Settings/IGoogleTestAdapterSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This file has been modified by Microsoft on 6/2017.

using GoogleTestAdapter.Common;

namespace GoogleTestAdapter.Settings
{

Expand Down Expand Up @@ -41,7 +43,9 @@ public interface IGoogleTestAdapterSettings
string TestNameSeparator { get; set; }
bool? ParseSymbolInformation { get; set; }
bool? DebugMode { get; set; }
OutputMode? OutputMode { get; set; }
bool? TimestampOutput { get; set; }
bool? ShowReleaseNotes { get; set; }
bool? KillProcessesOnCancel { get; set; }
bool? SkipOriginCheck { get; set; }
string ExitCodeTestCase { get; set; }
Expand Down Expand Up @@ -81,7 +85,9 @@ public static void GetUnsetValuesFrom(this IGoogleTestAdapterSettings self, IGoo
self.TestNameSeparator = self.TestNameSeparator ?? other.TestNameSeparator;
self.ParseSymbolInformation = self.ParseSymbolInformation ?? other.ParseSymbolInformation;
self.DebugMode = self.DebugMode ?? other.DebugMode;
self.OutputMode = self.OutputMode ?? other.OutputMode;
self.TimestampOutput = self.TimestampOutput ?? other.TimestampOutput;
self.ShowReleaseNotes = self.ShowReleaseNotes ?? other.ShowReleaseNotes;
self.KillProcessesOnCancel = self.KillProcessesOnCancel ?? other.KillProcessesOnCancel;
self.SkipOriginCheck = self.SkipOriginCheck ?? other.SkipOriginCheck;
self.ExitCodeTestCase = self.ExitCodeTestCase ?? other.ExitCodeTestCase;
Expand Down
Loading