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
Console output for minimal and quiet #2191
Changes from 9 commits
795d3a8
4da1046
5bda2ee
103ee9e
afeda96
dbd9b7e
bfb5804
c952c42
3391a72
ed14b11
3250de1
d38829e
8ab3fa2
bf38a2e
c16c653
1b77242
5075c6b
cae94bb
a742746
18c4022
a588684
d22a535
9ba8b23
6f3650a
61859a5
75d50f2
d36c66f
b0ab8d4
8644107
54aca6f
6ad0add
c4a52e4
ea8b54b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging | ||
{ | ||
using System; | ||
public class SourceSummary | ||
{ | ||
public int TotalTests { get; set; } | ||
public int PassedTests { get; set; } | ||
public int FailedTests { get; set; } | ||
public int SkippedTests { get; set; } | ||
public TimeSpan TimeSpan { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Internal | ||
{ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
|
@@ -17,7 +18,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Internal | |
using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
|
||
using CommandLineResources = Resources.Resources; | ||
|
||
/// <summary> | ||
/// Logger for sending output to the console. | ||
/// All the console logger messages prints to Standard Output with respective color, except OutputLevel.Error messages | ||
|
@@ -107,10 +107,6 @@ internal enum Verbosity | |
private Verbosity verbosityLevel = Verbosity.Minimal; | ||
#endif | ||
|
||
private int testsTotal = 0; | ||
private int testsPassed = 0; | ||
private int testsFailed = 0; | ||
private int testsSkipped = 0; | ||
private bool testRunHasErrorMessages = false; | ||
|
||
#endregion | ||
|
@@ -155,6 +151,13 @@ protected static IOutput Output | |
/// </summary> | ||
public Verbosity VerbosityLevel => verbosityLevel; | ||
|
||
/// <summary> | ||
/// Dictionary of summary of each source. | ||
hvinett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
private ConcurrentDictionary<string, SourceSummary> sourceSummaryDictionary { get; set; } | ||
|
||
private string targetFramework; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Docs? And also this should move next to the rest of the private members on the top |
||
|
||
#endregion | ||
|
||
#region ITestLoggerWithParameters | ||
|
@@ -181,7 +184,7 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) | |
// Progress indicator needs to be displayed only for cli experience. | ||
this.progressIndicator = new ProgressIndicator(Output, new ConsoleHelper()); | ||
} | ||
|
||
// Register for the events. | ||
events.TestRunMessage += this.TestMessageHandler; | ||
events.TestResult += this.TestResultHandler; | ||
|
@@ -190,6 +193,7 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) | |
|
||
// Register for the discovery events. | ||
events.DiscoveryMessage += this.TestMessageHandler; | ||
this.sourceSummaryDictionary = new ConcurrentDictionary<string, SourceSummary>(); | ||
|
||
// TODO Get changes from https://github.com/Microsoft/vstest/pull/1111/ | ||
// events.DiscoveredTests += DiscoveredTestsHandler; | ||
|
@@ -225,6 +229,11 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param | |
bool.TryParse(noprogress, out DisableProgress); | ||
} | ||
|
||
if (this.verbosityLevel == Verbosity.Quiet) | ||
hvinett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
this.targetFramework = parameters[DefaultLoggerParameterNames.TargetFramework]; | ||
} | ||
|
||
Initialize(events, String.Empty); | ||
} | ||
#endregion | ||
|
@@ -467,10 +476,16 @@ private void TestResultHandler(object sender, TestResultEventArgs e) | |
{ | ||
ValidateArg.NotNull<object>(sender, "sender"); | ||
ValidateArg.NotNull<TestResultEventArgs>(e, "e"); | ||
SourceSummary summary; | ||
if (!this.sourceSummaryDictionary.TryGetValue(e.Result.TestCase.Source, out summary)) | ||
{ | ||
summary = new SourceSummary(); | ||
this.sourceSummaryDictionary.TryAdd(e.Result.TestCase.Source, summary); | ||
} | ||
|
||
// Update the test count statistics based on the result of the test. | ||
this.testsTotal++; | ||
|
||
summary.TotalTests++; | ||
summary.TimeSpan += e.Result.Duration; | ||
var testDisplayName = e.Result.DisplayName; | ||
|
||
if (string.IsNullOrWhiteSpace(e.Result.DisplayName)) | ||
|
@@ -488,7 +503,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) | |
{ | ||
case TestOutcome.Skipped: | ||
{ | ||
this.testsSkipped++; | ||
summary.SkippedTests++; | ||
if (this.verbosityLevel == Verbosity.Quiet) | ||
{ | ||
break; | ||
|
@@ -512,12 +527,12 @@ private void TestResultHandler(object sender, TestResultEventArgs e) | |
|
||
case TestOutcome.Failed: | ||
{ | ||
this.testsFailed++; | ||
summary.FailedTests++; | ||
if (this.verbosityLevel == Verbosity.Quiet) | ||
{ | ||
break; | ||
} | ||
|
||
// Pause the progress indicator before displaying test result information | ||
this.progressIndicator?.Pause(); | ||
|
||
|
@@ -533,7 +548,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) | |
|
||
case TestOutcome.Passed: | ||
{ | ||
this.testsPassed++; | ||
summary.PassedTests++; | ||
if (this.verbosityLevel == Verbosity.Normal || this.verbosityLevel == Verbosity.Detailed) | ||
{ | ||
// Pause the progress indicator before displaying test result information | ||
|
@@ -619,8 +634,40 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) | |
{ | ||
// Stop the progress indicator as we are about to print the summary | ||
this.progressIndicator?.Stop(); | ||
var testsPassed = 0; | ||
var testsFailed = 0; | ||
var testsSkipped = 0; | ||
var testsTotal = 0; | ||
Output.WriteLine(string.Empty, OutputLevel.Information); | ||
|
||
foreach (var sd in this.sourceSummaryDictionary.ToArray()) | ||
{ | ||
var summary = this.sourceSummaryDictionary[sd.Key]; | ||
testsPassed += summary.PassedTests; | ||
testsFailed += summary.FailedTests; | ||
testsSkipped += summary.SkippedTests; | ||
testsTotal += summary.TotalTests; | ||
|
||
if (verbosityLevel == Verbosity.Quiet) | ||
{ | ||
if (summary.FailedTests > 0) | ||
{ | ||
// Failed! Pass {1} Failed {2} skipped {3} Time : 233 se ({4}) | ||
Output.Information(false, ConsoleColor.Red, string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryFailed, summary.TotalTests, summary.PassedTests, summary.FailedTests, summary.SkippedTests, GetFormattedDurationString(summary.TimeSpan), sd.Key.Split('\\').Last(), targetFramework)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
nohwnd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
nohwnd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// Passed! Pass {1} Failed {2} skipped {3} Time : 233 se ({4}) | ||
Output.Information(false, ConsoleColor.Green, string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryPassed, summary.TotalTests, summary.PassedTests, summary.FailedTests, summary.SkippedTests, GetFormattedDurationString(summary.TimeSpan), sd.Key.Split('\\').Last(), targetFramework)); | ||
} | ||
} | ||
} | ||
|
||
if (verbosityLevel == Verbosity.Quiet) | ||
{ | ||
return; | ||
} | ||
|
||
// Printing Run-level Attachments | ||
var runLevelAttachementCount = (e.AttachmentSets == null) ? 0 : e.AttachmentSets.Sum(attachmentSet => attachmentSet.Attachments.Count); | ||
if (runLevelAttachementCount > 0) | ||
|
@@ -644,7 +691,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) | |
{ | ||
Output.Error(false, CommandLineResources.TestRunAborted); | ||
} | ||
else if (this.testsFailed > 0 || this.testRunHasErrorMessages) | ||
else if (testsFailed > 0 || this.testRunHasErrorMessages) | ||
{ | ||
Output.Error(false, CommandLineResources.TestRunFailed); | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class with no docs?