From b90b191ef0d4b019982bcfe60669f6fde5a2ac21 Mon Sep 17 00:00:00 2001 From: Faizan2304 Date: Tue, 2 May 2017 21:30:51 -0700 Subject: [PATCH] Insert Microsoft.TestPlatform.cli for update3 preview1 (#6420) * Fix test issue failing with PathTooLongIssue (cherry picked from commit 340254f7742201c74ed1a5c349bdca89113bd5dc) * fix for issues: 1) https://github.com/Microsoft/vstest/issues/755 2) https://github.com/Microsoft/vstest/issues/687 3) https://github.com/Microsoft/vstest/issues/737 (cherry picked from commit 0e93b2a5d4734637538781fa5401ed81a31eea0f) * use new version * Update version * Fix pathtoolong issue * Fix test --- .../{VSTestDotNetCore => VSTestCore}/Tests.cs | 0 .../VSTestCore.csproj} | 0 .../Tests.cs | 0 .../VSTestDesktopAndNetCore.csproj | 1 - .../UnitTest1.cs | 0 .../XunitCore.csproj} | 0 .../UnitTest1.cs | 0 .../VSTestXunitDesktopAndNetCore.csproj | 0 build/DependencyVersions.props | 2 +- .../dotnet-test/LocalizableStrings.cs | 19 ++++- src/dotnet/commands/dotnet-test/Program.cs | 24 +++++- .../commands/dotnet-test/TestCommandParser.cs | 7 ++ .../GivenThatIWantToRestoreApp.cs | 2 +- ...ildsAndRunsTestFromCsprojForMultipleTFM.cs | 14 ++-- ...enDotnetTestBuildsAndRunsTestfromCsproj.cs | 73 ++++++++++--------- test/dotnet-vstest.Tests/VSTestTests.cs | 2 +- 16 files changed, 93 insertions(+), 51 deletions(-) rename TestAssets/TestProjects/{VSTestDotNetCore => VSTestCore}/Tests.cs (100%) rename TestAssets/TestProjects/{VSTestDotNetCore/VSTestDotNetCore.csproj => VSTestCore/VSTestCore.csproj} (100%) rename TestAssets/TestProjects/{VSTestDesktopAndNetCore => VSTestMulti}/Tests.cs (100%) rename TestAssets/TestProjects/{VSTestDesktopAndNetCore => VSTestMulti}/VSTestDesktopAndNetCore.csproj (95%) rename TestAssets/TestProjects/{VSTestXunitDotNetCore => XunitCore}/UnitTest1.cs (100%) rename TestAssets/TestProjects/{VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj => XunitCore/XunitCore.csproj} (100%) rename TestAssets/TestProjects/{VSTestXunitDesktopAndNetCore => XunitMulti}/UnitTest1.cs (100%) rename TestAssets/TestProjects/{VSTestXunitDesktopAndNetCore => XunitMulti}/VSTestXunitDesktopAndNetCore.csproj (100%) diff --git a/TestAssets/TestProjects/VSTestDotNetCore/Tests.cs b/TestAssets/TestProjects/VSTestCore/Tests.cs similarity index 100% rename from TestAssets/TestProjects/VSTestDotNetCore/Tests.cs rename to TestAssets/TestProjects/VSTestCore/Tests.cs diff --git a/TestAssets/TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj b/TestAssets/TestProjects/VSTestCore/VSTestCore.csproj similarity index 100% rename from TestAssets/TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj rename to TestAssets/TestProjects/VSTestCore/VSTestCore.csproj diff --git a/TestAssets/TestProjects/VSTestDesktopAndNetCore/Tests.cs b/TestAssets/TestProjects/VSTestMulti/Tests.cs similarity index 100% rename from TestAssets/TestProjects/VSTestDesktopAndNetCore/Tests.cs rename to TestAssets/TestProjects/VSTestMulti/Tests.cs diff --git a/TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj b/TestAssets/TestProjects/VSTestMulti/VSTestDesktopAndNetCore.csproj similarity index 95% rename from TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj rename to TestAssets/TestProjects/VSTestMulti/VSTestDesktopAndNetCore.csproj index 9cd7184f8..1a8fb8e53 100644 --- a/TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj +++ b/TestAssets/TestProjects/VSTestMulti/VSTestDesktopAndNetCore.csproj @@ -2,7 +2,6 @@ - Exe net46;netcoreapp2.0 diff --git a/TestAssets/TestProjects/VSTestXunitDotNetCore/UnitTest1.cs b/TestAssets/TestProjects/XunitCore/UnitTest1.cs similarity index 100% rename from TestAssets/TestProjects/VSTestXunitDotNetCore/UnitTest1.cs rename to TestAssets/TestProjects/XunitCore/UnitTest1.cs diff --git a/TestAssets/TestProjects/VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj b/TestAssets/TestProjects/XunitCore/XunitCore.csproj similarity index 100% rename from TestAssets/TestProjects/VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj rename to TestAssets/TestProjects/XunitCore/XunitCore.csproj diff --git a/TestAssets/TestProjects/VSTestXunitDesktopAndNetCore/UnitTest1.cs b/TestAssets/TestProjects/XunitMulti/UnitTest1.cs similarity index 100% rename from TestAssets/TestProjects/VSTestXunitDesktopAndNetCore/UnitTest1.cs rename to TestAssets/TestProjects/XunitMulti/UnitTest1.cs diff --git a/TestAssets/TestProjects/VSTestXunitDesktopAndNetCore/VSTestXunitDesktopAndNetCore.csproj b/TestAssets/TestProjects/XunitMulti/VSTestXunitDesktopAndNetCore.csproj similarity index 100% rename from TestAssets/TestProjects/VSTestXunitDesktopAndNetCore/VSTestXunitDesktopAndNetCore.csproj rename to TestAssets/TestProjects/XunitMulti/VSTestXunitDesktopAndNetCore.csproj diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index f599008f4..c4bb77b81 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -7,7 +7,7 @@ 2.0.0-alpha-20170502-2 4.3.0-beta1-2418 1.0.0-rel-20170501-473 - 15.1.0-preview-20170414-04 + 15.3.0-preview-20170502-03 $(CLI_SharedFrameworkVersion) $(CLI_SharedFrameworkVersion) $(CLI_SharedFrameworkVersion) diff --git a/src/dotnet/commands/dotnet-test/LocalizableStrings.cs b/src/dotnet/commands/dotnet-test/LocalizableStrings.cs index 6056e0fc2..fbe9ba5c0 100644 --- a/src/dotnet/commands/dotnet-test/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-test/LocalizableStrings.cs @@ -37,7 +37,8 @@ namespace Microsoft.DotNet.Tools.Test public const string CmdLoggerOption = "LoggerUri/FriendlyName"; public const string CmdLoggerDescription = @"Specify a logger for test results. - Example: --logger ""trx[;LogFileName=]"""; + Example: --logger ""trx[;LogFileName=]"" + More info on logger arguments support:https://aka.ms/vstest-report"; public const string CmdConfiguration = "CONFIGURATION"; @@ -58,12 +59,22 @@ namespace Microsoft.DotNet.Tools.Test public const string CmdNoBuildDescription = @"Do not build project before testing."; - public const string RunSettingsArgsHelpText = @"Any extra command-line runsettings arguments that should be passed to vstest. See 'dotnet vstest --help' for available options. - Example: -- RunConfiguration.ResultsDirectory=""C:\users\user\desktop\Results Directory"" MSTest.DeploymentEnabled=false"; - public const string CmdResultsDirectoryDescription = @"The directory where the test results are going to be placed. The specified directory will be created if it does not exist. Example: --results-directory "; public const string CmdPathToResultsDirectory = "PATH_TO_RESULTS_DIRECTORY"; + + public const string RunSettingsArgumentsDescription = @" + +RunSettings arguments: + Arguments to pass runsettings configurations through commandline. Arguments may be specified as name-value pair of the form [name]=[value] after ""-- "". Note the space after --. + Use a space to separate multiple[name] =[value]. + More info on RunSettings arguments support: https://aka.ms/vstest-runsettings-arguments + Example: dotnet test -- MSTest.DeploymentEnabled=false MSTest.MapInconclusiveToFailed=True"; + + public const string cmdCollectFriendlyName = "DATA_COLLECTOR_FRIENDLY_NAME"; + + public const string cmdCollectDescription = @"Enables data collector for the test run. + More info here : https://aka.ms/vstest-collect"; } } diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 913181a20..a7f9a0380 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Tools.Test { } - public static TestCommand FromArgs(string[] args, string msbuildPath=null) + public static TestCommand FromArgs(string[] args, string msbuildPath = null) { var msbuildArgs = new List() { @@ -34,6 +34,7 @@ namespace Microsoft.DotNet.Tools.Test var result = parser.ParseFrom("dotnet test", args); + UpdateRunSettingsArgumentsText(); result.ShowHelpOrErrorIfAppropriate(); var parsedTest = result["dotnet"]["test"]; @@ -42,7 +43,7 @@ namespace Microsoft.DotNet.Tools.Test msbuildArgs.AddRange(parsedTest.Arguments); - var runSettingsOptions = + var runSettingsOptions = result.UnparsedTokens .Select(GetSemiColonEscapedString); @@ -53,6 +54,17 @@ namespace Microsoft.DotNet.Tools.Test msbuildArgs.Add($"/p:VSTestCLIRunSettings=\"{runSettingsArg}\""); } + var verbosityArg = msbuildArgs.LastOrDefault(arg => arg.StartsWith("/verbosity")); + + if (!string.IsNullOrEmpty(verbosityArg)) + { + var verbosity = verbosityArg.Split(':'); + if (verbosity.Length == 2) + { + msbuildArgs.Add($"/p:VSTestVerbosity={verbosity[1]}"); + } + } + return new TestCommand(msbuildArgs, msbuildPath); } @@ -61,7 +73,7 @@ namespace Microsoft.DotNet.Tools.Test DebugHelper.HandleDebugSwitch(ref args); TestCommand cmd; - + try { cmd = FromArgs(args); @@ -96,5 +108,11 @@ namespace Microsoft.DotNet.Tools.Test return array; } + + private static void UpdateRunSettingsArgumentsText() + { + DefaultHelpViewText.Synopsis.AdditionalArguments = " [[--] ...]]"; + DefaultHelpViewText.AdditionalArgumentsSection = LocalizableStrings.RunSettingsArgumentsDescription; + } } } diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index c79dee524..a17aa20a7 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Cli Accept.ZeroOrMoreArguments() .With(name: LocalizableStrings.CmdArgProject, description: LocalizableStrings.CmdArgDescription), + false, CommonOptions.HelpOption(), Create.Option( "-s|--settings", @@ -74,6 +75,12 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdPathToResultsDirectory) .ForwardAsSingle(o => $"/p:VSTestResultsDirectory={o.Arguments.Single()}")), + Create.Option( + "--collect", + LocalizableStrings.cmdCollectDescription, + Accept.OneOrMoreArguments() + .With(name: LocalizableStrings.cmdCollectFriendlyName) + .ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")), CommonOptions.VerbosityOption()); private static string GetSemiColonEsacpedstring(string arg) diff --git a/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs b/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs index 6b6f1b6b9..3b5c44b42 100644 --- a/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs +++ b/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs @@ -73,7 +73,7 @@ namespace Microsoft.DotNet.Restore.Tests [Fact] public void ItRestoresTestAppToSpecificDirectory() { - var rootPath = TestAssets.Get("VSTestDotNetCore").CreateInstance().WithSourceFiles().Root.FullName; + var rootPath = TestAssets.Get("VSTestCore").CreateInstance().WithSourceFiles().Root.FullName; string dir = "pkgs"; string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestFromCsprojForMultipleTFM.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestFromCsprojForMultipleTFM.cs index b6ee1198b..a111db3c3 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestFromCsprojForMultipleTFM.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestFromCsprojForMultipleTFM.cs @@ -12,11 +12,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests { public class GivenDotnetTestBuildsAndRunsTestFromCsprojForMultipleTFM : TestBase { - [WindowsOnlyFact(Skip="https://github.com/dotnet/cli/issues/4616")] + [WindowsOnlyFact] public void MStestMultiTFM() { - var testProjectDirectory = TestAssets.Get("VSTestDesktopAndNetCore") - .CreateInstance() + var testProjectDirectory = TestAssets.Get("VSTestMulti") + .CreateInstance("1") .WithSourceFiles() .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages) .Root; @@ -45,15 +45,15 @@ namespace Microsoft.DotNet.Cli.Test.Tests [WindowsOnlyFact] public void XunitMultiTFM() { - // Copy VSTestXunitDesktopAndNetCore project in output directory of project dotnet-test.Tests - string testAppName = "VSTestXunitDesktopAndNetCore"; + // Copy XunitMulti project in output directory of project dotnet-test.Tests + string testAppName = "XunitMulti"; var testInstance = TestAssets.Get(testAppName) - .CreateInstance() + .CreateInstance("2") .WithSourceFiles(); var testProjectDirectory = testInstance.Root.FullName; - // Restore project VSTestXunitDesktopAndNetCore + // Restore project XunitMulti new RestoreCommand() .WithWorkingDirectory(testProjectDirectory) .Execute() diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index c3630da20..b20fb70ef 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -17,20 +17,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests [Fact] public void MSTestSingleTFM() { - // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests - string testAppName = "VSTestDotNetCore"; - var testInstance = TestAssets.Get(testAppName) - .CreateInstance() - .WithSourceFiles(); - - var testProjectDirectory = testInstance.Root.FullName; - - // Restore project VSTestDotNetCore - new RestoreCommand() - .WithWorkingDirectory(testProjectDirectory) - .Execute() - .Should() - .Pass(); + var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("3"); // Call test CommandResult result = new DotnetTestCommand() @@ -47,15 +34,15 @@ namespace Microsoft.DotNet.Cli.Test.Tests [Fact] public void XunitSingleTFM() { - // Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests - string testAppName = "VSTestXunitDotNetCore"; + // Copy XunitCore project in output directory of project dotnet-vstest.Tests + string testAppName = "XunitCore"; var testInstance = TestAssets.Get(testAppName) - .CreateInstance() + .CreateInstance("4") .WithSourceFiles(); var testProjectDirectory = testInstance.Root.FullName; - // Restore project VSTestXunitDotNetCore + // Restore project XunitCore new RestoreCommand() .WithWorkingDirectory(testProjectDirectory) .Execute() @@ -77,11 +64,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests [Fact] public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven() { - // Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests - var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp(); + // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests + var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("5"); string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; string expectedError = Path.Combine(testProjectDirectory, "bin", - configuration, "netcoreapp2.0", "VSTestDotNetCore.dll"); + configuration, "netcoreapp2.0", "VSTestCore.dll"); expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found."; // Call test @@ -96,10 +83,10 @@ namespace Microsoft.DotNet.Cli.Test.Tests [Fact] public void TestWillCreateTrxLoggerInTheSpecifiedResultsDirectoryBySwitch() { - // Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests - var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp(); + // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests + var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("6"); - string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults", "netcoreappx.y"); + string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TR", "x.y"); // Delete trxLoggerDirectory if it exist if (Directory.Exists(trxLoggerDirectory)) @@ -127,10 +114,10 @@ namespace Microsoft.DotNet.Cli.Test.Tests [Fact] public void ItCreatesTrxReportInTheSpecifiedResultsDirectoryByArgs() { - // Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests - var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp(); + // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests + var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("7"); - string trxLoggerDirectory = Path.Combine(testProjectDirectory, "ResultsDirectory"); + string trxLoggerDirectory = Path.Combine(testProjectDirectory, "RD"); // Delete trxLoggerDirectory if it exist if (Directory.Exists(trxLoggerDirectory)) @@ -155,12 +142,14 @@ namespace Microsoft.DotNet.Cli.Test.Tests } } - [Fact(Skip = "https://github.com/dotnet/cli/issues/5035")] + [Fact] public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory() { - var rootPath = TestAssets.Get("VSTestDotNetCore").CreateInstance().WithSourceFiles().Root.FullName; + // Creating folder with name short name "RestoreTest" to avoid PathTooLongException + var rootPath = TestAssets.Get("VSTestCore").CreateInstance("8").WithSourceFiles().Root.FullName; - string dir = "pkgs"; + // Moving pkgs folder on top to avoid PathTooLongException + string dir = @"..\..\..\..\pkgs"; string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); string args = $"--packages \"{dir}\""; @@ -186,17 +175,35 @@ namespace Microsoft.DotNet.Cli.Test.Tests result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest"); } + [Fact] + public void ItUsesVerbosityPassedToDefineVerbosityOfConsoleLoggerOfTheTests() + { + // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests + var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("9"); + + // Call test + CommandResult result = new DotnetTestCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("-v q"); + + // Verify + result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0."); + result.StdOut.Should().NotContain("Passed TestNamespace.VSTestTests.VSTestPassTest"); + result.StdOut.Should().NotContain("Failed TestNamespace.VSTestTests.VSTestFailTest"); + result.ExitCode.Should().Be(1); + } + private string CopyAndRestoreVSTestDotNetCoreTestApp([CallerMemberName] string callingMethod = "") { - // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests - string testAppName = "VSTestDotNetCore"; + // Copy VSTestCore project in output directory of project dotnet-vstest.Tests + string testAppName = "VSTestCore"; var testInstance = TestAssets.Get(testAppName) .CreateInstance(callingMethod) .WithSourceFiles(); var testProjectDirectory = testInstance.Root.FullName; - // Restore project VSTestDotNetCore + // Restore project VSTestCore new RestoreCommand() .WithWorkingDirectory(testProjectDirectory) .Execute() diff --git a/test/dotnet-vstest.Tests/VSTestTests.cs b/test/dotnet-vstest.Tests/VSTestTests.cs index cd7b0e8e9..0dba88ce5 100644 --- a/test/dotnet-vstest.Tests/VSTestTests.cs +++ b/test/dotnet-vstest.Tests/VSTestTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.DotNet.Cli.VSTest.Tests [Fact] public void TestsFromAGivenContainerShouldRunWithExpectedOutput() { - var testAppName = "VSTestDotNetCore"; + var testAppName = "VSTestCore"; var testRoot = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles()