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

for #2120 DisableProgress when environment CI true #2125

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
23 changes: 17 additions & 6 deletions src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ internal class ConsoleLogger : ITestLoggerWithParameters
/// </summary>
public const string NoProgressParam = "noprogress";

internal const string ContinuousIntegrationIndicator = "CI";

#endregion

internal enum Verbosity
Expand Down Expand Up @@ -136,7 +138,7 @@ internal ConsoleLogger(IOutput output, IProgressIndicator progressIndicator)

#endregion

#region Properties
#region Properties

/// <summary>
/// Gets instance of IOutput used for sending output.
Expand Down Expand Up @@ -181,7 +183,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;
Expand Down Expand Up @@ -219,10 +221,19 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
bool.TryParse(prefix, out AppendPrefix);
}

var ciEnvironment = Environment.GetEnvironmentVariable(ConsoleLogger.ContinuousIntegrationIndicator);
if (bool.TryParse(ciEnvironment, out var ci) && ci)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently only checking if true or false case insensitive. should additional values be accepted? 1/0?

{
DisableProgress = true;
}

var noprogressExists = parameters.TryGetValue(ConsoleLogger.NoProgressParam, out string noprogress);
if (noprogressExists)
{
bool.TryParse(noprogress, out DisableProgress);
if (bool.TryParse(noprogress, out var disableProgress))
{
DisableProgress = disableProgress;
}
}

Initialize(events, String.Empty);
Expand All @@ -232,7 +243,7 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
#region Private Methods

/// <summary>
/// Prints the timespan onto console.
/// Prints the timespan onto console.
/// </summary>
private static void PrintTimeSpan(TimeSpan timeSpan)
{
Expand Down Expand Up @@ -468,7 +479,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e)
ValidateArg.NotNull<object>(sender, "sender");
ValidateArg.NotNull<TestResultEventArgs>(e, "e");

// Update the test count statistics based on the result of the test.
// Update the test count statistics based on the result of the test.
this.testsTotal++;

var testDisplayName = e.Result.DisplayName;
Expand Down Expand Up @@ -517,7 +528,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e)
{
break;
}

// Pause the progress indicator before displaying test result information
this.progressIndicator?.Pause();

Expand Down
35 changes: 33 additions & 2 deletions test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,37 @@ public void InitializeWithParametersShouldSetNoProgress()
ConsoleLogger.DisableProgress = false;
}

[TestMethod]
public void InitializeWithParametersShouldSetDisableProgressWhenCI()
{
Environment.SetEnvironmentVariable("CI", "true");

var parameters = new Dictionary<string, string>();
parameters.Add("fakeparam", "false");

this.consoleLogger.Initialize(new Mock<TestLoggerEvents>().Object, parameters);

Assert.IsTrue(ConsoleLogger.DisableProgress);

ConsoleLogger.DisableProgress = false;
davidruhmann marked this conversation as resolved.
Show resolved Hide resolved
}

[TestMethod]
public void InitializeWithParametersShouldSetDisableProgressFalseOverrideCI()
{
Environment.SetEnvironmentVariable("CI", "true");

var parameters = new Dictionary<string, string>();
parameters.Add("noprogress", "false");

this.consoleLogger.Initialize(new Mock<TestLoggerEvents>().Object, parameters);

Assert.IsFalse(ConsoleLogger.DisableProgress);

ConsoleLogger.DisableProgress = false;
}


[TestMethod]
public void TestMessageHandlerShouldThrowExceptionIfEventArgsIsNull()
{
Expand Down Expand Up @@ -977,7 +1008,7 @@ public void DisplayFullInformationShouldWriteStdMessageWithNewLine()
this.consoleLogger.Initialize(loggerEvents, parameters);

var testresults = this.GetTestResultObject(TestOutcome.Passed);
testresults[0].Messages.Add(new TestResultMessage (TestResultMessage.StandardOutCategory, "Hello"));
testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, "Hello"));

foreach (var testResult in testresults)
{
Expand Down Expand Up @@ -1096,7 +1127,7 @@ private void Setup()
return testresultList;
}




private List<ObjectModel.TestResult> GetTestResultObject(TestOutcome outcome)
Expand Down