Skip to content

Commit

Permalink
Fixed the normal verbosity level to not log the full information for …
Browse files Browse the repository at this point in the history
…non-failed tests (#1396)

* Added an additional verbosity level to log the full informaton of non-failed tests. Normal level willnot log the full information for non-failed tests
  • Loading branch information
cltshivash authored Feb 1, 2018
1 parent 32611a5 commit 46ccd50
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ internal void RaiseDiscoveryComplete(DiscoveryCompleteEventArgs args)
this.loggerEventQueue.Flush();
}

/// <summary>
/// Raises test run complete to the enabled loggers
/// </summary>
/// <param name="args"> Arguments to be raised </param>
internal void RaiseTestRunComplete(TestRunCompleteEventArgs args)
{
ValidateArg.NotNull<TestRunCompleteEventArgs>(args, "args");

CheckDisposed();

// Size is being send as 0. (It is good to send the size as the job queue uses it)
SafeInvokeAsync(() => this.TestRunComplete, args, 0, "InternalTestLoggerEvents.SendTestRunComplete");

// Wait for the loggers to finish processing the messages for the run.
this.loggerEventQueue.Flush();
}

/// <summary>
/// Raise the test run complete event to test loggers and waits
/// for the events to be processed.
Expand Down
181 changes: 114 additions & 67 deletions src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Internal
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities;

using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;
using CommandLineResources = Resources.Resources;

/// <summary>
/// Logger for sending output to the console.
Expand Down Expand Up @@ -61,7 +61,8 @@ internal enum Verbosity
{
Quiet,
Minimal,
Normal
Normal,
Detailed
}

#region Fields
Expand All @@ -76,11 +77,12 @@ internal enum Verbosity
private Verbosity verbosityLevel = Verbosity.Minimal;
#endif

private TestOutcome testOutcome = TestOutcome.None;
private int testsTotal = 0;
private int testsPassed = 0;
private int testsFailed = 0;
private int testsSkipped = 0;
private bool testRunHasErrorMessages = false;

#endregion

#region Constructor
Expand Down Expand Up @@ -168,10 +170,10 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
var prefixExists = parameters.TryGetValue(ConsoleLogger.PrefixParam, out string prefix);
if (prefixExists)
{
bool.TryParse(prefix, out ConsoleLogger.AppendPrefix);
bool.TryParse(prefix, out AppendPrefix);
}

this.Initialize(events, String.Empty);
Initialize(events, String.Empty);
}
#endregion

Expand Down Expand Up @@ -331,17 +333,35 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e)
switch (e.Level)
{
case TestMessageLevel.Informational:
Output.Information(ConsoleLogger.AppendPrefix, e.Message);
break;
{
if (verbosityLevel == Verbosity.Quiet || verbosityLevel == Verbosity.Minimal)
{
break;
}

Output.Information(AppendPrefix, e.Message);
break;
}

case TestMessageLevel.Warning:
Output.Warning(ConsoleLogger.AppendPrefix, e.Message);
break;
{
if (verbosityLevel == Verbosity.Quiet)
{
break;
}

Output.Warning(AppendPrefix, e.Message);
break;
}

case TestMessageLevel.Error:
this.testOutcome = TestOutcome.Failed;
Output.Error(ConsoleLogger.AppendPrefix, e.Message);
break;
{
this.testRunHasErrorMessages = true;
Output.Error(AppendPrefix, e.Message);
break;
}
default:
Debug.Fail("ConsoleLogger.TestMessageHandler: The test message level is unrecognized: {0}", e.Level.ToString());
EqtTrace.Warning("ConsoleLogger.TestMessageHandler: The test message level is unrecognized: {0}", e.Level.ToString());
break;
}
}
Expand All @@ -357,51 +377,78 @@ private void TestResultHandler(object sender, TestResultEventArgs e)
// Update the test count statistics based on the result of the test.
this.testsTotal++;

string name = null;
name = !string.IsNullOrEmpty(e.Result.DisplayName) ? e.Result.DisplayName : e.Result.TestCase.DisplayName;

if (e.Result.Outcome == TestOutcome.Skipped)
string testDisplayName = e.Result.DisplayName;
if (string.IsNullOrWhiteSpace(e.Result.DisplayName))
{
this.testsSkipped++;
if (!this.verbosityLevel.Equals(Verbosity.Quiet))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator,
name);
Output.Warning(false, output);
DisplayFullInformation(e.Result);
}
testDisplayName = e.Result.TestCase.DisplayName;
}
else if (e.Result.Outcome == TestOutcome.Failed)
{
this.testOutcome = TestOutcome.Failed;
this.testsFailed++;
if (!this.verbosityLevel.Equals(Verbosity.Quiet))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator,
name);
Output.Information(false, ConsoleColor.Red, output);
DisplayFullInformation(e.Result);
}
}
else if (e.Result.Outcome == TestOutcome.Passed)
{
if (this.verbosityLevel.Equals(Verbosity.Normal))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, name);
Output.Information(false, output);
DisplayFullInformation(e.Result);
}
this.testsPassed++;
}
else

switch (e.Result.Outcome)
{
if (!this.verbosityLevel.Equals(Verbosity.Quiet))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator,
name);
Output.Information(false, output);
DisplayFullInformation(e.Result);
}
case TestOutcome.Skipped:
{
this.testsSkipped++;
if (this.verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator, testDisplayName);
Output.Warning(false, output);
if (this.verbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}

break;
}

case TestOutcome.Failed:
{
this.testsFailed++;
if (this.verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, testDisplayName);
Output.Information(false, ConsoleColor.Red, output);
DisplayFullInformation(e.Result);
break;
}

case TestOutcome.Passed:
{
this.testsPassed++;
if (this.verbosityLevel == Verbosity.Normal || this.verbosityLevel == Verbosity.Detailed)
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, testDisplayName);
Output.Information(false, output);
if (this.verbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}
}

break;
}

default:
{
if (this.verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator, testDisplayName);
Output.Information(false, output);
if (this.verbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}

break;
}
}
}

Expand Down Expand Up @@ -429,17 +476,17 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
}

// Output a summary.
if (this.testsTotal > 0)
if (testsTotal > 0)
{
string testCountDetails;

if (e.IsAborted || e.IsCanceled)
{
testCountDetails = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, testsPassed, testsFailed, testsSkipped);
testCountDetails = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, this.testsPassed, this.testsFailed, this.testsSkipped);
}
else
{
testCountDetails = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, testsTotal, testsPassed, testsFailed, testsSkipped);
testCountDetails = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, this.testsTotal, this.testsPassed, this.testsFailed, this.testsSkipped);
}

Output.Information(false, testCountDetails);
Expand All @@ -453,24 +500,24 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
{
Output.Error(false, CommandLineResources.TestRunAborted);
}
else if (this.testOutcome == TestOutcome.Failed && this.testsTotal > 0)
else if (this.testsFailed > 0 || this.testRunHasErrorMessages)
{
Output.Error(false, CommandLineResources.TestRunFailed);
}
else if(this.testsTotal > 0)
else if (testsTotal > 0)
{
Output.Information(false, ConsoleColor.Green, CommandLineResources.TestRunSuccessful);
}

if (this.testsTotal > 0)
if (testsTotal > 0)
{
if (!e.ElapsedTimeInRunningTests.Equals(TimeSpan.Zero))
if (e.ElapsedTimeInRunningTests.Equals(TimeSpan.Zero))
{
PrintTimeSpan(e.ElapsedTimeInRunningTests);
EqtTrace.Info("Skipped printing test execution time on console because it looks like the test run had faced some errors");
}
else
{
EqtTrace.Info("Skipped printing test execution time on console because it looks like the test run had faced some errors");
PrintTimeSpan(e.ElapsedTimeInRunningTests);
}
}
}
Expand All @@ -491,14 +538,14 @@ public static void RaiseTestRunError(TestRunResultAggregator testRunResultAggreg
// testRunResultAggregator can be null, if error is being raised in discovery context.
testRunResultAggregator?.MarkTestRunFailed();

Output.Error(ConsoleLogger.AppendPrefix, exception.Message);
Output.Error(AppendPrefix, exception.Message);

// Send inner exception only when its message is different to avoid duplicate.
if (exception is TestPlatformException &&
exception.InnerException != null &&
string.Compare(exception.Message, exception.InnerException.Message, StringComparison.CurrentCultureIgnoreCase) != 0)
{
Output.Error(ConsoleLogger.AppendPrefix, exception.InnerException.Message);
Output.Error(AppendPrefix, exception.InnerException.Message);
}
}

Expand All @@ -514,7 +561,7 @@ public static void RaiseTestRunWarning(TestRunResultAggregator testRunResultAggr
ConsoleLogger.Output = ConsoleOutput.Instance;
}

Output.Warning(ConsoleLogger.AppendPrefix, warningMessage);
Output.Warning(AppendPrefix, warningMessage);
}
}
}
Loading

0 comments on commit 46ccd50

Please sign in to comment.