diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs b/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs index 5404ddde5d..302087ba93 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Friends.cs @@ -3,5 +3,4 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("vstest.console, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] -[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("vstest.console, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs b/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs index 75a4a66e5b..dc1d6d7a2d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs @@ -20,13 +20,14 @@ public static class OutputExtensions /// Output an error message. /// /// Output instance the method is being invoked with. + /// Bool to decide whether Verbose level should be added as prefix or not in log messages. /// Format string for the error message. /// Arguments to format into the format string. - public static void Error(this IOutput output, string format, params object[] args) + public static void Error(this IOutput output, bool appendPrefix, string format, params object[] args) { SetColorForAction(ConsoleColor.Red, () => { - Output(output, OutputLevel.Error, DefaultFormat, format, args); + Output(output, OutputLevel.Error, appendPrefix ? Resources.CommandLineError : DefaultFormat, format, args); }); } @@ -34,13 +35,14 @@ public static void Error(this IOutput output, string format, params object[] arg /// Output a warning message. /// /// Output instance the method is being invoked with. + /// Bool to decide whether Verbose level should be added as prefix or not in log messages. /// Format string for the warning message. /// Arguments to format into the format string. - public static void Warning(this IOutput output, string format, params object[] args) + public static void Warning(this IOutput output, bool appendPrefix, string format, params object[] args) { SetColorForAction(ConsoleColor.Yellow, () => { - Output(output, OutputLevel.Warning, DefaultFormat, format, args); + Output(output, OutputLevel.Warning, appendPrefix ? Resources.CommandLineWarning : DefaultFormat, format, args); }); } @@ -48,25 +50,27 @@ public static void Warning(this IOutput output, string format, params object[] a /// Output a informational message. /// /// Output instance the method is being invoked with. + /// Bool to decide whether Verbose level should be added as prefix or not in log messages. /// Format string for the informational message. /// Arguments to format into the format string. - public static void Information(this IOutput output, string format, params object[] args) + public static void Information(this IOutput output, bool appendPrefix, string format, params object[] args) { - Information(output, Console.ForegroundColor, format, args); + Information(output, appendPrefix, Console.ForegroundColor, format, args); } /// /// Output a informational message. /// /// Output instance the method is being invoked with. - /// Format string for the informational message. + /// Bool to decide whether Verbose level should be added as prefix or not in log messages. /// Color in which text prints. + /// Format string for the informational message. /// Arguments to format into the format string. - public static void Information(this IOutput output, ConsoleColor foregroundColor, string format, params object[] args) + public static void Information(this IOutput output, bool appendPrefix, ConsoleColor foregroundColor, string format, params object[] args) { SetColorForAction(foregroundColor, () => { - Output(output, OutputLevel.Information, DefaultFormat, format, args); + Output(output, OutputLevel.Information, appendPrefix ? Resources.CommandLineInformational : DefaultFormat, format, args); }); } diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs index 3c258469fd..9f843fcbf8 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameLogger.cs @@ -112,7 +112,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) return; } - this.output.Error(Resources.Resources.AbortedTestRun); + this.output.Error(false, Resources.Resources.AbortedTestRun); StringBuilder sb = new StringBuilder(); foreach (var tcn in testCaseNames) @@ -120,7 +120,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) sb.Append(tcn).Append(Environment.NewLine); } - this.output.Error(sb.ToString()); + this.output.Error(false, sb.ToString()); } #endregion @@ -162,4 +162,4 @@ private IEnumerable GetFaultyTestCaseNames(TestRunCompleteEventArgs e) #endregion } -} +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs index 759541fc22..df24d75f1a 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs @@ -405,7 +405,7 @@ internal virtual void PopulateTrxFile(string trxFileName, XmlElement rootElement { var overwriteWarningMsg = string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.TrxLoggerResultsFileOverwriteWarning, trxFileName); - ConsoleOutput.Instance.Warning(overwriteWarningMsg); + ConsoleOutput.Instance.Warning(false, overwriteWarningMsg); EqtTrace.Warning(overwriteWarningMsg); } @@ -414,12 +414,12 @@ internal virtual void PopulateTrxFile(string trxFileName, XmlElement rootElement rootElement.OwnerDocument.Save(fs); } String resultsFileMessage = String.Format(CultureInfo.CurrentCulture, TrxLoggerResources.TrxLoggerResultsFile, trxFileName); - ConsoleOutput.Instance.Information(resultsFileMessage); + ConsoleOutput.Instance.Information(false, resultsFileMessage); EqtTrace.Info(resultsFileMessage); } catch (System.UnauthorizedAccessException fileWriteException) { - ConsoleOutput.Instance.Error(fileWriteException.Message); + ConsoleOutput.Instance.Error(false, fileWriteException.Message); } } diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs index aa54509e23..858c67fe0e 100644 --- a/src/vstest.console/CommandLine/Executor.cs +++ b/src/vstest.console/CommandLine/Executor.cs @@ -182,7 +182,7 @@ private int GetArgumentProcessors(string[] args, out List pr else { // No known processor was found, report an error and continue - this.Output.Error(string.Format(CultureInfo.CurrentCulture, CommandLineResources.NoArgumentProcessorFound, arg)); + this.Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.NoArgumentProcessorFound, arg)); // Add the help processor if (result == 0) @@ -218,7 +218,7 @@ private int GetArgumentProcessors(string[] args, out List pr } catch (CommandLineException e) { - this.Output.Error(e.Message); + this.Output.Error(false, e.Message); result = 1; } } @@ -258,7 +258,7 @@ private int IdentifyDuplicateArguments(IEnumerable argumentP // Update the count so we do not print the error out for this argument multiple times. commandSeenCount[processor.Metadata.Value.CommandName] = ++count; - this.Output.Error(string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateArgumentError, processor.Metadata.Value.CommandName)); + this.Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateArgumentError, processor.Metadata.Value.CommandName)); } } } @@ -305,7 +305,7 @@ private bool ExecuteArgumentProcessor(IArgumentProcessor processor, ref int exit if (ex is CommandLineException || ex is TestPlatformException) { EqtTrace.Error("ExecuteArgumentProcessor: failed to execute argument process: {0}", ex); - this.Output.Error(ex.Message); + this.Output.Error(false, ex.Message); result = ArgumentProcessorResult.Fail; } else @@ -408,7 +408,7 @@ private int ParseResponseFile(string fullPath, out IEnumerable responseF } catch (Exception) { - this.Output.Error(string.Format(CultureInfo.CurrentCulture, CommandLineResources.OpenResponseFileError, fullPath)); + this.Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.OpenResponseFileError, fullPath)); responseFileArguments = new string[0]; result = 1; } diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 522ec14f2b..58a7049083 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -30,6 +30,11 @@ internal class ConsoleLogger : ITestLoggerWithParameters #region Constants private const string TestMessageFormattingPrefix = " "; + /// + /// Bool to decide whether Verbose level should be added as prefix or not in log messages. + /// + internal static bool AppendPrefix; + /// /// Uri used to uniquely identify the console logger. /// @@ -45,6 +50,11 @@ internal class ConsoleLogger : ITestLoggerWithParameters /// public const string VerbosityParam = "verbosity"; + /// + /// Parameter for log message prefix + /// + public const string PrefixParam = "prefix"; + #endregion internal enum Verbosity @@ -66,7 +76,6 @@ internal enum Verbosity private int testsPassed = 0; private int testsFailed = 0; private int testsSkipped = 0; - #endregion #region Constructor @@ -89,7 +98,8 @@ internal ConsoleLogger(IOutput output) #endregion - #region Properties + #region Properties + /// /// Gets instance of IOutput used for sending output. /// @@ -150,6 +160,12 @@ public void Initialize(TestLoggerEvents events, Dictionary param this.verbosityLevel = verbosityLevel; } + var prefixExists = parameters.TryGetValue(ConsoleLogger.PrefixParam, out string prefix); + if (prefixExists) + { + bool.TryParse(prefix, out ConsoleLogger.AppendPrefix); + } + this.Initialize(events, String.Empty); } #endregion @@ -163,19 +179,19 @@ private static void PrintTimeSpan(TimeSpan timeSpan) { if (timeSpan.TotalDays >= 1) { - Output.Information(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalDays, CommandLineResources.Days)); + Output.Information(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalDays, CommandLineResources.Days)); } else if (timeSpan.TotalHours >= 1) { - Output.Information(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalHours, CommandLineResources.Hours)); + Output.Information(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalHours, CommandLineResources.Hours)); } else if (timeSpan.TotalMinutes >= 1) { - Output.Information(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalMinutes, CommandLineResources.Minutes)); + Output.Information(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalMinutes, CommandLineResources.Minutes)); } else { - Output.Information(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalSeconds, CommandLineResources.Seconds)); + Output.Information(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, timeSpan.TotalSeconds, CommandLineResources.Seconds)); } } @@ -224,17 +240,17 @@ private static void DisplayFullInformation(TestResult result) if (!String.IsNullOrEmpty(result.ErrorMessage)) { addAdditionalNewLine = true; - Output.Information(ConsoleColor.Red, CommandLineResources.ErrorMessageBanner); + Output.Information(false, ConsoleColor.Red, CommandLineResources.ErrorMessageBanner); var errorMessage = String.Format(CultureInfo.CurrentCulture, "{0}{1}", TestMessageFormattingPrefix, result.ErrorMessage); - Output.Information(ConsoleColor.Red, errorMessage); + Output.Information(false, ConsoleColor.Red, errorMessage); } if (!String.IsNullOrEmpty(result.ErrorStackTrace)) { addAdditionalNewLine = false; - Output.Information(ConsoleColor.Red, CommandLineResources.StacktraceBanner); + Output.Information(false, ConsoleColor.Red, CommandLineResources.StacktraceBanner); var stackTrace = String.Format(CultureInfo.CurrentCulture, "{0}", result.ErrorStackTrace); - Output.Information(ConsoleColor.Red, stackTrace); + Output.Information(false, ConsoleColor.Red, stackTrace); } var stdOutMessagesCollection = GetTestMessages(result.Messages, TestResultMessage.StandardOutCategory); @@ -245,8 +261,8 @@ private static void DisplayFullInformation(TestResult result) if (!string.IsNullOrEmpty(stdOutMessages)) { - Output.Information(CommandLineResources.StdOutMessagesBanner); - Output.Information(stdOutMessages); + Output.Information(false, CommandLineResources.StdOutMessagesBanner); + Output.Information(false, stdOutMessages); } } @@ -258,8 +274,8 @@ private static void DisplayFullInformation(TestResult result) if (!string.IsNullOrEmpty(stdErrMessages)) { - Output.Information(ConsoleColor.Red, CommandLineResources.StdErrMessagesBanner); - Output.Information(ConsoleColor.Red, stdErrMessages); + Output.Information(false, ConsoleColor.Red, CommandLineResources.StdErrMessagesBanner); + Output.Information(false, ConsoleColor.Red, stdErrMessages); } } @@ -271,8 +287,8 @@ private static void DisplayFullInformation(TestResult result) if (!string.IsNullOrEmpty(dbgTrcMessages)) { - Output.Information(CommandLineResources.DbgTrcMessagesBanner); - Output.Information(dbgTrcMessages); + Output.Information(false, CommandLineResources.DbgTrcMessagesBanner); + Output.Information(false, dbgTrcMessages); } } @@ -284,8 +300,8 @@ private static void DisplayFullInformation(TestResult result) if (!string.IsNullOrEmpty(addnlInfoMessages)) { - Output.Information(CommandLineResources.AddnlInfoMessagesBanner); - Output.Information(addnlInfoMessages); + Output.Information(false, CommandLineResources.AddnlInfoMessagesBanner); + Output.Information(false, addnlInfoMessages); } } @@ -310,14 +326,14 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e) switch (e.Level) { case TestMessageLevel.Informational: - Output.Information(e.Message); + Output.Information(ConsoleLogger.AppendPrefix, e.Message); break; case TestMessageLevel.Warning: - Output.Warning(e.Message); + Output.Warning(ConsoleLogger.AppendPrefix, e.Message); break; case TestMessageLevel.Error: this.testOutcome = TestOutcome.Failed; - Output.Error(e.Message); + Output.Error(ConsoleLogger.AppendPrefix, e.Message); break; default: Debug.Fail("ConsoleLogger.TestMessageHandler: The test message level is unrecognized: {0}", e.Level.ToString()); @@ -346,7 +362,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) { var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator, name); - Output.Warning(output); + Output.Warning(false, output); DisplayFullInformation(e.Result); } } @@ -358,7 +374,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) { var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, name); - Output.Information(ConsoleColor.Red, output); + Output.Information(false, ConsoleColor.Red, output); DisplayFullInformation(e.Result); } } @@ -367,7 +383,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) if (this.verbosityLevel.Equals(Verbosity.Normal)) { var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, name); - Output.Information(output); + Output.Information(false, output); DisplayFullInformation(e.Result); } this.testsPassed++; @@ -378,7 +394,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) { var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator, name); - Output.Information(output); + Output.Information(false, output); DisplayFullInformation(e.Result); } } @@ -395,13 +411,13 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) var runLevelAttachementCount = (e.AttachmentSets == null) ? 0 : e.AttachmentSets.Sum(attachmentSet => attachmentSet.Attachments.Count); if (runLevelAttachementCount > 0) { - Output.Information(CommandLineResources.AttachmentsBanner); + Output.Information(false, CommandLineResources.AttachmentsBanner); foreach (var attachmentSet in e.AttachmentSets) { foreach (var uriDataAttachment in attachmentSet.Attachments) { var attachmentOutput = string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath); - Output.Information(attachmentOutput); + Output.Information(false, attachmentOutput); } } Output.WriteLine(String.Empty, OutputLevel.Information); @@ -421,23 +437,23 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) testCountDetails = string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, testsTotal, testsPassed, testsFailed, testsSkipped); } - Output.Information(testCountDetails); + Output.Information(false, testCountDetails); if (e.IsCanceled) { - Output.Error(CommandLineResources.TestRunCanceled); + Output.Error(false, CommandLineResources.TestRunCanceled); } - else if(e.IsAborted) + else if (e.IsAborted) { - Output.Error(CommandLineResources.TestRunAborted); + Output.Error(false, CommandLineResources.TestRunAborted); } - else if(this.testOutcome == TestOutcome.Failed) + else if (this.testOutcome == TestOutcome.Failed) { - Output.Error(CommandLineResources.TestRunFailed); + Output.Error(false, CommandLineResources.TestRunFailed); } else { - Output.Information(ConsoleColor.Green, CommandLineResources.TestRunSuccessful); + Output.Information(false, ConsoleColor.Green, CommandLineResources.TestRunSuccessful); } if (!e.ElapsedTimeInRunningTests.Equals(TimeSpan.Zero)) diff --git a/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs b/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs index da21d5739a..bd5a6c95b3 100644 --- a/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs @@ -149,7 +149,7 @@ public void Initialize(string argument) if (!EqtTrace.InitializeVerboseTrace(argument)) { if (!string.IsNullOrEmpty(EqtTrace.ErrorOnInitialization)) - ConsoleOutput.Instance.Warning(EqtTrace.ErrorOnInitialization); + ConsoleOutput.Instance.Warning(false, EqtTrace.ErrorOnInitialization); } } diff --git a/src/vstest.console/Processors/FrameworkArgumentProcessor.cs b/src/vstest.console/Processors/FrameworkArgumentProcessor.cs index 77850ce59d..447b53e85c 100644 --- a/src/vstest.console/Processors/FrameworkArgumentProcessor.cs +++ b/src/vstest.console/Processors/FrameworkArgumentProcessor.cs @@ -151,6 +151,7 @@ public void Initialize(string argument) // Legacy testsettings file support only default target framework. IOutput output = ConsoleOutput.Instance; output.Warning( + false, CommandLineResources.TestSettingsFrameworkMismatch, this.commandLineOptions.TargetFrameworkVersion.ToString(), Framework.DefaultFramework.ToString()); diff --git a/src/vstest.console/Processors/HelpArgumentProcessor.cs b/src/vstest.console/Processors/HelpArgumentProcessor.cs index 0f8d55e20d..fe0f122984 100644 --- a/src/vstest.console/Processors/HelpArgumentProcessor.cs +++ b/src/vstest.console/Processors/HelpArgumentProcessor.cs @@ -183,7 +183,7 @@ private string LookupHelpDescription(IArgumentProcessor argumentProcessor) } catch (Exception e) { - Output.Warning(e.Message); + Output.Warning(false, e.Message); } } diff --git a/src/vstest.console/Processors/ListTestsArgumentProcessor.cs b/src/vstest.console/Processors/ListTestsArgumentProcessor.cs index cb89901165..957fa39c5b 100644 --- a/src/vstest.console/Processors/ListTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/ListTestsArgumentProcessor.cs @@ -210,7 +210,7 @@ public ArgumentProcessorResult Execute() this.output.WriteLine(CommandLineResources.ListTestsHeaderMessage, OutputLevel.Information); if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { - this.output.Information(CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); + this.output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); } var runSettings = this.runSettingsManager.ActiveRunSettings.SettingsXml; diff --git a/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs b/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs index 817778cc9e..7d11795940 100644 --- a/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs @@ -228,7 +228,7 @@ private bool DiscoverTestsAndSelectSpecified(IEnumerable sources) this.output.WriteLine(CommandLineResources.StartingDiscovery, OutputLevel.Information); if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { - this.output.Information(CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); + this.output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); } return this.testRequestManager.DiscoverTests( @@ -247,7 +247,7 @@ private bool ExecuteSelectedTests() { string missingFilters = string.Join(", ", this.undiscoveredFilters); string warningMessage = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SomeTestsUnavailableAfterFiltering, this.discoveredTestCount, missingFilters); - this.output.Warning(warningMessage); + this.output.Warning(false, warningMessage); } // for command line keep alive is always false. @@ -278,7 +278,7 @@ private bool ExecuteSelectedTests() } } - this.output.Warning(warningMessage); + this.output.Warning(false, warningMessage); } return result; diff --git a/src/vstest.console/Processors/RunTestsArgumentProcessor.cs b/src/vstest.console/Processors/RunTestsArgumentProcessor.cs index 237eea18a1..94ac969b07 100644 --- a/src/vstest.console/Processors/RunTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/RunTestsArgumentProcessor.cs @@ -165,7 +165,7 @@ public ArgumentProcessorResult Execute() this.output.WriteLine(CommandLineResources.StartingExecution, OutputLevel.Information); if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { - this.output.Information(CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); + this.output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); } var success = true; diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Output/OutputExtensionsTests.cs b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Output/OutputExtensionsTests.cs index b87a50f887..9f584af427 100644 --- a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Output/OutputExtensionsTests.cs +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Output/OutputExtensionsTests.cs @@ -45,10 +45,17 @@ public void CleanUp() [TestMethod] public void OutputErrorForSimpleMessageShouldOutputTheMessageString() { - this.mockOutput.Object.Error("HelloError", null); + this.mockOutput.Object.Error(false, "HelloError", null); this.mockOutput.Verify(o => o.WriteLine("HelloError", OutputLevel.Error), Times.Once()); } + [TestMethod] + public void OutputErrorForSimpleMessageShouldOutputTheMessageStringWithPrefixIfSet() + { + this.mockOutput.Object.Error(true, "HelloError", null); + this.mockOutput.Verify(o => o.WriteLine("Error: HelloError", OutputLevel.Error), Times.Once()); + } + [TestMethod] public void OutputErrorForSimpleMessageShouldSetConsoleColorToRed() { @@ -57,21 +64,21 @@ public void OutputErrorForSimpleMessageShouldSetConsoleColorToRed() return; } - this.mockOutput.Object.Error("HelloError", null); + this.mockOutput.Object.Error(false, "HelloError", null); Assert.IsTrue(this.color == ConsoleColor.Red, "Console color not set."); } [TestMethod] public void OutputErrorForMessageWithParamsShouldOutputFormattedMessage() { - this.mockOutput.Object.Error("HelloError {0} {1}", "Foo", "Bar"); + this.mockOutput.Object.Error(false, "HelloError {0} {1}", "Foo", "Bar"); this.mockOutput.Verify(o => o.WriteLine("HelloError Foo Bar", OutputLevel.Error), Times.Once()); } [TestMethod] public void OutputWarningForSimpleMessageShouldOutputTheMessageString() { - this.mockOutput.Object.Warning("HelloWarning", null); + this.mockOutput.Object.Warning(false, "HelloWarning", null); this.mockOutput.Verify(o => o.WriteLine("HelloWarning", OutputLevel.Warning), Times.Once()); } @@ -83,21 +90,21 @@ public void OutputWarningForSimpleMessageShouldSetConsoleColorToYellow() return; } - this.mockOutput.Object.Warning("HelloWarning", null); + this.mockOutput.Object.Warning(false, "HelloWarning", null); Assert.IsTrue(this.color == ConsoleColor.Yellow); } [TestMethod] public void OutputWarningForMessageWithParamsShouldOutputFormattedMessage() { - this.mockOutput.Object.Warning("HelloWarning {0} {1}", "Foo", "Bar"); + this.mockOutput.Object.Warning(false, "HelloWarning {0} {1}", "Foo", "Bar"); this.mockOutput.Verify(o => o.WriteLine("HelloWarning Foo Bar", OutputLevel.Warning), Times.Once()); } [TestMethod] public void OutputInformationForSimpleMessageShouldOutputTheMessageString() { - this.mockOutput.Object.Information(ConsoleColor.Green, "HelloInformation", null); + this.mockOutput.Object.Information(false, ConsoleColor.Green, "HelloInformation", null); this.mockOutput.Verify(o => o.WriteLine("HelloInformation", OutputLevel.Information), Times.Once()); } @@ -109,14 +116,14 @@ public void OutputInformationForSimpleMessageShouldSetConsoleColorToGivenColor() return; } - this.mockOutput.Object.Information(ConsoleColor.Green, "HelloInformation", null); + this.mockOutput.Object.Information(false, ConsoleColor.Green, "HelloInformation", null); Assert.IsTrue(this.color == ConsoleColor.Green); } [TestMethod] public void OutputInformationForMessageWithParamsShouldOutputFormattedMessage() { - this.mockOutput.Object.Information("HelloInformation {0} {1}", "Foo", "Bar"); + this.mockOutput.Object.Information(false, "HelloInformation {0} {1}", "Foo", "Bar"); this.mockOutput.Verify(o => o.WriteLine("HelloInformation Foo Bar", OutputLevel.Information), Times.Once()); } @@ -134,7 +141,7 @@ public void OutputInformationShouldNotChangeConsoleOutputColor() color2 = Console.ForegroundColor; }); - this.mockOutput.Object.Information("HelloInformation {0} {1}", "Foo", "Bar"); + this.mockOutput.Object.Information(false, "HelloInformation {0} {1}", "Foo", "Bar"); this.mockOutput.Verify(o => o.WriteLine("HelloInformation Foo Bar", OutputLevel.Information), Times.Once()); Assert.IsTrue(color1 == color2); } diff --git a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs index 90cd22dff6..eb6aed39b3 100644 --- a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs +++ b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs @@ -109,6 +109,21 @@ public void InitializeWithParametersShouldDefaultToMinimalVerbosityLevelForInval Assert.AreEqual(ConsoleLogger.Verbosity.Minimal, this.consoleLogger.VerbosityLevel); } + [TestMethod] + public void InitializeWithParametersShouldSetPrefixValue() + { + var parameters = new Dictionary(); + + Assert.IsFalse(ConsoleLogger.AppendPrefix); + + parameters.Add("prefix", "true"); + this.consoleLogger.Initialize(new Mock().Object, parameters); + + Assert.IsTrue(ConsoleLogger.AppendPrefix); + + ConsoleLogger.AppendPrefix = false; + } + [TestMethod] public void TestMessageHandlerShouldThrowExceptionIfEventArgsIsNull() { @@ -427,7 +442,7 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsPass() this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, 1, 1, 0, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunSuccessful, OutputLevel.Information), Times.Once()); } - + [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsFail() {