Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunAttachmentsProcessing;

Expand All @@ -23,6 +24,13 @@ internal class DataCollectorAttachmentsProcessorsFactory : IDataCollectorAttachm
private const string CoverageFriendlyName = "Code Coverage";
private static readonly ConcurrentDictionary<string, DataCollectorExtensionManager> DataCollectorExtensionManagerCache = new();

private readonly IRunSettingsHelper _runSettingsHelper;

public DataCollectorAttachmentsProcessorsFactory(IRunSettingsHelper? runSettingsHelper = null)
{
_runSettingsHelper = runSettingsHelper ?? RunSettingsHelper.Instance;
}

public DataCollectorAttachmentProcessor[] Create(InvokedDataCollector[]? invokedDataCollectors, IMessageLogger? logger)
{
IDictionary<string, Tuple<string, IDataCollectorAttachmentProcessor>> datacollectorsAttachmentsProcessors = new Dictionary<string, Tuple<string, IDataCollectorAttachmentProcessor>>();
Expand Down Expand Up @@ -52,7 +60,7 @@ public DataCollectorAttachmentProcessor[] Create(InvokedDataCollector[]? invoked
#endif

// If we're in design mode we need to load the extension inside a different AppDomain to avoid to lock extension file containers.
if (canUseAppDomains && RunSettingsHelper.Instance.IsDesignMode)
if (canUseAppDomains && _runSettingsHelper.IsDesignMode)
{
#if NETFRAMEWORK
try
Expand Down
13 changes: 11 additions & 2 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using Abstraction::Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;

using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

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

Expand Down Expand Up @@ -61,6 +63,7 @@ internal class Executor
private readonly IProcessHelper _processHelper;
private readonly IEnvironment _environment;
private readonly IRunSettingsProvider _runSettingsProvider;
private readonly IRunSettingsHelper _runSettingsHelper;
private bool _showHelp;

/// <summary>
Expand Down Expand Up @@ -91,11 +94,16 @@ internal class Executor
}

internal Executor(IOutput output, ITestPlatformEventSource testPlatformEventSource, IProcessHelper processHelper, IEnvironment environment)
: this(output, testPlatformEventSource, processHelper, environment, RunSettingsManager.Instance)
: this(output, testPlatformEventSource, processHelper, environment, RunSettingsManager.Instance, RunSettingsHelper.Instance)
{
}

internal Executor(IOutput output, ITestPlatformEventSource testPlatformEventSource, IProcessHelper processHelper, IEnvironment environment, IRunSettingsProvider runSettingsProvider)
: this(output, testPlatformEventSource, processHelper, environment, runSettingsProvider, RunSettingsHelper.Instance)
{
}

internal Executor(IOutput output, ITestPlatformEventSource testPlatformEventSource, IProcessHelper processHelper, IEnvironment environment, IRunSettingsProvider runSettingsProvider, IRunSettingsHelper runSettingsHelper)
{
DebuggerBreakpoint.AttachVisualStudioDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_DEBUG_ATTACHVS);
DebuggerBreakpoint.WaitForNativeDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_NATIVE_DEBUG);
Expand All @@ -107,6 +115,7 @@ internal Executor(IOutput output, ITestPlatformEventSource testPlatformEventSour
_processHelper = processHelper;
_environment = environment;
_runSettingsProvider = runSettingsProvider;
_runSettingsHelper = runSettingsHelper;
}

/// <summary>
Expand Down Expand Up @@ -228,7 +237,7 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
{
processors = new List<IArgumentProcessor>();
int result = 0;
var processorFactory = ArgumentProcessorFactory.Create(runSettingsProvider: _runSettingsProvider);
var processorFactory = ArgumentProcessorFactory.Create(runSettingsProvider: _runSettingsProvider, runSettingsHelper: _runSettingsHelper);
for (var index = 0; index < args.Length; index++)
{
var arg = args[index];
Expand Down
14 changes: 9 additions & 5 deletions src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

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

Expand All @@ -30,10 +30,12 @@ internal class CliRunSettingsArgumentProcessor : IArgumentProcessor
private Lazy<IArgumentProcessorCapabilities>? _metadata;
private Lazy<IArgumentExecutor>? _executor;
private readonly IRunSettingsProvider _runSettingsProvider;
private readonly IRunSettingsHelper _runSettingsHelper;

public CliRunSettingsArgumentProcessor(IRunSettingsProvider runSettingsProvider)
public CliRunSettingsArgumentProcessor(IRunSettingsProvider runSettingsProvider, IRunSettingsHelper runSettingsHelper)
{
_runSettingsProvider = runSettingsProvider;
_runSettingsHelper = runSettingsHelper;
}

/// <summary>
Expand All @@ -49,7 +51,7 @@ public Lazy<IArgumentProcessorCapabilities> Metadata
public Lazy<IArgumentExecutor>? Executor
{
get => _executor ??= new Lazy<IArgumentExecutor>(() =>
new CliRunSettingsArgumentExecutor(_runSettingsProvider, CommandLineOptions.Instance));
new CliRunSettingsArgumentExecutor(_runSettingsProvider, CommandLineOptions.Instance, _runSettingsHelper));

set => _executor = value;
}
Expand All @@ -74,11 +76,13 @@ internal class CliRunSettingsArgumentExecutor : IArgumentsExecutor
{
private readonly IRunSettingsProvider _runSettingsManager;
private readonly CommandLineOptions _commandLineOptions;
private readonly IRunSettingsHelper _runSettingsHelper;

internal CliRunSettingsArgumentExecutor(IRunSettingsProvider runSettingsManager, CommandLineOptions commandLineOptions)
internal CliRunSettingsArgumentExecutor(IRunSettingsProvider runSettingsManager, CommandLineOptions commandLineOptions, IRunSettingsHelper runSettingsHelper)
{
_runSettingsManager = runSettingsManager;
_commandLineOptions = commandLineOptions;
_runSettingsHelper = runSettingsHelper;
}

public void Initialize(string? argument)
Expand Down Expand Up @@ -239,7 +243,7 @@ private void UpdateFrameworkAndPlatform(string key, string value)
bool success = Enum.TryParse<Architecture>(value, true, out var architecture);
if (success)
{
RunSettingsHelper.Instance.IsDefaultTargetArchitecture = false;
_runSettingsHelper.IsDefaultTargetArchitecture = false;
_commandLineOptions.TargetArchitecture = architecture;
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/vstest.console/Processors/PlatformArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

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

Expand All @@ -29,10 +29,12 @@ internal class PlatformArgumentProcessor : IArgumentProcessor
private Lazy<IArgumentProcessorCapabilities>? _metadata;
private Lazy<IArgumentExecutor>? _executor;
private readonly IRunSettingsProvider _runSettingsProvider;
private readonly IRunSettingsHelper _runSettingsHelper;

public PlatformArgumentProcessor(IRunSettingsProvider runSettingsProvider)
public PlatformArgumentProcessor(IRunSettingsProvider runSettingsProvider, IRunSettingsHelper runSettingsHelper)
{
_runSettingsProvider = runSettingsProvider;
_runSettingsHelper = runSettingsHelper;
}

/// <summary>
Expand All @@ -48,7 +50,7 @@ public Lazy<IArgumentProcessorCapabilities> Metadata
public Lazy<IArgumentExecutor>? Executor
{
get => _executor ??= new Lazy<IArgumentExecutor>(() =>
new PlatformArgumentExecutor(CommandLineOptions.Instance, _runSettingsProvider));
new PlatformArgumentExecutor(CommandLineOptions.Instance, _runSettingsProvider, _runSettingsHelper));

set => _executor = value;
}
Expand Down Expand Up @@ -80,19 +82,24 @@ internal class PlatformArgumentExecutor : IArgumentExecutor

private readonly IRunSettingsProvider _runSettingsManager;

private readonly IRunSettingsHelper _runSettingsHelper;

public const string RunSettingsPath = "RunConfiguration.TargetPlatform";

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="options"> The options. </param>
/// <param name="runSettingsManager"> The runsettings manager. </param>
public PlatformArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager)
/// <param name="runSettingsHelper"> The runsettings helper. </param>
public PlatformArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager, IRunSettingsHelper runSettingsHelper)
{
ValidateArg.NotNull(options, nameof(options));
ValidateArg.NotNull(runSettingsManager, nameof(runSettingsManager));
ValidateArg.NotNull(runSettingsHelper, nameof(runSettingsHelper));
_commandLineOptions = options;
_runSettingsManager = runSettingsManager;
_runSettingsHelper = runSettingsHelper;
}


Expand Down Expand Up @@ -125,7 +132,7 @@ public void Initialize(string? argument)

if (validPlatform)
{
RunSettingsHelper.Instance.IsDefaultTargetArchitecture = false;
_runSettingsHelper.IsDefaultTargetArchitecture = false;
_commandLineOptions.TargetArchitecture = platform;
_runSettingsManager.UpdateRunSettingsNode(RunSettingsPath, platform.ToString());
}
Expand Down
30 changes: 21 additions & 9 deletions src/vstest.console/Processors/PortArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Abstraction::Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Abstraction::Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

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

Expand All @@ -30,6 +30,12 @@ internal class PortArgumentProcessor : IArgumentProcessor

private Lazy<IArgumentProcessorCapabilities>? _metadata;
private Lazy<IArgumentExecutor>? _executor;
private readonly IRunSettingsHelper _runSettingsHelper;

public PortArgumentProcessor(IRunSettingsHelper runSettingsHelper)
{
_runSettingsHelper = runSettingsHelper;
}
Comment on lines +35 to +38

/// <summary>
/// Gets the metadata.
Expand All @@ -43,7 +49,7 @@ public Lazy<IArgumentProcessorCapabilities> Metadata
public Lazy<IArgumentExecutor>? Executor
{
get => _executor ??= new Lazy<IArgumentExecutor>(() =>
new PortArgumentExecutor(CommandLineOptions.Instance, TestRequestManager.Instance));
new PortArgumentExecutor(CommandLineOptions.Instance, TestRequestManager.Instance, _runSettingsHelper));

set => _executor = value;
}
Expand Down Expand Up @@ -99,39 +105,45 @@ internal class PortArgumentExecutor : IArgumentExecutor
/// </summary>
private readonly IProcessHelper _processHelper;

/// <summary>
/// Used to flag that the run was started from an Editor or IDE.
/// </summary>
private readonly IRunSettingsHelper _runSettingsHelper;

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="options">
/// The options.
/// </param>
/// <param name="testRequestManager"> Test request manager</param>
public PortArgumentExecutor(CommandLineOptions options, ITestRequestManager testRequestManager)
: this(options, testRequestManager, InitializeDesignMode, new ProcessHelper())
/// <param name="runSettingsHelper"> The runsettings helper. </param>
public PortArgumentExecutor(CommandLineOptions options, ITestRequestManager testRequestManager, IRunSettingsHelper runSettingsHelper)
: this(options, testRequestManager, InitializeDesignMode, new ProcessHelper(), runSettingsHelper)
{
}

/// <summary>
/// For Unit testing only
/// </summary>
internal PortArgumentExecutor(CommandLineOptions options, ITestRequestManager testRequestManager, IProcessHelper processHelper)
: this(options, testRequestManager, InitializeDesignMode, processHelper)
internal PortArgumentExecutor(CommandLineOptions options, ITestRequestManager testRequestManager, IProcessHelper processHelper, IRunSettingsHelper runSettingsHelper)
: this(options, testRequestManager, InitializeDesignMode, processHelper, runSettingsHelper)
{
}

/// <summary>
/// For Unit testing only
/// </summary>
internal PortArgumentExecutor(CommandLineOptions options, ITestRequestManager testRequestManager, Func<int, IProcessHelper, IDesignModeClient> designModeInitializer, IProcessHelper processHelper)
internal PortArgumentExecutor(CommandLineOptions options, ITestRequestManager testRequestManager, Func<int, IProcessHelper, IDesignModeClient> designModeInitializer, IProcessHelper processHelper, IRunSettingsHelper runSettingsHelper)
{
ValidateArg.NotNull(options, nameof(options));
_commandLineOptions = options;
_testRequestManager = testRequestManager;
_designModeInitializer = designModeInitializer;
_processHelper = processHelper;
_runSettingsHelper = runSettingsHelper;
}
Comment on lines 139 to 145


#region IArgumentExecutor

/// <summary>
Expand All @@ -148,7 +160,7 @@ public void Initialize(string? argument)
_port = portNumber;
_commandLineOptions.Port = portNumber;
_commandLineOptions.IsDesignMode = true;
RunSettingsHelper.Instance.IsDesignMode = true;
_runSettingsHelper.IsDesignMode = true;
_designModeClient = _designModeInitializer?.Invoke(_commandLineOptions.ParentProcessId, _processHelper);
}

Expand Down
12 changes: 8 additions & 4 deletions src/vstest.console/Processors/RunSettingsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ internal class RunSettingsArgumentProcessor : IArgumentProcessor
private Lazy<IArgumentProcessorCapabilities>? _metadata;
private Lazy<IArgumentExecutor>? _executor;
private readonly IRunSettingsProvider _runSettingsProvider;
private readonly IRunSettingsHelper _runSettingsHelper;

public RunSettingsArgumentProcessor(IRunSettingsProvider runSettingsProvider)
public RunSettingsArgumentProcessor(IRunSettingsProvider runSettingsProvider, IRunSettingsHelper runSettingsHelper)
{
_runSettingsProvider = runSettingsProvider;
_runSettingsHelper = runSettingsHelper;
}

/// <summary>
Expand All @@ -50,7 +52,7 @@ public Lazy<IArgumentProcessorCapabilities> Metadata
public Lazy<IArgumentExecutor>? Executor
{
get => _executor ??= new Lazy<IArgumentExecutor>(() =>
new RunSettingsArgumentExecutor(CommandLineOptions.Instance, _runSettingsProvider));
new RunSettingsArgumentExecutor(CommandLineOptions.Instance, _runSettingsProvider, _runSettingsHelper));

set => _executor = value;
}
Expand All @@ -75,13 +77,15 @@ internal class RunSettingsArgumentExecutor : IArgumentExecutor
{
private readonly CommandLineOptions _commandLineOptions;
private readonly IRunSettingsProvider _runSettingsManager;
private readonly IRunSettingsHelper _runSettingsHelper;

internal IFileHelper FileHelper { get; set; }

internal RunSettingsArgumentExecutor(CommandLineOptions commandLineOptions, IRunSettingsProvider runSettingsManager)
internal RunSettingsArgumentExecutor(CommandLineOptions commandLineOptions, IRunSettingsProvider runSettingsManager, IRunSettingsHelper runSettingsHelper)
{
_commandLineOptions = commandLineOptions;
_runSettingsManager = runSettingsManager;
_runSettingsHelper = runSettingsHelper;
FileHelper = new FileHelper();
}

Expand Down Expand Up @@ -150,7 +154,7 @@ private void ExtractFrameworkAndPlatform()
var platformStr = _runSettingsManager.QueryRunSettingsNode(PlatformArgumentExecutor.RunSettingsPath);
if (Enum.TryParse<Architecture>(platformStr, true, out var architecture))
{
RunSettingsHelper.Instance.IsDefaultTargetArchitecture = false;
_runSettingsHelper.IsDefaultTargetArchitecture = false;
_commandLineOptions.TargetArchitecture = architecture;
}
}
Expand Down
Loading
Loading