Merge pull request #1452 from dotnet/eerhardt-PackagedCommands
Packaged Command Refactor
This commit is contained in:
commit
0262a174b5
12 changed files with 172 additions and 48 deletions
|
@ -54,6 +54,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-projectmodel-server.
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Files", "src\Microsoft.DotNet.Files\Microsoft.DotNet.Files.xproj", "{D521DD9F-0614-4929-93B4-D8FA5682C174}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet.Tests", "test\dotnet.Tests\dotnet.Tests.xproj", "{CB710268-4A82-48E4-9531-FAF1C8F78F4B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{88278B81-7649-45DC-8A6A-D3A645C5AFC3}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-cli-build", "scripts\dotnet-cli-build\dotnet-cli-build.xproj", "{D7B9695D-23EB-4EA8-B8AB-707A0092E1D5}"
|
||||
|
@ -390,6 +392,22 @@ Global
|
|||
{49BEB486-AB5A-4416-91EA-8CD34ABB0C9D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{49BEB486-AB5A-4416-91EA-8CD34ABB0C9D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{49BEB486-AB5A-4416-91EA-8CD34ABB0C9D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{920B71D8-62DA-4F5E-8A26-926C113F1D97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{920B71D8-62DA-4F5E-8A26-926C113F1D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{920B71D8-62DA-4F5E-8A26-926C113F1D97}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
@ -525,6 +543,7 @@ Global
|
|||
{386D412C-003C-47B1-8258-0E35865CB7C4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{11C77123-E4DA-499F-8900-80C88C2C69F2} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{D521DD9F-0614-4929-93B4-D8FA5682C174} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
|
||||
{CB710268-4A82-48E4-9531-FAF1C8F78F4B} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{D7B9695D-23EB-4EA8-B8AB-707A0092E1D5} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
|
||||
{49BEB486-AB5A-4416-91EA-8CD34ABB0C9D} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
|
||||
{920B71D8-62DA-4F5E-8A26-926C113F1D97} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
public static readonly string[] TestProjects = new[]
|
||||
{
|
||||
"EndToEnd",
|
||||
"dotnet.Tests",
|
||||
"dotnet-publish.Tests",
|
||||
"dotnet-compile.Tests",
|
||||
"dotnet-compile.UnitTests",
|
||||
|
@ -36,11 +37,17 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
[Target(nameof(PrepareTargets.Init), nameof(SetupTests), nameof(RestoreTests), nameof(BuildTests), nameof(RunTests), nameof(ValidateDependencies))]
|
||||
public static BuildTargetResult Test(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(RestoreTestPrerequisites), nameof(BuildTestPrerequisites))]
|
||||
[Target(nameof(SetupTestPackages), nameof(SetupTestProjects))]
|
||||
public static BuildTargetResult SetupTests(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(RestoreTestAssetPackages), nameof(BuildTestAssetPackages))]
|
||||
public static BuildTargetResult SetupTestPackages(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(RestoreTestAssetProjects), nameof(BuildTestAssetProjects))]
|
||||
public static BuildTargetResult SetupTestProjects(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult RestoreTestPrerequisites(BuildTargetContext c)
|
||||
public static BuildTargetResult RestoreTestAssetPackages(BuildTargetContext c)
|
||||
{
|
||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
|
||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
|
||||
|
@ -48,7 +55,23 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
CleanNuGetTempCache();
|
||||
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
dotnet.Restore().WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets")).Execute().EnsureSuccessful();
|
||||
dotnet.Restore().WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages")).Execute().EnsureSuccessful();
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult RestoreTestAssetProjects(BuildTargetContext c)
|
||||
{
|
||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
|
||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
|
||||
|
||||
CleanNuGetTempCache();
|
||||
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
dotnet.Restore("--fallbacksource", Dirs.TestPackages)
|
||||
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"))
|
||||
.Execute().EnsureSuccessful();
|
||||
|
||||
// The 'testapp' directory contains intentionally-unresolved dependencies, so don't check for success. Also, suppress the output
|
||||
dotnet.Restore().WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "testapp")).CaptureStdErr().CaptureStdOut().Execute();
|
||||
|
@ -57,14 +80,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult BuildTestPrerequisites(BuildTargetContext c)
|
||||
{
|
||||
BuildTestAssetPackages(c);
|
||||
BuildTestAssetProjects(c);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static void BuildTestAssetPackages(BuildTargetContext c)
|
||||
public static BuildTargetResult BuildTestAssetPackages(BuildTargetContext c)
|
||||
{
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
|
||||
|
@ -80,9 +96,12 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static void BuildTestAssetProjects(BuildTargetContext c)
|
||||
[Target]
|
||||
public static BuildTargetResult BuildTestAssetProjects(BuildTargetContext c)
|
||||
{
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
|
||||
|
@ -98,6 +117,8 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
|
@ -129,7 +150,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(RunXUnitTests), nameof(RunPackageCommandTests))]
|
||||
[Target(nameof(RunXUnitTests))]
|
||||
public static BuildTargetResult RunTests(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target]
|
||||
|
@ -173,40 +194,6 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult RunPackageCommandTests(BuildTargetContext c)
|
||||
{
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
var consumers = Path.Combine(c.BuildContext.BuildDirectory, "test", "PackagedCommands", "Consumers");
|
||||
|
||||
// Compile the consumer apps
|
||||
foreach (var dir in Directory.EnumerateDirectories(consumers))
|
||||
{
|
||||
dotnet.Build().WorkingDirectory(dir).Execute().EnsureSuccessful();
|
||||
}
|
||||
|
||||
// Test the apps
|
||||
foreach (var dir in Directory.EnumerateDirectories(consumers))
|
||||
{
|
||||
var result = dotnet.Exec("hello").WorkingDirectory(dir)
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.Execute();
|
||||
result.EnsureSuccessful();
|
||||
if (!string.Equals("Hello", result.StdOut.Trim(), StringComparison.Ordinal))
|
||||
{
|
||||
var testName = Path.GetFileName(dir);
|
||||
c.Error($"Packaged Commands Test '{testName}' failed");
|
||||
c.Error($" Expected 'Hello', but got: '{result.StdOut.Trim()}'");
|
||||
return c.Failed($"Packaged Commands Test failed '{testName}'");
|
||||
}
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult ValidateDependencies(BuildTargetContext c)
|
||||
{
|
||||
|
|
|
@ -6,7 +6,6 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public class TestCommand
|
||||
|
|
71
test/dotnet.Tests/PackagedCommandTests.cs
Normal file
71
test/dotnet.Tests/PackagedCommandTests.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
// 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.IO;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tests
|
||||
{
|
||||
public class PackagedCommandTests : TestBase
|
||||
{
|
||||
private readonly string _testProjectsRoot;
|
||||
|
||||
public PackagedCommandTests()
|
||||
{
|
||||
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("AppWithDirectAndToolDependency")]
|
||||
[InlineData("AppWithDirectDependency")]
|
||||
[InlineData("AppWithToolDependency")]
|
||||
public void TestPackagedCommandDependency(string appName)
|
||||
{
|
||||
string appDirectory = Path.Combine(_testProjectsRoot, appName);
|
||||
|
||||
new BuildCommand(Path.Combine(appDirectory, "project.json"))
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var currentDirectory = Directory.GetCurrentDirectory();
|
||||
Directory.SetCurrentDirectory(appDirectory);
|
||||
|
||||
try
|
||||
{
|
||||
CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();
|
||||
|
||||
result.Should().HaveStdOut("Hello" + Environment.NewLine);
|
||||
result.Should().NotHaveStdErr();
|
||||
result.Should().Pass();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.SetCurrentDirectory(currentDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
class HelloCommand : TestCommand
|
||||
{
|
||||
public HelloCommand()
|
||||
: base("dotnet")
|
||||
{
|
||||
}
|
||||
|
||||
public override CommandResult Execute(string args = "")
|
||||
{
|
||||
args = $"hello {args}";
|
||||
return base.Execute(args);
|
||||
}
|
||||
|
||||
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||
{
|
||||
args = $"hello {args}";
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
test/dotnet.Tests/dotnet.Tests.xproj
Normal file
18
test/dotnet.Tests/dotnet.Tests.xproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>cb710268-4a82-48e4-9531-faf1c8f78f4b</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
30
test/dotnet.Tests/project.json
Normal file
30
test/dotnet.Tests/project.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23810",
|
||||
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-48273-16"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
},
|
||||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/AppWithDirectAndToolDependency/**/*",
|
||||
"../../TestAssets/TestProjects/AppWithDirectDependency/**/*",
|
||||
"../../TestAssets/TestProjects/AppWithToolDependency/**/*"
|
||||
],
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
Loading…
Reference in a new issue