From aae8fc39ea898315617134ad1eefab345c51dea9 Mon Sep 17 00:00:00 2001 From: Mayank Bansal Date: Tue, 31 Jan 2017 18:54:49 +0530 Subject: [PATCH] Adding /InIsolation flag for backward compatibility --- .../InIsolationArgumentProcessor.cs | 116 ++++++++++++++++++ .../Utilities/ArgumentProcessorFactory.cs | 3 +- .../Resources/Resources.Designer.cs | 11 ++ src/vstest.console/Resources/Resources.resx | 3 + .../Resources/xlf/Resources.cs.xlf | 5 + .../Resources/xlf/Resources.de.xlf | 5 + .../Resources/xlf/Resources.es.xlf | 5 + .../Resources/xlf/Resources.fr.xlf | 5 + .../Resources/xlf/Resources.it.xlf | 5 + .../Resources/xlf/Resources.ja.xlf | 5 + .../Resources/xlf/Resources.ko.xlf | 5 + .../Resources/xlf/Resources.pl.xlf | 5 + .../Resources/xlf/Resources.pt-BR.xlf | 5 + .../Resources/xlf/Resources.ru.xlf | 5 + .../Resources/xlf/Resources.tr.xlf | 5 + .../Resources/xlf/Resources.zh-Hans.xlf | 5 + .../Resources/xlf/Resources.zh-Hant.xlf | 5 + .../InIsolationArgumentProcessorTests.cs | 49 ++++++++ 18 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 src/vstest.console/Processors/InIsolationArgumentProcessor.cs create mode 100644 test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs diff --git a/src/vstest.console/Processors/InIsolationArgumentProcessor.cs b/src/vstest.console/Processors/InIsolationArgumentProcessor.cs new file mode 100644 index 0000000000..de5693ce61 --- /dev/null +++ b/src/vstest.console/Processors/InIsolationArgumentProcessor.cs @@ -0,0 +1,116 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors +{ + using System; + using System.Globalization; + using Microsoft.VisualStudio.TestPlatform.Utilities; + using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; + + /// + /// An argument processor that allows the user to specify whether the execution + /// should happen in the current vstest.console.exe process or a new different process. + /// + internal class InIsolationArgumentProcessor : IArgumentProcessor + { + #region Constants + + public const string CommandName = "/InIsolation"; + + #endregion + + private Lazy metadata; + + private Lazy executor; + + /// + /// Gets the metadata. + /// + public Lazy Metadata + { + get + { + if (this.metadata == null) + { + this.metadata = new Lazy(() => new InIsolationArgumentProcessorCapabilities()); + } + + return this.metadata; + } + } + + /// + /// Gets or sets the executor. + /// + public Lazy Executor + { + get + { + if (this.executor == null) + { + this.executor = + new Lazy( + () => + new InIsolationArgumentExecutor()); + } + + return this.executor; + } + + set + { + this.executor = value; + } + } + } + + internal class InIsolationArgumentProcessorCapabilities : BaseArgumentProcessorCapabilities + { + public override string CommandName => InIsolationArgumentProcessor.CommandName; + + public override bool AllowMultiple => false; + + public override bool IsAction => false; + + public override ArgumentProcessorPriority Priority => ArgumentProcessorPriority.Normal; + + public override HelpContentPriority HelpPriority => HelpContentPriority.InIsolationArgumentProcessorHelpPriority; + } + + internal class InIsolationArgumentExecutor : IArgumentExecutor + { + #region Constructors + public InIsolationArgumentExecutor() + { + } + #endregion + + #region IArgumentProcessor + + /// + /// Initializes with the argument that was provided with the command. + /// + /// Argument that was provided with the command. + public void Initialize(string argument) + { + if (!string.IsNullOrWhiteSpace(argument)) + { + throw new CommandLineException( + string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidInIsolationCommand, argument)); + } + + ConsoleOutput.Instance.WriteLine(CommandLineResources.InIsolationDeprecated, OutputLevel.Information); + } + + /// + /// Execute. + /// + public ArgumentProcessorResult Execute() + { + // Nothing to do since we updated the parameter during initialize parameter + return ArgumentProcessorResult.Success; + } + + #endregion + } +} diff --git a/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs b/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs index 241ab9efbe..754f9c6435 100644 --- a/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs +++ b/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs @@ -230,7 +230,8 @@ public IEnumerable GetArgumentProcessorsToAlwaysExecute() new ParallelArgumentProcessor(), new EnableDiagArgumentProcessor(), new CLIRunSettingsArgumentProcessor(), - new ResultsDirectoryArgumentProcessor() + new ResultsDirectoryArgumentProcessor(), + new InIsolationArgumentProcessor() }; /// diff --git a/src/vstest.console/Resources/Resources.Designer.cs b/src/vstest.console/Resources/Resources.Designer.cs index 0f55d62a8b..bc92446200 100644 --- a/src/vstest.console/Resources/Resources.Designer.cs +++ b/src/vstest.console/Resources/Resources.Designer.cs @@ -1449,5 +1449,16 @@ public static string UseVsixExtensionsValueRequired { return ResourceManager.GetString("UseVsixExtensionsValueRequired", resourceCulture); } } + + /// + /// Looks up a localized string similar to The /InIsolation flag is deprecated. The test are always run in a separate process + /// + public static string InIsolationDeprecated + { + get + { + return ResourceManager.GetString("InIsolationDeprecated", resourceCulture); + } + } } } diff --git a/src/vstest.console/Resources/Resources.resx b/src/vstest.console/Resources/Resources.resx index 7165b68a1c..f59bed4b42 100644 --- a/src/vstest.console/Resources/Resources.resx +++ b/src/vstest.console/Resources/Resources.resx @@ -634,4 +634,7 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.cs.xlf b/src/vstest.console/Resources/xlf/Resources.cs.xlf index ae99dcd7ff..6eefc12f23 100644 --- a/src/vstest.console/Resources/xlf/Resources.cs.xlf +++ b/src/vstest.console/Resources/xlf/Resources.cs.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.de.xlf b/src/vstest.console/Resources/xlf/Resources.de.xlf index abdfcff487..fe2b48d32b 100644 --- a/src/vstest.console/Resources/xlf/Resources.de.xlf +++ b/src/vstest.console/Resources/xlf/Resources.de.xlf @@ -1514,6 +1514,11 @@ Standardeinstellungen werden verwendet, wenn die Verwendung der Einstellungsdate The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.es.xlf b/src/vstest.console/Resources/xlf/Resources.es.xlf index c4142180c9..9a872e37a8 100644 --- a/src/vstest.console/Resources/xlf/Resources.es.xlf +++ b/src/vstest.console/Resources/xlf/Resources.es.xlf @@ -1526,6 +1526,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.fr.xlf b/src/vstest.console/Resources/xlf/Resources.fr.xlf index 7efa9415ec..ded1eb6100 100644 --- a/src/vstest.console/Resources/xlf/Resources.fr.xlf +++ b/src/vstest.console/Resources/xlf/Resources.fr.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.it.xlf b/src/vstest.console/Resources/xlf/Resources.it.xlf index 9d1bc35168..5f7211425b 100644 --- a/src/vstest.console/Resources/xlf/Resources.it.xlf +++ b/src/vstest.console/Resources/xlf/Resources.it.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.ja.xlf b/src/vstest.console/Resources/xlf/Resources.ja.xlf index 2cc9e96f7c..21a95e5c62 100644 --- a/src/vstest.console/Resources/xlf/Resources.ja.xlf +++ b/src/vstest.console/Resources/xlf/Resources.ja.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.ko.xlf b/src/vstest.console/Resources/xlf/Resources.ko.xlf index 9a601129e8..2cd71478cc 100644 --- a/src/vstest.console/Resources/xlf/Resources.ko.xlf +++ b/src/vstest.console/Resources/xlf/Resources.ko.xlf @@ -1515,6 +1515,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.pl.xlf b/src/vstest.console/Resources/xlf/Resources.pl.xlf index 8ff25b780a..e5aa3e3798 100644 --- a/src/vstest.console/Resources/xlf/Resources.pl.xlf +++ b/src/vstest.console/Resources/xlf/Resources.pl.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf b/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf index 68cb76d2c3..fdb663ae82 100644 --- a/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf +++ b/src/vstest.console/Resources/xlf/Resources.pt-BR.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.ru.xlf b/src/vstest.console/Resources/xlf/Resources.ru.xlf index 771f68df78..7f25e6c6c8 100644 --- a/src/vstest.console/Resources/xlf/Resources.ru.xlf +++ b/src/vstest.console/Resources/xlf/Resources.ru.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.tr.xlf b/src/vstest.console/Resources/xlf/Resources.tr.xlf index 0d475c70d2..c99d81f63f 100644 --- a/src/vstest.console/Resources/xlf/Resources.tr.xlf +++ b/src/vstest.console/Resources/xlf/Resources.tr.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf b/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf index 5724b5e2b7..05556609b3 100644 --- a/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/vstest.console/Resources/xlf/Resources.zh-Hans.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf b/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf index f7e0d7db37..294fec6fda 100644 --- a/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/vstest.console/Resources/xlf/Resources.zh-Hant.xlf @@ -1514,6 +1514,11 @@ The path '{0}' specified in the 'ResultsDirectory' is invalid. Error: {1} + + The /InIsolation flag is deprecated. The tests are always run in a separate process + The /InIsolation flag is deprecated. The tests are always run in a separate process + + \ No newline at end of file diff --git a/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs new file mode 100644 index 0000000000..ea312cb0ee --- /dev/null +++ b/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors +{ + using System.Diagnostics; + using System.IO; + + using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using Moq; + + using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; + + [TestClass] + public class InIsolationArgumentProcessorTests + { + private readonly InIsolationArgumentProcessor isolationProcessor; + + public InIsolationArgumentProcessorTests() + { + this.isolationProcessor = new InIsolationArgumentProcessor(); + } + + [TestMethod] + public void InIsolationArgumentProcessorMetadataShouldProvideAppropriateCapabilities() + { + Assert.IsFalse(this.isolationProcessor.Metadata.Value.AllowMultiple); + Assert.IsFalse(this.isolationProcessor.Metadata.Value.AlwaysExecute); + Assert.IsFalse(this.isolationProcessor.Metadata.Value.IsAction); + Assert.IsFalse(this.isolationProcessor.Metadata.Value.IsSpecialCommand); + Assert.AreEqual(InIsolationArgumentProcessor.CommandName, this.isolationProcessor.Metadata.Value.CommandName); + Assert.AreEqual(null, this.isolationProcessor.Metadata.Value.ShortCommandName); + Assert.AreEqual(ArgumentProcessorPriority.Normal, this.isolationProcessor.Metadata.Value.Priority); + Assert.AreEqual(HelpContentPriority.InIsolationArgumentProcessorHelpPriority, this.isolationProcessor.Metadata.Value.HelpPriority); + } + + + [TestMethod] + public void InIsolationArgumentProcessorExecutorShouldThrowIfArgumentIsProvided() + { + Assert.ThrowsException(() => this.isolationProcessor.Executor.Value.Initialize("foo")); + } + + } +} \ No newline at end of file