2016-02-10 19:16:23 +00:00
|
|
|
|
// 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;
|
2016-04-06 22:29:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-12-13 22:15:35 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-02-10 19:16:23 +00:00
|
|
|
|
using System.IO;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using FluentAssertions;
|
2016-02-10 19:16:23 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-08-10 06:30:12 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-02-10 19:16:23 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
using Microsoft.DotNet.InternalAbstractions;
|
2016-02-10 19:16:23 +00:00
|
|
|
|
using Xunit;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
using Xunit.Abstractions;
|
2016-12-20 20:15:33 +00:00
|
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.Build.Evaluation;
|
2017-05-05 20:13:18 +00:00
|
|
|
|
using System.Xml.Linq;
|
2016-02-10 19:16:23 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tests
|
|
|
|
|
{
|
|
|
|
|
public class PackagedCommandTests : TestBase
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
|
|
|
|
|
|
public PackagedCommandTests(ITestOutputHelper output)
|
|
|
|
|
{
|
|
|
|
|
_output = output;
|
|
|
|
|
}
|
2016-02-10 19:16:23 +00:00
|
|
|
|
|
2016-05-08 21:20:34 +00:00
|
|
|
|
public static IEnumerable<object[]> DependencyToolArguments
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-10 16:52:39 +00:00
|
|
|
|
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var projectOutputPath = $"AppWithProjTool2Fx\\bin\\Debug\\net451\\{rid}\\dotnet-desktop-and-portable.exe";
|
2016-05-08 21:20:34 +00:00
|
|
|
|
return new[]
|
|
|
|
|
{
|
2017-02-07 18:08:14 +00:00
|
|
|
|
new object[] { "CoreFX", ".NETCoreApp,Version=v1.0", "lib\\netcoreapp1.0\\dotnet-desktop-and-portable.dll" },
|
|
|
|
|
new object[] { "NetFX", ".NETFramework,Version=v4.5.1", projectOutputPath }
|
2016-05-08 21:20:34 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static IEnumerable<object[]> LibraryDependencyToolArguments
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-10 16:52:39 +00:00
|
|
|
|
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
var projectOutputPath = $"LibWithProjTool2Fx\\bin\\Debug\\net451\\dotnet-desktop-and-portable.exe";
|
|
|
|
|
|
2016-05-08 21:20:34 +00:00
|
|
|
|
return new[]
|
|
|
|
|
{
|
2017-02-07 18:08:14 +00:00
|
|
|
|
new object[] { "CoreFX", ".NETStandard,Version=v1.6", "lib\\netstandard1.6\\dotnet-desktop-and-portable.dll" },
|
|
|
|
|
new object[] { "NetFX", ".NETFramework,Version=v4.5.1", projectOutputPath }
|
2016-05-08 21:20:34 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-10 19:16:23 +00:00
|
|
|
|
[Theory]
|
2017-02-02 00:35:52 +00:00
|
|
|
|
[InlineData("AppWithDirectAndToolDep", true)]
|
|
|
|
|
[InlineData("AppWithToolDependency", false)]
|
|
|
|
|
public void TestProjectToolIsAvailableThroughDriver(string appName, bool useCurrentFrameworkRuntimeVersion)
|
2016-02-10 19:16:23 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get(appName)
|
2016-10-31 23:16:07 +00:00
|
|
|
|
.CreateInstance()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.WithSourceFiles()
|
2017-02-13 21:06:30 +00:00
|
|
|
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
2016-08-10 06:30:12 +00:00
|
|
|
|
|
2017-02-02 00:35:52 +00:00
|
|
|
|
if (useCurrentFrameworkRuntimeVersion)
|
|
|
|
|
{
|
|
|
|
|
testInstance = testInstance.UseCurrentRuntimeFrameworkVersion();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 21:06:30 +00:00
|
|
|
|
// restore again now that the project has changed
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(testInstance.Root)
|
2016-02-10 19:16:23 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new PortableCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
2016-12-13 22:15:35 +00:00
|
|
|
|
.Should().HaveStdOutContaining("Hello Portable World!")
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.And.NotHaveStdErr()
|
|
|
|
|
.And.Pass();
|
2016-02-10 19:16:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 17:03:45 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(true)]
|
|
|
|
|
[InlineData(false)]
|
|
|
|
|
public void IfPreviousVersionOfSharedFrameworkIsNotInstalled_ToolsTargetingItFail(bool toolPrefersCLIRuntime)
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("AppWithToolDependency")
|
|
|
|
|
.CreateInstance(identifier: toolPrefersCLIRuntime ? "preferCLIRuntime" : "")
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
|
|
|
|
|
|
|
|
|
testInstance = testInstance.WithProjectChanges(project =>
|
|
|
|
|
{
|
|
|
|
|
var ns = project.Root.Name.Namespace;
|
|
|
|
|
|
|
|
|
|
var toolReference = project.Descendants(ns + "DotNetCliToolReference")
|
|
|
|
|
.Where(tr => tr.Attribute("Include").Value == "dotnet-portable")
|
|
|
|
|
.Single();
|
|
|
|
|
|
|
|
|
|
toolReference.Attribute("Include").Value =
|
|
|
|
|
toolPrefersCLIRuntime ? "dotnet-portable-v1-prefercli" : "dotnet-portable-v1";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testInstance = testInstance.WithRestoreFiles();
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new GenericCommand(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1")
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RequiresSpecificFrameworkTheory("netcoreapp1.1")]
|
|
|
|
|
[InlineData(true)]
|
|
|
|
|
[InlineData(false)]
|
|
|
|
|
public void IfPreviousVersionOfSharedFrameworkIsInstalled_ToolsTargetingItRun(bool toolPrefersCLIRuntime)
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("AppWithToolDependency")
|
|
|
|
|
.CreateInstance(identifier: toolPrefersCLIRuntime ? "preferCLIRuntime" : "")
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
|
|
|
|
|
|
|
|
|
testInstance = testInstance.WithProjectChanges(project =>
|
|
|
|
|
{
|
|
|
|
|
var ns = project.Root.Name.Namespace;
|
|
|
|
|
|
|
|
|
|
var toolReference = project.Descendants(ns + "DotNetCliToolReference")
|
|
|
|
|
.Where(tr => tr.Attribute("Include").Value == "dotnet-portable")
|
|
|
|
|
.Single();
|
|
|
|
|
|
|
|
|
|
toolReference.Attribute("Include").Value =
|
|
|
|
|
toolPrefersCLIRuntime ? "dotnet-portable-v1-prefercli" : "dotnet-portable-v1";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testInstance = testInstance.WithRestoreFiles();
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var result =
|
|
|
|
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1");
|
|
|
|
|
|
|
|
|
|
result.Should().Pass()
|
2017-05-09 19:12:47 +00:00
|
|
|
|
.And.HaveStdOutContaining("I'm running on shared framework version 1.1.2!");
|
2017-04-25 17:03:45 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 20:13:18 +00:00
|
|
|
|
[RequiresSpecificFrameworkFact("netcoreapp1.1")]
|
|
|
|
|
public void IfAToolHasNotBeenRestoredForNetCoreApp2_0ItFallsBackToNetCoreApp1_x()
|
|
|
|
|
{
|
|
|
|
|
string toolName = "dotnet-portable-v1";
|
|
|
|
|
|
|
|
|
|
var toolFolder = Path.Combine(new RepoDirectoriesProvider().NugetPackages,
|
|
|
|
|
".tools",
|
|
|
|
|
toolName);
|
|
|
|
|
|
2017-08-18 22:36:01 +00:00
|
|
|
|
// Other tests may have restored the tool for netcoreapp2.1, so delete its tools folder
|
2017-05-05 20:13:18 +00:00
|
|
|
|
if (Directory.Exists(toolFolder))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(toolFolder, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var testInstance = TestAssets.Get("AppWithToolDependency")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
|
|
|
|
|
|
|
|
|
testInstance = testInstance.WithProjectChanges(project =>
|
|
|
|
|
{
|
|
|
|
|
var ns = project.Root.Name.Namespace;
|
|
|
|
|
|
|
|
|
|
// Remove reference to tool that won't restore on 1.x
|
|
|
|
|
project.Descendants(ns + "DotNetCliToolReference")
|
|
|
|
|
.Where(tr => tr.Attribute("Include").Value == "dotnet-PreferCliRuntime")
|
|
|
|
|
.Remove();
|
|
|
|
|
|
|
|
|
|
var toolReference = project.Descendants(ns + "DotNetCliToolReference")
|
|
|
|
|
.Where(tr => tr.Attribute("Include").Value == "dotnet-portable")
|
|
|
|
|
.Single();
|
|
|
|
|
|
|
|
|
|
toolReference.Attribute("Include").Value = toolName;
|
|
|
|
|
|
|
|
|
|
// Restore tools for .NET Core 1.1
|
|
|
|
|
project.Root.Element(ns + "PropertyGroup")
|
|
|
|
|
.Add(new XElement(ns + "DotnetCliToolTargetFramework", "netcoreapp1.1"));
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testInstance = testInstance.WithRestoreFiles();
|
|
|
|
|
|
|
|
|
|
var result =
|
|
|
|
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute("portable-v1");
|
|
|
|
|
|
|
|
|
|
result.Should().Pass()
|
2017-05-09 19:12:47 +00:00
|
|
|
|
.And.HaveStdOutContaining("I'm running on shared framework version 1.1.2!");
|
2017-05-05 20:13:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 23:05:53 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CanInvokeToolWhosePackageNameIsDifferentFromDllName()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("AppWithDepOnToolWithOutputName")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2016-08-10 06:30:12 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(testInstance.Root)
|
2016-04-20 23:05:53 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new GenericCommand("tool-with-output-name")
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
|
.Should().HaveStdOutContaining("Tool with output name!")
|
|
|
|
|
.And.NotHaveStdErr()
|
|
|
|
|
.And.Pass();
|
2016-04-20 23:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 18:20:37 +00:00
|
|
|
|
[Fact]
|
2016-04-20 23:05:53 +00:00
|
|
|
|
public void CanInvokeToolFromDirectDependenciesIfPackageNameDifferentFromToolName()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("AppWithDirectDepWithOutputName")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2017-08-19 01:07:14 +00:00
|
|
|
|
|
|
|
|
|
string framework = Tools.Tests.Utilities.NuGetFrameworks.NetCoreApp21.DotNetFrameworkName;
|
2016-04-20 23:05:53 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(testInstance.Root)
|
|
|
|
|
.WithConfiguration("Debug")
|
2016-04-20 23:05:53 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
2017-04-07 23:36:23 +00:00
|
|
|
|
new DependencyToolInvokerCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.WithEnvironmentVariable(CommandContext.Variables.Verbose, "true")
|
|
|
|
|
.ExecuteWithCapturedOutput($"tool-with-output-name", framework, "")
|
|
|
|
|
.Should().HaveStdOutContaining("Tool with output name!")
|
|
|
|
|
.And.NotHaveStdErr()
|
|
|
|
|
.And.Pass();
|
2016-04-20 23:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 22:00:25 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItShowsErrorWhenToolIsNotRestored()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("NonRestoredTestProjects", "AppWithNonExistingToolDependency")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
new TestCommand("dotnet")
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput("nonexistingtool")
|
|
|
|
|
.Should().Fail()
|
2017-06-13 00:31:40 +00:00
|
|
|
|
.And.HaveStdErrContaining(string.Format(LocalizableStrings.NoExecutableFoundMatchingCommand, "dotnet-nonexistingtool"));
|
2016-12-19 22:00:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 20:15:33 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItRunsToolRestoredToSpecificPackageDir()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("NonRestoredTestProjects", "ToolWithRandomPackageName")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var appWithDepOnToolDir = testInstance.Root.Sub("AppWithDepOnTool");
|
|
|
|
|
var toolWithRandPkgNameDir = testInstance.Root.Sub("ToolWithRandomPackageName");
|
|
|
|
|
var pkgsDir = testInstance.Root.CreateSubdirectory("pkgs");
|
|
|
|
|
|
2016-12-20 21:53:21 +00:00
|
|
|
|
// 3ebdd4f1-a194-470a-b01a-4515672791d1
|
|
|
|
|
// ^-- index = 24
|
|
|
|
|
string randomPackageName = Guid.NewGuid().ToString().Substring(24);
|
2016-12-20 20:15:33 +00:00
|
|
|
|
|
|
|
|
|
// TODO: This is a workround for https://github.com/dotnet/cli/issues/5020
|
|
|
|
|
SetGeneratedPackageName(appWithDepOnToolDir.GetFile("AppWithDepOnTool.csproj"),
|
|
|
|
|
randomPackageName);
|
|
|
|
|
|
|
|
|
|
SetGeneratedPackageName(toolWithRandPkgNameDir.GetFile("ToolWithRandomPackageName.csproj"),
|
|
|
|
|
randomPackageName);
|
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(toolWithRandPkgNameDir)
|
2016-12-20 21:53:21 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-12-20 20:15:33 +00:00
|
|
|
|
|
|
|
|
|
new PackCommand()
|
|
|
|
|
.WithWorkingDirectory(toolWithRandPkgNameDir)
|
2016-12-20 21:53:21 +00:00
|
|
|
|
.Execute($"-o \"{pkgsDir.FullName}\"")
|
|
|
|
|
.Should().Pass();
|
2016-12-20 20:15:33 +00:00
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(appWithDepOnToolDir)
|
2016-12-20 21:53:21 +00:00
|
|
|
|
.Execute($"--packages \"{pkgsDir.FullName}\"")
|
|
|
|
|
.Should().Pass();
|
2016-12-20 20:15:33 +00:00
|
|
|
|
|
|
|
|
|
new TestCommand("dotnet")
|
|
|
|
|
.WithWorkingDirectory(appWithDepOnToolDir)
|
|
|
|
|
.ExecuteWithCapturedOutput("randompackage")
|
|
|
|
|
.Should().Pass()
|
|
|
|
|
.And.HaveStdOutContaining("Hello World from tool!")
|
|
|
|
|
.And.NotHaveStdErr();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 18:08:14 +00:00
|
|
|
|
[WindowsOnlyTheory(Skip="https://github.com/dotnet/cli/issues/4514")]
|
|
|
|
|
[MemberData("DependencyToolArguments")]
|
|
|
|
|
public void TestFrameworkSpecificDependencyToolsCanBeInvoked(string identifier, string framework, string expectedDependencyToolPath)
|
2016-03-28 08:15:09 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx")
|
|
|
|
|
.CreateInstance(identifier: identifier)
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2016-03-28 08:15:09 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.WithConfiguration("Debug")
|
2016-03-28 08:15:09 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new DependencyToolInvokerCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput($"desktop-and-portable {framework} {identifier}")
|
|
|
|
|
.Should().HaveStdOutContaining(framework)
|
|
|
|
|
.And.HaveStdOutContaining(identifier)
|
|
|
|
|
.And.HaveStdOutContaining(expectedDependencyToolPath)
|
|
|
|
|
.And.NotHaveStdErr()
|
|
|
|
|
.And.Pass();
|
2016-03-28 08:15:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 18:08:14 +00:00
|
|
|
|
[WindowsOnlyTheory]
|
2016-05-08 21:20:34 +00:00
|
|
|
|
[MemberData("LibraryDependencyToolArguments")]
|
2017-02-07 18:08:14 +00:00
|
|
|
|
public void TestFrameworkSpecificLibraryDependencyToolsCannotBeInvoked(string identifier, string framework, string expectedDependencyToolPath)
|
2016-05-08 21:20:34 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "LibWithProjTool2Fx")
|
|
|
|
|
.CreateInstance(identifier: identifier)
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2016-05-08 21:20:34 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.WithConfiguration("Debug")
|
2016-05-08 21:20:34 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
2016-05-08 21:20:34 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new DependencyToolInvokerCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput($"desktop-and-portable {framework} {identifier}")
|
|
|
|
|
.Should().Fail();
|
2016-05-08 21:20:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 18:20:37 +00:00
|
|
|
|
[Fact]
|
2016-04-08 22:33:32 +00:00
|
|
|
|
public void ToolsCanAccessDependencyContextProperly()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("DependencyContextFromTool")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
2017-04-07 23:36:23 +00:00
|
|
|
|
new DependencyContextTestCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute("")
|
|
|
|
|
.Should().Pass();
|
2016-04-08 22:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-03 23:31:04 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestProjectDependencyIsNotAvailableThroughDriver()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("AppWithDirectDep")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
2017-02-13 21:06:30 +00:00
|
|
|
|
.UseCurrentRuntimeFrameworkVersion()
|
|
|
|
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
2017-02-02 00:35:52 +00:00
|
|
|
|
|
|
|
|
|
// restore again now that the project has changed
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
2016-03-03 23:31:04 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
2016-03-03 23:31:04 +00:00
|
|
|
|
|
|
|
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
CommandResult result = new HelloCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput();
|
2016-03-03 23:31:04 +00:00
|
|
|
|
|
2017-06-13 00:31:40 +00:00
|
|
|
|
result.StdErr.Should().Contain(string.Format(LocalizableStrings.NoExecutableFoundMatchingCommand, "dotnet-hello"));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
result.Should().Fail();
|
2016-03-03 23:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 20:14:07 +00:00
|
|
|
|
[Fact(Skip = "https://github.com/dotnet/cli/issues/6144")]
|
2016-12-13 22:15:35 +00:00
|
|
|
|
public void WhenToolAssetsFileIsInUseThenCLIRetriesLaunchingTheCommandForAtLeastOneSecond()
|
2016-11-09 07:23:13 +00:00
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("AppWithToolDependency")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
2016-12-13 22:15:35 +00:00
|
|
|
|
var assetsFile = new DirectoryInfo(new RepoDirectoriesProvider().NugetPackages)
|
2017-08-18 22:36:01 +00:00
|
|
|
|
.GetDirectory(".tools", "dotnet-portable", "1.0.0", "netcoreapp2.1")
|
2016-12-13 22:15:35 +00:00
|
|
|
|
.GetFile("project.assets.json");
|
|
|
|
|
|
|
|
|
|
var stopWatch = Stopwatch.StartNew();
|
2016-11-09 07:23:13 +00:00
|
|
|
|
|
|
|
|
|
using (assetsFile.Lock()
|
|
|
|
|
.DisposeAfter(TimeSpan.FromMilliseconds(1000)))
|
|
|
|
|
{
|
|
|
|
|
new PortableCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
2016-12-13 22:15:35 +00:00
|
|
|
|
.Should().HaveStdOutContaining("Hello Portable World!")
|
2016-11-09 07:23:13 +00:00
|
|
|
|
.And.NotHaveStdErr()
|
|
|
|
|
.And.Pass();
|
|
|
|
|
}
|
2016-12-13 22:15:35 +00:00
|
|
|
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
|
|
|
|
stopWatch.ElapsedMilliseconds.Should().BeGreaterThan(1000, "Because dotnet should respect the NuGet lock");
|
2016-11-09 07:23:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-11 01:11:32 +00:00
|
|
|
|
[Fact(Skip="https://github.com/dotnet/cli/issues/6006")]
|
2016-12-13 22:15:35 +00:00
|
|
|
|
public void WhenToolAssetsFileIsLockedByNuGetThenCLIRetriesLaunchingTheCommandForAtLeastOneSecond()
|
2016-11-09 07:23:13 +00:00
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("AppWithToolDependency")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
2016-12-13 22:15:35 +00:00
|
|
|
|
var assetsFile = new DirectoryInfo(new RepoDirectoriesProvider().NugetPackages)
|
2017-03-03 07:43:06 +00:00
|
|
|
|
.GetDirectory(".tools", "dotnet-portable", "1.0.0", "netcoreapp1.0")
|
2016-12-13 22:15:35 +00:00
|
|
|
|
.GetFile("project.assets.json");
|
|
|
|
|
|
|
|
|
|
var stopWatch = Stopwatch.StartNew();
|
2016-11-09 07:23:13 +00:00
|
|
|
|
|
|
|
|
|
using (assetsFile.NuGetLock()
|
|
|
|
|
.DisposeAfter(TimeSpan.FromMilliseconds(1000)))
|
|
|
|
|
{
|
|
|
|
|
new PortableCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
2016-12-13 22:15:35 +00:00
|
|
|
|
.Should().HaveStdOutContaining("Hello Portable World!")
|
2016-11-09 07:23:13 +00:00
|
|
|
|
.And.NotHaveStdErr()
|
|
|
|
|
.And.Pass();
|
|
|
|
|
}
|
2016-12-13 22:15:35 +00:00
|
|
|
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
|
|
|
|
stopWatch.ElapsedMilliseconds.Should().BeGreaterThan(1000, "Because dotnet should respect the NuGet lock");
|
2016-11-09 07:23:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 20:15:33 +00:00
|
|
|
|
private void SetGeneratedPackageName(FileInfo project, string packageName)
|
|
|
|
|
{
|
|
|
|
|
const string propertyName = "GeneratedPackageId";
|
|
|
|
|
var p = ProjectRootElement.Open(project.FullName, new ProjectCollection(), true);
|
|
|
|
|
p.AddProperty(propertyName, packageName);
|
|
|
|
|
p.Save();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 21:55:56 +00:00
|
|
|
|
class HelloCommand : DotnetCommand
|
2016-02-10 19:16:23 +00:00
|
|
|
|
{
|
|
|
|
|
public HelloCommand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-17 18:43:17 +00:00
|
|
|
|
|
2017-03-21 21:55:56 +00:00
|
|
|
|
class PortableCommand : DotnetCommand
|
2016-03-17 18:43:17 +00:00
|
|
|
|
{
|
|
|
|
|
public PortableCommand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult Execute(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"portable {args}";
|
|
|
|
|
return base.Execute(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"portable {args}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-28 08:15:09 +00:00
|
|
|
|
|
2017-03-21 21:55:56 +00:00
|
|
|
|
class GenericCommand : DotnetCommand
|
2016-04-20 23:05:53 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly string _commandName;
|
|
|
|
|
|
|
|
|
|
public GenericCommand(string commandName)
|
|
|
|
|
{
|
|
|
|
|
_commandName = commandName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult Execute(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"{_commandName} {args}";
|
|
|
|
|
return base.Execute(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"{_commandName} {args}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 21:55:56 +00:00
|
|
|
|
class DependencyContextTestCommand : DotnetCommand
|
2016-04-08 22:33:32 +00:00
|
|
|
|
{
|
2017-04-06 20:43:26 +00:00
|
|
|
|
public DependencyContextTestCommand(string dotnetUnderTest) : base(dotnetUnderTest)
|
2016-04-08 22:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult Execute(string path)
|
|
|
|
|
{
|
|
|
|
|
var args = $"dependency-context-test {path}";
|
|
|
|
|
return base.Execute(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string path)
|
|
|
|
|
{
|
|
|
|
|
var args = $"dependency-context-test {path}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-10 19:16:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|