- Implementation of test3 verb for single TragetFramework
- E2E test for test3 verb.
This commit is contained in:
parent
0bf92b635a
commit
579df78466
8 changed files with 385 additions and 0 deletions
|
@ -172,6 +172,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-msbuild.Tests", "tes
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-publish3.Tests", "test\dotnet-publish3.Tests\dotnet-publish3.Tests.xproj", "{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-test3.Tests", "test\dotnet-test3.Tests\dotnet-test3.Tests.xproj", "{90236A80-4B84-41D3-A161-AA20709776B1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -1000,6 +1002,22 @@ Global
|
|||
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.Release|x64.Build.0 = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1064,5 +1082,6 @@ Global
|
|||
{9F5AE280-A040-4160-9799-6504D907742D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{2FFCBDF0-BA36-4393-8DDB-1AE04AEA3CD6} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -20,4 +20,10 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'==''">$(MSBuildExtensionsPath)\NuGet.targets</NuGetRestoreTargets>
|
||||
</PropertyGroup>
|
||||
<Import Condition="Exists('$(NuGetRestoreTargets)')" Project="$(NuGetRestoreTargets)" />
|
||||
|
||||
<!-- Import Microsoft.TestPlatform.targets for Test3 -->
|
||||
<PropertyGroup>
|
||||
<VSTestTargets Condition="'$(VSTestTargets)'==''">$(MSBuildExtensionsPath)\Microsoft.TestPlatform.targets</VSTestTargets>
|
||||
</PropertyGroup>
|
||||
<Import Condition="Exists('$(VSTestTargets)')" Project="$(VSTestTargets)" />
|
||||
</Project>
|
||||
|
|
|
@ -27,6 +27,7 @@ using Microsoft.DotNet.Tools.Restore3;
|
|||
using Microsoft.DotNet.Tools.Run;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.DotNet.Tools.VSTest;
|
||||
using Microsoft.DotNet.Tools.Test3;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
|
@ -51,6 +52,7 @@ namespace Microsoft.DotNet.Cli
|
|||
["restore3"] = Restore3Command.Run,
|
||||
["publish3"] = Publish3Command.Run,
|
||||
["vstest"] = VSTestCommand.Run,
|
||||
["test3"] = Test3Command.Run,
|
||||
["pack3"] = Pack3Command.Run,
|
||||
["migrate"] = MigrateCommand.Run,
|
||||
["projectmodel-server"] = ProjectModelServerCommand.Run,
|
||||
|
|
247
src/dotnet/commands/dotnet-test3/Program.cs
Normal file
247
src/dotnet/commands/dotnet-test3/Program.cs
Normal file
|
@ -0,0 +1,247 @@
|
|||
// Copyright(c) .NET Foundation and contributors.All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test3
|
||||
{
|
||||
public class Test3Command
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var cmd = new CommandLineApplication(throwOnUnexpectedArg: false)
|
||||
{
|
||||
Name = "dotnet test3",
|
||||
FullName = ".NET Test Driver",
|
||||
Description = "Test Driver for the .NET Platform"
|
||||
};
|
||||
|
||||
cmd.HelpOption("-h|--help");
|
||||
|
||||
var argRoot = cmd.Argument(
|
||||
"<PROJECT>",
|
||||
"The project to test, defaults to the current directory.",
|
||||
multipleValues: false);
|
||||
|
||||
var settingOption = cmd.Option(
|
||||
"--settings <SettingsFile>",
|
||||
"Settings to use when running tests." + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var testsOption = cmd.Option(
|
||||
"--tests <TestNames>",
|
||||
@"Run tests with names that match the provided values. To provide multiple
|
||||
values, separate them by commas.
|
||||
Examples: --tests:TestMethod1
|
||||
--tests:TestMethod1,testMethod2" + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var testAdapterPathOption = cmd.Option(
|
||||
"--testAdapterPath",
|
||||
@"This makes vstest.console.exe process use custom test adapters
|
||||
from a given path (if any) in the test run.
|
||||
Example --testAdapterPath:<pathToCustomAdapters>" + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var platformOption = cmd.Option(
|
||||
"--platform <PlatformType>",
|
||||
@"Target platform architecture to be used for test execution.
|
||||
Valid values are x86, x64 and ARM." + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var frameworkOption = cmd.Option(
|
||||
"--framework <FrameworkVersion>",
|
||||
@"Target .Net Framework version to be used for test execution.
|
||||
Valid values are "".NETFramework, Version = v4.6"", "".NETCoreApp, Version = v1.0"" etc.
|
||||
Other supported values are Framework35, Framework40 and Framework45" + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var testCaseFilterOption = cmd.Option(
|
||||
"--testCaseFilter <Expression>",
|
||||
@"Run tests that match the given expression.
|
||||
<Expression> is of the format <property>Operator<value>[|&<Expression>]
|
||||
where Operator is one of =, != or ~ (Operator ~ has 'contains'
|
||||
semantics and is applicable for string properties like DisplayName).
|
||||
Parenthesis () can be used to group sub-expressions.
|
||||
Examples: --testCaseFilter:""Priority = 1""
|
||||
--testCaseFilter:""(FullyQualifiedName~Nightly | Name = MyTestMethod)""" + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
// TODO tfs publisher text
|
||||
var loggerOption = cmd.Option(
|
||||
"--logger <LoggerUri/FriendlyName>",
|
||||
@"Specify a logger for test results. For example, to log results into a
|
||||
Visual Studio Test Results File(TRX) use --logger:trx" + Environment.NewLine,
|
||||
CommandOptionType.MultipleValue);
|
||||
|
||||
var listTestsOption = cmd.Option(
|
||||
"-lt|--listTests",
|
||||
@"Lists discovered tests" + Environment.NewLine,
|
||||
CommandOptionType.NoValue);
|
||||
|
||||
var parentProcessIdOption = cmd.Option(
|
||||
"--parentProcessId <ParentProcessId>",
|
||||
@"Process Id of the Parent Process responsible for launching current process." + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var portOption = cmd.Option(
|
||||
"--port <Port>",
|
||||
@"The Port for socket connection and receiving the event messages." + Environment.NewLine,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
cmd.OnExecute(() =>
|
||||
{
|
||||
var msbuildArgs = new List<string>()
|
||||
{
|
||||
"/t:VSTest"
|
||||
};
|
||||
|
||||
msbuildArgs.Add("/verbosity:quiet");
|
||||
msbuildArgs.Add("/nologo");
|
||||
|
||||
if (settingOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestSetting={settingOption.Value()}");
|
||||
}
|
||||
|
||||
if (testsOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestTests={testsOption.Value()}");
|
||||
}
|
||||
|
||||
if (testAdapterPathOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestTestAdapterPath={testAdapterPathOption.Value()}");
|
||||
}
|
||||
|
||||
if (platformOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestPlatform={platformOption.Value()}");
|
||||
}
|
||||
|
||||
if (frameworkOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestFramework={frameworkOption.Value()}");
|
||||
}
|
||||
|
||||
if (testCaseFilterOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestTestCaseFilter={testCaseFilterOption.Value()}");
|
||||
}
|
||||
|
||||
if (loggerOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestLogger={string.Join(";", loggerOption.Values)}");
|
||||
}
|
||||
|
||||
if (listTestsOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestListTests=true");
|
||||
}
|
||||
|
||||
if (parentProcessIdOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestParentProcessId={parentProcessIdOption.Value()}");
|
||||
}
|
||||
|
||||
if (portOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestPort={portOption.Value()}");
|
||||
}
|
||||
|
||||
string defaultproject = GetSingleTestProjectToRunTestIfNotProvided(argRoot.Value, cmd.RemainingArguments);
|
||||
|
||||
if(!string.IsNullOrEmpty(defaultproject))
|
||||
{
|
||||
msbuildArgs.Add(defaultproject);
|
||||
}
|
||||
|
||||
msbuildArgs.Add(argRoot.Value);
|
||||
|
||||
// Add remaining arguments that the parser did not understand,
|
||||
msbuildArgs.AddRange(cmd.RemainingArguments);
|
||||
|
||||
return new MSBuildForwardingApp(msbuildArgs).Execute();
|
||||
});
|
||||
|
||||
return cmd.Execute(args);
|
||||
}
|
||||
|
||||
private static string GetSingleTestProjectToRunTestIfNotProvided(string args, List<string> remainingArguments)
|
||||
{
|
||||
string result = string.Empty;
|
||||
int projectFound = NumberOfTestProjectInRemainingArgs(remainingArguments) + NumberOfTestProjectArgsRoot(args);
|
||||
|
||||
if (projectFound > 1)
|
||||
{
|
||||
throw new GracefulException(
|
||||
$"Specify a single project file to run tests from.");
|
||||
}
|
||||
else if (projectFound == 0)
|
||||
{
|
||||
result = GetDefaultTestProject();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int NumberOfTestProjectArgsRoot(string args)
|
||||
{
|
||||
Regex pattern = new Regex(@"^.*\..*proj$");
|
||||
|
||||
if (!string.IsNullOrEmpty(args))
|
||||
{
|
||||
return pattern.IsMatch(args) ? 1 : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int NumberOfTestProjectInRemainingArgs(List<string> remainingArguments)
|
||||
{
|
||||
int count = 0;
|
||||
if (remainingArguments.Count != 0)
|
||||
{
|
||||
Regex pattern = new Regex(@"^.*\..*proj$");
|
||||
|
||||
foreach (var x in remainingArguments)
|
||||
{
|
||||
if (pattern.IsMatch(x))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private static string GetDefaultTestProject()
|
||||
{
|
||||
string directory = Directory.GetCurrentDirectory();
|
||||
string[] projectFiles = Directory.GetFiles(directory, "*.*proj");
|
||||
|
||||
if (projectFiles.Length == 0)
|
||||
{
|
||||
throw new GracefulException(
|
||||
$"Couldn't find a project to run test from. Ensure a project exists in {directory}." + Environment.NewLine +
|
||||
"Or pass the path to the project");
|
||||
}
|
||||
else if (projectFiles.Length > 1)
|
||||
{
|
||||
throw new GracefulException(
|
||||
$"Specify which project file to use because this '{directory}' contains more than one project file.");
|
||||
}
|
||||
|
||||
return projectFiles[0];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public sealed class Test3Command : TestCommand
|
||||
{
|
||||
public Test3Command()
|
||||
: base("dotnet")
|
||||
{
|
||||
}
|
||||
|
||||
public override CommandResult Execute(string args = "")
|
||||
{
|
||||
args = $"test3 {args}";
|
||||
return base.Execute(args);
|
||||
}
|
||||
|
||||
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||
{
|
||||
args = $"test3 {args}";
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
}
|
||||
}
|
||||
}
|
39
test/dotnet-test3.Tests/Test3Tests.cs
Normal file
39
test/dotnet-test3.Tests/Test3Tests.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Test3.Tests
|
||||
{
|
||||
public class Test3Tests : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void TestsFromAGivenProjectShouldRunWithExpectedOutput()
|
||||
{
|
||||
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
|
||||
string testAppName = "VSTestDotNetCoreProject";
|
||||
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
|
||||
|
||||
string testProjectDirectory = testInstance.TestRoot;
|
||||
|
||||
// Restore project VSTestDotNetCoreProject
|
||||
new Restore3Command()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
// Call test3
|
||||
CommandResult result = new Test3Command().WithWorkingDirectory(testProjectDirectory).ExecuteWithCapturedOutput("/p:TargetFramework=netcoreapp1.0");
|
||||
|
||||
// Verify
|
||||
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
|
||||
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
|
||||
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
|
||||
}
|
||||
}
|
||||
}
|
21
test/dotnet-test3.Tests/dotnet-test3.Tests.xproj
Normal file
21
test/dotnet-test3.Tests/dotnet-test3.Tests.xproj
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>90236a80-4b84-41d3-a161-aa20709776b1</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Cli.Test3.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
24
test/dotnet-test3.Tests/project.json
Normal file
24
test/dotnet-test3.Tests/project.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": {
|
||||
"target": "project"
|
||||
},
|
||||
"xunit": "2.2.0-beta3-build3330",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-330423-54"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"testRunner": "xunit"
|
||||
}
|
Loading…
Reference in a new issue