Skip to content

Commit

Permalink
Add noprogress parameter to disable progress indicator (#2117)
Browse files Browse the repository at this point in the history
* Add noprogress parameter to disable progress indicator
* Add test for setting noprogress parameter
  • Loading branch information
zcsizmadia authored and singhsarab committed Aug 8, 2019
1 parent 2d36ed9 commit 03cb97c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ internal class ConsoleLogger : ITestLoggerWithParameters
/// </summary>
internal static bool AppendPrefix;

/// <summary>
/// Bool to decide whether progress indicator should be disabled.
/// </summary>
internal static bool DisableProgress;

/// <summary>
/// Uri used to uniquely identify the console logger.
/// </summary>
Expand All @@ -75,6 +80,11 @@ internal class ConsoleLogger : ITestLoggerWithParameters
/// </summary>
public const string PrefixParam = "prefix";

/// <summary>
/// Parameter for disabling progress
/// </summary>
public const string NoProgressParam = "noprogress";

#endregion

internal enum Verbosity
Expand Down Expand Up @@ -166,7 +176,7 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory)
ConsoleLogger.Output = ConsoleOutput.Instance;
}

if (this.progressIndicator == null && !Console.IsOutputRedirected)
if (this.progressIndicator == null && !Console.IsOutputRedirected && !DisableProgress)
{
// Progress indicator needs to be displayed only for cli experience.
this.progressIndicator = new ProgressIndicator(Output, new ConsoleHelper());
Expand Down Expand Up @@ -209,6 +219,12 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
bool.TryParse(prefix, out AppendPrefix);
}

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

Initialize(events, String.Empty);
}
#endregion
Expand Down
15 changes: 15 additions & 0 deletions test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ public void InitializeWithParametersShouldSetPrefixValue()
ConsoleLogger.AppendPrefix = false;
}

[TestMethod]
public void InitializeWithParametersShouldSetNoProgress()
{
var parameters = new Dictionary<string, string>();

Assert.IsFalse(ConsoleLogger.DisableProgress);

parameters.Add("noprogress", "true");
this.consoleLogger.Initialize(new Mock<TestLoggerEvents>().Object, parameters);

Assert.IsTrue(ConsoleLogger.DisableProgress);

ConsoleLogger.DisableProgress = false;
}

[TestMethod]
public void TestMessageHandlerShouldThrowExceptionIfEventArgsIsNull()
{
Expand Down

0 comments on commit 03cb97c

Please sign in to comment.