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

Add ResultsDirectory arg to cli #322

Merged
merged 12 commits into from
Jan 9, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ private static bool TryGetFrameworkXml(XPathNavigator runSettingsNavigator, out

Func<string, bool> validator = (string xml) =>
{
if (Framework.FromString(xml) != null)
{
// Allow TargetFrameworkMoniker values like .NETFramework,Version=v4.5, ".NETCoreApp,Version=v1.0
return true;
}

var value = (FrameworkVersion)Enum.Parse(typeof(FrameworkVersion), xml, true);

if (!Enum.IsDefined(typeof(FrameworkVersion), value) || value == FrameworkVersion.None)
Expand Down
12 changes: 11 additions & 1 deletion src/vstest.console/CommandLine/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,22 @@ internal Framework TargetFrameworkVersion
this.FrameworkVersionSpecified = true;
}
}

/// <summary>
/// Gets a value indicating whether /Framework has been specified on command line or not.
/// </summary>
internal bool FrameworkVersionSpecified { get; private set; }

/// <summary>
/// Gets or sets the results directory for test run.
/// </summary>
internal string ResultsDirectory { get; set; }

/// <summary>
/// Gets or sets the /setting switch value. i.e path to settings file.
/// </summary>
internal string SettingsFile { get; set; }

#endregion

#region Public Methods
Expand Down
5 changes: 5 additions & 0 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common;

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

Expand Down Expand Up @@ -190,6 +192,9 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
var processorsToAlwaysExecute = processorFactory.GetArgumentProcessorsToAlwaysExecute();
processors.AddRange(processorsToAlwaysExecute);

// Initialize Runsettings with defaults
RunSettingsUtilities.AddDefaultRunSettings(RunSettingsManager.Instance);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the defaults be initialized on the first query to ActiveRunSettings?

Copy link
Contributor Author

@smadala smadala Jan 8, 2017

Choose a reason for hiding this comment

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

Currenlty we can't assign defaults on first query, because it is public type in different assembly.


// Ensure we have an action argument.
this.EnsureActionArgumentIsPresent(processors, processorFactory);

Expand Down
64 changes: 4 additions & 60 deletions src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;

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

Expand Down Expand Up @@ -114,41 +115,13 @@ public void Initialize(string[] arguments)
// Load up the run settings and set it as the active run settings.
try
{
var doc = new XmlDocument();

if (this.runSettingsManager.ActiveRunSettings != null && !string.IsNullOrEmpty(this.runSettingsManager.ActiveRunSettings.SettingsXml))
{
var settingsXml = this.runSettingsManager.ActiveRunSettings.SettingsXml;

#if net46
using (var reader = XmlReader.Create(new StringReader(settingsXml), new XmlReaderSettings() { XmlResolver = null, CloseInput = true, DtdProcessing = DtdProcessing.Prohibit }))
{
#else
using (var reader = XmlReader.Create(new StringReader(settingsXml), new XmlReaderSettings() { CloseInput = true, DtdProcessing = DtdProcessing.Prohibit }))
{
#endif
doc.Load(reader);
}
}
else
{
#if net46
doc = (XmlDocument)XmlRunSettingsUtilities.CreateDefaultRunSettings();
#else
using (var reader = XmlReader.Create(new StringReader(XmlRunSettingsUtilities.CreateDefaultRunSettings().CreateNavigator().OuterXml), new XmlReaderSettings() { CloseInput = true, DtdProcessing = DtdProcessing.Prohibit }))
{
doc.Load(reader);
}
#endif
}
var doc = RunSettingsUtilities.GetRunSettingXmlDocument(this.runSettingsManager);

// Append / Override run settings supplied in CLI
CreateOrOverwriteRunSettings(doc, arguments);

// Set Active Run Settings.
var runSettings = new RunSettings();
runSettings.LoadSettingsXml(doc.OuterXml);
this.runSettingsManager.SetActiveRunSettings(runSettings);
RunSettingsUtilities.UpdateRunSettings(this.runSettingsManager, doc.OuterXml);
}
catch (XPathException exception)
{
Expand Down Expand Up @@ -186,37 +159,8 @@ private void CreateOrOverwriteRunSettings(XmlDocument xmlDoc, string[] args)
continue;
}

// Check if the key exists.
var xPath = key.Replace('.', '/');
var node = xmlDoc.SelectSingleNode(string.Format("//RunSettings/{0}", xPath));

if (node == null)
{
node = CreateNode(xmlDoc, key.Split('.'));
}

node.InnerText = value;
}
}

private XmlNode CreateNode(XmlDocument doc, string[] xPath)
{
XmlNode node = null;
XmlNode parent = doc.DocumentElement;

for (int i = 0; i < xPath.Length; i++)
{
node = parent.SelectSingleNode(xPath[i]);

if (node == null)
{
node = parent.AppendChild(doc.CreateElement(xPath[i]));
}

parent = node;
RunSettingsUtilities.UpdateRunSettingsXmlDocument(xmlDoc, key, value);
}

return node;
}
}
}
34 changes: 27 additions & 7 deletions src/vstest.console/Processors/FrameworkArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors
using System;
using System.Diagnostics.Contracts;
using System.Globalization;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Utilities;

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

Expand Down Expand Up @@ -54,7 +59,7 @@ public Lazy<IArgumentExecutor> Executor
{
if (this.executor == null)
{
this.executor = new Lazy<IArgumentExecutor>(() => new FrameworkArgumentExecutor(CommandLineOptions.Instance));
this.executor = new Lazy<IArgumentExecutor>(() => new FrameworkArgumentExecutor(CommandLineOptions.Instance, RunSettingsManager.Instance));
}

return this.executor;
Expand Down Expand Up @@ -94,21 +99,27 @@ internal class FrameworkArgumentExecutor : IArgumentExecutor
/// </summary>
private CommandLineOptions commandLineOptions;

private IRunSettingsProvider runSettingsManager;

public const string RunSettingsPath = "RunConfiguration.TargetFrameworkVersion";

#endregion

#region Constructor

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="options">
/// The options.
/// </param>
public FrameworkArgumentExecutor(CommandLineOptions options)
/// <param name="options"> The options. </param>
/// <param name="runSettingsManager"> The runsettings manager. </param>
public FrameworkArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager)
{
Contract.Requires(options != null);
Contract.Requires(runSettingsManager != null);
this.commandLineOptions = options;
this.runSettingsManager = runSettingsManager;
}

#endregion

#region IArgumentExecutor
Expand All @@ -126,16 +137,25 @@ public void Initialize(string argument)

var validFramework = Framework.FromString(argument);
if (validFramework == null)
{
{
throw new CommandLineException(
string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidFrameworkVersion, argument));
}
commandLineOptions.TargetFrameworkVersion = validFramework;
this.commandLineOptions.TargetFrameworkVersion = validFramework;
RunSettingsUtilities.UpdateRunSettingsNode(this.runSettingsManager, FrameworkArgumentExecutor.RunSettingsPath, validFramework.ToString());

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("Using .Net Framework version:{0}", commandLineOptions.TargetFrameworkVersion);
}

if (this.commandLineOptions.TargetFrameworkVersion != Framework.DefaultFramework
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get more context on why this warning is interesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added Comment.

&& !string.IsNullOrWhiteSpace(this.commandLineOptions.SettingsFile)
&& MSTestSettingsUtilities.IsLegacyTestSettingsFile(this.commandLineOptions.SettingsFile))
{
IOutput output = ConsoleOutput.Instance;
output.Warning(CommandLineResources.TestSettingsFrameworkMismatch, this.commandLineOptions.TargetFrameworkVersion.ToString(), Framework.DefaultFramework.ToString());
}
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/vstest.console/Processors/ListTestsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public ArgumentProcessorResult Execute()
{
Contract.Assert(this.output != null);
Contract.Assert(this.commandLineOptions != null);
Contract.Assert(!string.IsNullOrWhiteSpace(this.runSettingsManager?.ActiveRunSettings?.SettingsXml));

if (this.commandLineOptions.Sources.Count() <= 0)
{
Expand All @@ -207,7 +208,7 @@ public ArgumentProcessorResult Execute()

this.output.WriteLine(CommandLineResources.ListTestsHeaderMessage, OutputLevel.Information);

var runSettings = RunSettingsUtilities.GetRunSettings(this.runSettingsManager, this.commandLineOptions);
var runSettings = this.runSettingsManager.ActiveRunSettings.SettingsXml;

var success = this.testRequestManager.DiscoverTests(
new DiscoveryRequestPayload() { Sources = this.commandLineOptions.Sources, RunSettings = runSettings },
Expand Down
21 changes: 16 additions & 5 deletions src/vstest.console/Processors/ParallelArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors
using System.Diagnostics.Contracts;
using System.Globalization;

using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;

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

/// <summary>
Expand Down Expand Up @@ -49,7 +53,7 @@ public Lazy<IArgumentExecutor> Executor
{
if (this.executor == null)
{
this.executor = new Lazy<IArgumentExecutor>(() => new ParallelArgumentExecutor(CommandLineOptions.Instance));
this.executor = new Lazy<IArgumentExecutor>(() => new ParallelArgumentExecutor(CommandLineOptions.Instance, RunSettingsManager.Instance));
}

return this.executor;
Expand Down Expand Up @@ -89,21 +93,27 @@ internal class ParallelArgumentExecutor : IArgumentExecutor
/// </summary>
private CommandLineOptions commandLineOptions;

private IRunSettingsProvider runSettingsManager;

public const string RunSettingsPath = "RunConfiguration.MaxCpuCount";

#endregion

#region Constructor

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="options">
/// The options.
/// </param>
public ParallelArgumentExecutor(CommandLineOptions options)
/// <param name="options"> The options. </param>
/// <param name="runSettingsManager"> The runsettings manager. </param>
public ParallelArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager)
{
Contract.Requires(options != null);
Contract.Requires(runSettingsManager != null);
this.commandLineOptions = options;
this.runSettingsManager = runSettingsManager;
}

#endregion

#region IArgumentExecutor
Expand All @@ -122,6 +132,7 @@ public void Initialize(string argument)
}

commandLineOptions.Parallel = true;
RunSettingsUtilities.UpdateRunSettingsNode(this.runSettingsManager, ParallelArgumentExecutor.RunSettingsPath, "0");
}

/// <summary>
Expand Down
21 changes: 16 additions & 5 deletions src/vstest.console/Processors/PlatformArgumentProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;

namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors
{
using System;
Expand Down Expand Up @@ -54,7 +58,7 @@ public Lazy<IArgumentExecutor> Executor
{
if (this.executor == null)
{
this.executor = new Lazy<IArgumentExecutor>(() => new PlatformArgumentExecutor(CommandLineOptions.Instance));
this.executor = new Lazy<IArgumentExecutor>(() => new PlatformArgumentExecutor(CommandLineOptions.Instance, RunSettingsManager.Instance));
}

return this.executor;
Expand Down Expand Up @@ -94,21 +98,27 @@ internal class PlatformArgumentExecutor : IArgumentExecutor
/// </summary>
private CommandLineOptions commandLineOptions;

private IRunSettingsProvider runSettingsManager;

public const string RunSettingsPath = "RunConfiguration.TargetPlatform";

#endregion

#region Constructor

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="options">
/// The options.
/// </param>
public PlatformArgumentExecutor(CommandLineOptions options)
/// <param name="options"> The options. </param>
/// <param name="runSettingsManager"> The runsettings manager. </param>
public PlatformArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager)
{
Contract.Requires(options != null);
Contract.Requires(runSettingsManager != null);
this.commandLineOptions = options;
this.runSettingsManager = runSettingsManager;
}

#endregion

#region IArgumentExecutor
Expand All @@ -134,6 +144,7 @@ public void Initialize(string argument)
if (validPlatform)
{
this.commandLineOptions.TargetArchitecture = platform;
RunSettingsUtilities.UpdateRunSettingsNode(this.runSettingsManager, PlatformArgumentExecutor.RunSettingsPath, platform.ToString());
}
else
{
Expand Down
Loading