2015-12-15 01:39:29 +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.
|
|
|
|
|
|
2016-01-11 21:40:47 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
using System.IO;
|
2016-01-11 21:40:47 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2016-02-20 00:48:43 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-02-10 08:16:40 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2015-12-19 00:39:43 +00:00
|
|
|
|
using Microsoft.Extensions.PlatformAbstractions;
|
2016-01-11 21:40:47 +00:00
|
|
|
|
using Xunit;
|
2016-01-30 01:37:08 +00:00
|
|
|
|
using System;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Publish.Tests
|
|
|
|
|
{
|
|
|
|
|
public class PublishTests : TestBase
|
|
|
|
|
{
|
2016-01-29 00:16:50 +00:00
|
|
|
|
private readonly string _testProjectsRoot;
|
2016-02-13 00:57:32 +00:00
|
|
|
|
private readonly Func<string, string, string> _getProjectJson = ProjectUtils.GetProjectJson;
|
2016-01-29 00:16:50 +00:00
|
|
|
|
|
|
|
|
|
public PublishTests()
|
|
|
|
|
{
|
2016-02-10 08:16:40 +00:00
|
|
|
|
_testProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "TestProjects");
|
2016-01-29 00:16:50 +00:00
|
|
|
|
}
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<object[]> PublishOptions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
2016-02-10 08:16:40 +00:00
|
|
|
|
new object[] { "1", "", "", "", "" },
|
2016-03-01 23:35:32 +00:00
|
|
|
|
new object[] { "2", "netstandardapp1.5", "", "", "" },
|
2016-02-10 08:16:40 +00:00
|
|
|
|
new object[] { "3", "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" },
|
|
|
|
|
new object[] { "4", "", "", "Release", "" },
|
|
|
|
|
new object[] { "5", "", "", "", "some/dir"},
|
|
|
|
|
new object[] { "6", "", "", "", "some/dir/with spaces" },
|
2016-03-01 23:35:32 +00:00
|
|
|
|
new object[] { "7", "netstandardapp1.5", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" },
|
2015-12-15 01:39:29 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[MemberData("PublishOptions")]
|
2016-02-10 08:16:40 +00:00
|
|
|
|
public void PublishOptionsTest(string testIdentifier, string framework, string runtime, string config, string outputDir)
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-02-11 22:17:20 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifier)
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
string testRoot = _getProjectJson(instance.TestRoot, "TestApp");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2016-02-10 08:16:40 +00:00
|
|
|
|
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testRoot, output: outputDir);
|
2015-12-15 01:39:29 +00:00
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
// verify the output executable generated
|
|
|
|
|
var publishedDir = publishCommand.GetOutputDirectory();
|
|
|
|
|
var outputExe = publishCommand.GetOutputExecutable();
|
|
|
|
|
var outputPdb = Path.ChangeExtension(outputExe, "pdb");
|
|
|
|
|
|
|
|
|
|
// lets make sure that the output exe is runnable
|
|
|
|
|
var outputExePath = Path.Combine(publishedDir.FullName, publishCommand.GetOutputExecutable());
|
|
|
|
|
var command = new TestCommand(outputExePath);
|
|
|
|
|
command.Execute("").Should().ExitWith(100);
|
|
|
|
|
|
|
|
|
|
// the pdb should also be published
|
|
|
|
|
publishedDir.Should().HaveFile(outputPdb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ProjectWithContentsTest()
|
|
|
|
|
{
|
2016-02-11 22:17:20 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithContents")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "TestAppWithContents");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
|
2016-02-10 08:16:40 +00:00
|
|
|
|
publishCommand.Execute().Should().Pass();
|
2016-01-11 21:40:47 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("testcontentfile.txt");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2016-01-30 01:37:08 +00:00
|
|
|
|
public void FailWhenNoRestoreTest()
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-02-11 22:17:20 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
string testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-02 01:49:36 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("centos.7-x64", "", new string[] { "libhostfxr.so", "libcoreclr.so", "libhostpolicy.so" })]
|
|
|
|
|
[InlineData("rhel.7.2-x64", "", new string[] { "libhostfxr.so", "libcoreclr.so", "libhostpolicy.so" })]
|
|
|
|
|
[InlineData("ubuntu.14.04-x64", "", new string[] { "libhostfxr.so", "libcoreclr.so", "libhostpolicy.so" })]
|
|
|
|
|
[InlineData("win7-x64", ".exe", new string[] { "hostfxr.dll", "coreclr.dll", "hostpolicy.dll" })]
|
|
|
|
|
[InlineData("osx.10.11-x64", "", new string[] { "libhostfxr.dylib", "libcoreclr.dylib", "libhostpolicy.dylib" })]
|
|
|
|
|
public void CrossPublishingSucceedsAndHasExpectedArtifacts(string rid, string hostExtension, string[] expectedArtifacts)
|
|
|
|
|
{
|
|
|
|
|
var testNugetCache = "packages_cross_publish_test";
|
|
|
|
|
TestInstance instance = GetTestGroupTestAssetsManager("CrossPublishTestProjects")
|
|
|
|
|
.CreateTestInstance("StandaloneAppCrossPublish");
|
|
|
|
|
|
|
|
|
|
var testProject = Path.Combine(instance.TestRoot, "project.json");
|
|
|
|
|
|
|
|
|
|
var restoreCommand = new RestoreCommand();
|
|
|
|
|
|
|
|
|
|
restoreCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
|
|
|
|
|
restoreCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
|
|
|
|
|
restoreCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var buildCommand = new BuildCommand(testProject, runtime: rid);
|
|
|
|
|
|
|
|
|
|
buildCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
|
|
|
|
|
buildCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var publishCommand = new PublishCommand(testProject, runtime: rid, noBuild: true);
|
|
|
|
|
publishCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
|
|
|
|
|
publishCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var publishedDir = publishCommand.GetOutputDirectory();
|
|
|
|
|
publishedDir.Should().HaveFile("StandaloneAppCrossPublish"+ hostExtension);
|
|
|
|
|
|
|
|
|
|
foreach (var artifact in expectedArtifacts)
|
|
|
|
|
{
|
|
|
|
|
publishedDir.Should().HaveFile(artifact);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 19:36:26 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void PublishesWhenPrebuildWithBuildBasePath()
|
|
|
|
|
{
|
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
string basePath = Path.Combine(instance.TestRoot, "build");
|
|
|
|
|
string testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
|
|
|
|
var buildCommand = new BuildCommand(testProject, buildBasePath: basePath);
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var publishCommand = new PublishCommand(testProject, buildBasePath: basePath, noBuild: true);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void LibraryPublishTest()
|
|
|
|
|
{
|
2016-02-13 00:57:32 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary"))
|
2016-02-11 22:17:20 +00:00
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "TestLibrary");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibrary.exe");
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibrary.dll");
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibrary.pdb");
|
|
|
|
|
// dependencies should also be copied
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("System.Runtime.dll");
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 23:02:26 +00:00
|
|
|
|
[WindowsOnlyFact]
|
2016-01-30 01:37:08 +00:00
|
|
|
|
public void TestLibraryBindingRedirectGeneration()
|
2016-01-12 23:02:26 +00:00
|
|
|
|
{
|
2016-02-11 22:17:20 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestBindingRedirectGeneration")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2016-01-12 23:02:26 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
var lesserTestProject = _getProjectJson(instance.TestRoot, "TestLibraryLesser");
|
2016-01-12 23:02:26 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
var publishCommand = new PublishCommand(lesserTestProject, "net451");
|
2016-01-12 23:02:26 +00:00
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll.config");
|
2016-03-09 00:46:50 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps.json");
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2016-01-12 23:02:26 +00:00
|
|
|
|
// dependencies should also be copied
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
|
2016-01-14 22:52:19 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Delete(true);
|
|
|
|
|
|
2016-03-01 23:35:32 +00:00
|
|
|
|
publishCommand = new PublishCommand(lesserTestProject, "netstandardapp1.5", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier());
|
2016-01-14 22:52:19 +00:00
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.dll.config");
|
2016-03-09 00:46:50 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps.json");
|
2016-01-30 08:20:09 +00:00
|
|
|
|
|
2016-01-14 22:52:19 +00:00
|
|
|
|
// dependencies should also be copied
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
|
2016-01-12 23:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-22 00:40:33 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void RefsPublishTest()
|
|
|
|
|
{
|
2016-02-11 22:17:20 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2016-01-22 00:40:33 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
2016-01-22 00:40:33 +00:00
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
2016-02-10 08:16:40 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestApp.dll");
|
2016-01-22 00:40:33 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibrary.dll");
|
|
|
|
|
|
|
|
|
|
var refsDirectory = new DirectoryInfo(Path.Combine(publishCommand.GetOutputDirectory().FullName, "refs"));
|
|
|
|
|
// Should have compilation time assemblies
|
|
|
|
|
refsDirectory.Should().HaveFile("System.IO.dll");
|
|
|
|
|
// Libraries in which lib==ref should be deduped
|
|
|
|
|
refsDirectory.Should().NotHaveFile("TestLibrary.dll");
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CompilationFailedTest()
|
|
|
|
|
{
|
2016-02-11 22:17:20 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("CompileFail")
|
|
|
|
|
.WithLockFiles();
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2016-02-13 00:57:32 +00:00
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "CompileFail");
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
|
|
|
|
|
publishCommand.Execute().Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-29 21:15:26 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void PublishFailsWhenProjectNotBuiltAndNoBuildFlagSet()
|
|
|
|
|
{
|
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
|
|
|
|
var publishCommand = new PublishCommand(testProject, noBuild: true);
|
|
|
|
|
|
|
|
|
|
publishCommand.Execute().Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PublishSucceedsWhenProjectPreviouslyCompiledAndNoBuildFlagSet()
|
|
|
|
|
{
|
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
|
|
|
|
|
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
|
|
|
|
var publishCommand = new PublishCommand(testProject, noBuild: true);
|
|
|
|
|
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 21:40:47 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void PublishScriptsRun()
|
|
|
|
|
{
|
2016-02-13 01:26:58 +00:00
|
|
|
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithScripts")
|
2016-02-11 22:17:20 +00:00
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2016-01-11 21:40:47 +00:00
|
|
|
|
|
2016-02-13 01:26:58 +00:00
|
|
|
|
var testProject = _getProjectJson(instance.TestRoot, "TestAppWithScripts");
|
2016-01-11 21:40:47 +00:00
|
|
|
|
|
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
var result = publishCommand.ExecuteWithCapturedOutput();
|
|
|
|
|
|
2016-03-02 01:42:44 +00:00
|
|
|
|
result.Should().HaveStdOutMatching("\nprepublish_output( \\?[^%]+\\?){5}.+\npostpublish_output( \\?[^%]+\\?){5}", RegexOptions.Singleline);
|
2016-01-11 21:40:47 +00:00
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
2016-03-17 20:46:46 +00:00
|
|
|
|
|
|
|
|
|
public void PublishAppWithOutputAssemblyName()
|
|
|
|
|
{
|
|
|
|
|
TestInstance instance =
|
|
|
|
|
TestAssetsManager
|
|
|
|
|
.CreateTestInstance("AppWithOutputAssemblyName")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
|
|
|
|
|
|
|
|
|
var testRoot = _getProjectJson(instance.TestRoot, "AppWithOutputAssemblyName");
|
|
|
|
|
var publishCommand = new PublishCommand(testRoot, output: testRoot);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var publishedDir = publishCommand.GetOutputDirectory();
|
|
|
|
|
var extension = publishCommand.GetExecutableExtension();
|
|
|
|
|
var outputExe = "MyApp" + extension;
|
|
|
|
|
publishedDir.Should().HaveFiles(new[] { "MyApp.dll", outputExe });
|
|
|
|
|
publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName" + extension);
|
|
|
|
|
publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName.dll");
|
|
|
|
|
|
|
|
|
|
var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe));
|
|
|
|
|
command.Execute("").Should().ExitWith(0);
|
|
|
|
|
}
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
2016-01-11 21:40:47 +00:00
|
|
|
|
}
|