From 4f30aed1260bb91c4bfc8993baeeb4002ace947e Mon Sep 17 00:00:00 2001 From: Harsh Jain Date: Tue, 3 Jan 2017 19:47:00 +0530 Subject: [PATCH 1/3] Enclosing run settings arguments to handle whitespace. --- src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index b4e2076d40..2fd3f1a56e 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -165,10 +165,13 @@ private IEnumerable CreateArgument() } } - if (this.VSTestCLIRunSettings!=null && this.VSTestCLIRunSettings.Length>0) + if (this.VSTestCLIRunSettings != null && this.VSTestCLIRunSettings.Length > 0) { allArgs.Add("--"); - allArgs.AddRange(this.VSTestCLIRunSettings); + foreach (var arg in this.VSTestCLIRunSettings) + { + allArgs.Add(this.AddDoubleQuotes(arg)); + } } return allArgs; From 56963d559f545fabb954a53667520a51de5cad00 Mon Sep 17 00:00:00 2001 From: Harsh Jain Date: Wed, 4 Jan 2017 23:52:25 +0530 Subject: [PATCH 2/3] Added Tests. --- TestPlatform.sln | 33 ++++++++++----- src/Microsoft.TestPlatform.Build/Friends.cs | 10 +++++ .../Tasks/VSTestTask.cs | 19 ++++----- ...rosoft.TestPlatform.Build.UnitTests.csproj | 40 +++++++++++++++++++ .../Program.cs | 11 +++++ .../VsTestTaskTests.cs | 33 +++++++++++++++ 6 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 src/Microsoft.TestPlatform.Build/Friends.cs create mode 100644 test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj create mode 100644 test/Microsoft.TestPlatform.Build.UnitTests/Program.cs create mode 100644 test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs diff --git a/TestPlatform.sln b/TestPlatform.sln index 67d17fdcdb..be14931330 100644 --- a/TestPlatform.sln +++ b/TestPlatform.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26014.0 +VisualStudioVersion = 15.0.26009.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}" EndProject @@ -122,6 +122,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Prot EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleTestProject3", "test\TestAssets\SimpleTestProject3\SimpleTestProject3.csproj", "{82E75225-FA92-4F87-909D-039D62F96BFF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Build.UnitTests", "test\Microsoft.TestPlatform.Build.UnitTests\Microsoft.TestPlatform.Build.UnitTests.csproj", "{EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -182,16 +184,16 @@ Global {2820F090-3F3D-4DA2-8CBA-B8273D695333}.Release|x86.Build.0 = Release|x86 {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x64.ActiveCfg = Debug|x64 - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x64.Build.0 = Debug|x64 - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x86.ActiveCfg = Debug|x86 - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x86.Build.0 = Debug|x86 + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x64.ActiveCfg = Debug|Any CPU + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x64.Build.0 = Debug|Any CPU + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x86.ActiveCfg = Debug|Any CPU + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Debug|x86.Build.0 = Debug|Any CPU {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|Any CPU.ActiveCfg = Release|Any CPU {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|Any CPU.Build.0 = Release|Any CPU - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x64.ActiveCfg = Release|x64 - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x64.Build.0 = Release|x64 - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x86.ActiveCfg = Release|x86 - {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x86.Build.0 = Release|x86 + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x64.ActiveCfg = Release|Any CPU + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x64.Build.0 = Release|Any CPU + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x86.ActiveCfg = Release|Any CPU + {6F5EC38C-4A11-40D3-827C-F607B90BEFF0}.Release|x86.Build.0 = Release|Any CPU {E19B5128-3469-492E-82E1-725631C4A68C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E19B5128-3469-492E-82E1-725631C4A68C}.Debug|Any CPU.Build.0 = Debug|Any CPU {E19B5128-3469-492E-82E1-725631C4A68C}.Debug|x64.ActiveCfg = Debug|x64 @@ -672,6 +674,18 @@ Global {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x64.Build.0 = Release|Any CPU {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x86.ActiveCfg = Release|Any CPU {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x86.Build.0 = Release|Any CPU + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Debug|x64.ActiveCfg = Debug|x64 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Debug|x64.Build.0 = Debug|x64 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Debug|x86.ActiveCfg = Debug|x86 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Debug|x86.Build.0 = Debug|x86 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Release|Any CPU.Build.0 = Release|Any CPU + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Release|x64.ActiveCfg = Release|x64 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Release|x64.Build.0 = Release|x64 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Release|x86.ActiveCfg = Release|x86 + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -728,5 +742,6 @@ Global {D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} {97DD9467-B011-4736-AAC4-2C21BF554349} = {B9AB7A3D-4F63-48D2-86C0-70F52F6509AB} {82E75225-FA92-4F87-909D-039D62F96BFF} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} + {EFA38DEF-C2BB-42AE-8B68-B31D79F3107E} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} EndGlobalSection EndGlobal diff --git a/src/Microsoft.TestPlatform.Build/Friends.cs b/src/Microsoft.TestPlatform.Build/Friends.cs new file mode 100644 index 0000000000..96425d0028 --- /dev/null +++ b/src/Microsoft.TestPlatform.Build/Friends.cs @@ -0,0 +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 System.Runtime.CompilerServices; + +#region Test Assemblies + +[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Build.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] + +#endregion diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index 2fd3f1a56e..29bb2f7112 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -3,13 +3,14 @@ namespace Microsoft.TestPlatform.Build.Tasks { + using System; using System.Collections.Generic; + using System.Diagnostics; + using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; - using System; - using System.IO; - using System.Diagnostics; + using Trace; public class VSTestTask : Task, ICancelableTask @@ -96,12 +97,7 @@ public void Cancel() vsTestForwardingApp.Cancel(); } - private string AddDoubleQuotes(string x) - { - return "\"" + x + "\""; - } - - private IEnumerable CreateArgument() + internal IEnumerable CreateArgument() { var allArgs = new List(); @@ -176,5 +172,10 @@ private IEnumerable CreateArgument() return allArgs; } + + private string AddDoubleQuotes(string x) + { + return "\"" + x + "\""; + } } } diff --git a/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj b/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj new file mode 100644 index 0000000000..4a343e76b7 --- /dev/null +++ b/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj @@ -0,0 +1,40 @@ + + + $(MSBuildThisFileDirectory)../../ + true + + + + Exe + netcoreapp1.0;net46 + Microsoft.TestPlatform.Build.UnitTests + $(PackageTargetFallback);dnxcore50;portable-net45+win8 + + + + + + + + + true + + + true + + + + + 1.0.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.Build.UnitTests/Program.cs b/test/Microsoft.TestPlatform.Build.UnitTests/Program.cs new file mode 100644 index 0000000000..1ee281bfd3 --- /dev/null +++ b/test/Microsoft.TestPlatform.Build.UnitTests/Program.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. + +namespace Microsoft.TestPlatform.Build.UnitTests +{ + public static class Program + { + public static void Main(string[] args) + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs b/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs new file mode 100644 index 0000000000..a74ec7d5c0 --- /dev/null +++ b/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. + +namespace Microsoft.TestPlatform.Build.UnitTests +{ + using System.Linq; + + using Microsoft.TestPlatform.Build.Tasks; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class VsTestTaskTests + { + [TestMethod] + public void CreateArgumentShouldAddDoubleQuotesForCLIRunSettings() + { + const string arg1 = "RunConfiguration.ResultsDirectory=Path having Space"; + const string arg2 = "MSTest.DeploymentEnabled"; + var vstestTask = new VSTestTask { VSTestCLIRunSettings = new string[2] }; + vstestTask.VSTestCLIRunSettings[0] = arg1; + vstestTask.VSTestCLIRunSettings[1] = arg2; + + // Add values for required properties. + vstestTask.TestFileFullPath = "abc"; + vstestTask.VSTestFramework = "abc"; + + var result = vstestTask.CreateArgument().ToArray(); + + // First, second and third args would be --framework:abc, testfilepath and -- respectively. + Assert.AreEqual($"\"{arg1}\"", result[3]); + Assert.AreEqual($"\"{arg2}\"", result[4]); + } + } +} From b000a8c087b11eb69babaedb98892af0b9937627 Mon Sep 17 00:00:00 2001 From: Harsh Jain Date: Thu, 5 Jan 2017 00:20:39 +0530 Subject: [PATCH 3/3] Fixes for test.cmd to work --- .../Microsoft.TestPlatform.Build.UnitTests.csproj | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj b/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj index 4a343e76b7..1114a97147 100644 --- a/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.Build.UnitTests/Microsoft.TestPlatform.Build.UnitTests.csproj @@ -1,4 +1,4 @@ - + $(MSBuildThisFileDirectory)../../ true @@ -18,11 +18,19 @@ true - - + + true + + + 15.1.0-preview-000458-02 + + + 15.1.0-preview-000458-02 + + 1.0.0