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;
|
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;
|
|
|
|
|
|
|
|
|
|
public PublishTests()
|
|
|
|
|
{
|
|
|
|
|
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, @"TestProjects");
|
|
|
|
|
}
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<object[]> PublishOptions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
new object[] { "", "", "", "" },
|
|
|
|
|
new object[] { "dnxcore50", "", "", "" },
|
2015-12-19 00:39:43 +00:00
|
|
|
|
new object[] { "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" },
|
2015-12-15 01:39:29 +00:00
|
|
|
|
new object[] { "", "", "Release", "" },
|
|
|
|
|
new object[] { "", "", "", "some/dir"},
|
2016-01-22 22:05:02 +00:00
|
|
|
|
new object[] { "", "", "", "some/dir/with spaces" },
|
2015-12-19 00:39:43 +00:00
|
|
|
|
new object[] { "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" },
|
2015-12-15 01:39:29 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[MemberData("PublishOptions")]
|
|
|
|
|
public void PublishOptionsTest(string framework, string runtime, string config, string outputDir)
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var testAppDir = root.CreateDirectory("TestApp");
|
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
|
|
|
|
|
|
|
|
|
//copy projects to the temp dir
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
|
|
|
|
|
|
|
|
|
// run publish
|
|
|
|
|
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir);
|
|
|
|
|
var testProject = GetProjectPath(testAppDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testProject, output: outputDir);
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var testDir = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var testAppDir = Path.Combine(_testProjectsRoot, "TestAppWithContents");
|
|
|
|
|
|
|
|
|
|
// copy projects to the temp dir
|
|
|
|
|
CopyProjectToTempDir(testAppDir, testDir);
|
|
|
|
|
|
|
|
|
|
// run publish
|
|
|
|
|
var testProject = GetProjectPath(testDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
// make sure that the output dir has the content files
|
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
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var testAppDir = root.CreateDirectory("TestApp");
|
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
|
|
|
|
|
|
|
|
|
// copy projects to the temp dir
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
File.Delete(Path.Combine(testAppDir.Path, "project.lock.json"));
|
|
|
|
|
File.Delete(Path.Combine(testLibDir.Path, "project.lock.json"));
|
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var testProject = GetProjectPath(testAppDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LibraryPublishTest()
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
|
|
|
|
|
2016-01-11 21:40:47 +00:00
|
|
|
|
//copy projects to the temp dir
|
2015-12-15 01:39:29 +00:00
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
|
|
|
|
|
|
|
|
|
var testProject = GetProjectPath(testLibDir);
|
|
|
|
|
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-01-30 01:37:08 +00:00
|
|
|
|
// Set up Test Staging in Temporary Directory
|
2016-01-12 23:02:26 +00:00
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
root.CopyDirectory(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration"));
|
2016-01-12 23:02:26 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
var testProjectsRootDir = Path.Combine(root.Path, "TestBindingRedirectGeneration");
|
|
|
|
|
var greaterTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryGreater");
|
|
|
|
|
var lesserTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryLesser");
|
2016-01-12 23:02:26 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
var lesserTestProject = Path.Combine(lesserTestLibDir, "project.json");
|
|
|
|
|
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-01-30 05:44:53 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps");
|
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-01-30 01:37:08 +00:00
|
|
|
|
publishCommand = new PublishCommand(lesserTestProject, "dnxcore50", 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-01-30 08:20:09 +00:00
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps");
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2016-01-22 00:40:33 +00:00
|
|
|
|
var testAppDir = root.CreateDirectory("TestAppCompilationContext");
|
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
|
|
|
|
|
|
|
|
|
// copy projects to the temp dir
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
|
|
|
|
|
|
|
|
|
var testProject = GetProjectPath(testAppDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
publishCommand.GetOutputDirectory().Should().HaveFile("TestAppCompilationContext.dll");
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
var testDir = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
var compileFailDir = Path.Combine(_testProjectsRoot, "CompileFail");
|
|
|
|
|
|
|
|
|
|
CopyProjectToTempDir(compileFailDir, testDir);
|
|
|
|
|
|
|
|
|
|
var testProject = GetProjectPath(testDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
|
|
|
|
|
publishCommand.Execute().Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 21:40:47 +00:00
|
|
|
|
[Fact]
|
2016-01-23 00:31:35 +00:00
|
|
|
|
[ActiveIssue(982)]
|
2016-01-11 21:40:47 +00:00
|
|
|
|
public void PublishScriptsRun()
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
2016-01-11 21:40:47 +00:00
|
|
|
|
var testAppDir = root.CreateDirectory("TestApp");
|
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
|
|
|
|
|
|
|
|
|
//copy projects to the temp dir
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
|
|
|
|
|
|
|
|
|
// run publish
|
|
|
|
|
var testProject = GetProjectPath(testAppDir);
|
|
|
|
|
var publishCommand = new PublishCommand(testProject);
|
|
|
|
|
|
|
|
|
|
var result = publishCommand.ExecuteWithCapturedOutput();
|
|
|
|
|
|
|
|
|
|
result.Should().StdOutMatchPattern("\nprepublish_output( \\?[^%]+\\?){5}.+\npostpublish_output( \\?[^%]+\\?){5}", RegexOptions.Singleline);
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
|
|
|
|
{
|
|
|
|
|
// copy all the files to temp dir
|
|
|
|
|
foreach (var file in Directory.EnumerateFiles(projectDir))
|
|
|
|
|
{
|
|
|
|
|
tempDir.CopyFile(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetProjectPath(TempDirectory projectDir)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(projectDir.Path, "project.json");
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-11 21:40:47 +00:00
|
|
|
|
}
|