2016-01-08 19:03:14 +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-20 23:41:46 +00:00
|
|
|
|
using System;
|
2016-01-08 19:03:14 +00:00
|
|
|
|
using System.IO;
|
2016-02-17 18:08:27 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-02-20 00:48:43 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-01-08 19:03:14 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2016-02-17 18:08:27 +00:00
|
|
|
|
using FluentAssertions;
|
2016-01-08 19:03:14 +00:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
2016-01-29 00:16:50 +00:00
|
|
|
|
namespace Microsoft.DotNet.Tools.Compiler.Tests
|
2016-01-08 19:03:14 +00:00
|
|
|
|
{
|
|
|
|
|
public class CompilerTests : TestBase
|
|
|
|
|
{
|
2016-01-29 00:16:50 +00:00
|
|
|
|
private readonly string _testProjectsRoot;
|
|
|
|
|
|
|
|
|
|
public CompilerTests()
|
|
|
|
|
{
|
2016-02-05 23:43:50 +00:00
|
|
|
|
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
|
2016-01-29 00:16:50 +00:00
|
|
|
|
}
|
2016-01-08 19:03:14 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void XmlDocumentationFileIsGenerated()
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
2016-01-13 00:36:31 +00:00
|
|
|
|
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
|
|
|
|
|
|
2016-01-08 19:03:14 +00:00
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
2016-02-11 22:17:20 +00:00
|
|
|
|
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestAppWithLibrary", "TestLibrary");
|
2016-01-08 19:03:14 +00:00
|
|
|
|
|
2016-01-29 00:16:50 +00:00
|
|
|
|
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
2016-01-08 19:03:14 +00:00
|
|
|
|
|
|
|
|
|
// run compile
|
|
|
|
|
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
|
|
|
|
var testProject = GetProjectPath(testLibDir);
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
2016-01-08 19:03:14 +00:00
|
|
|
|
var result = buildCommand.ExecuteWithCapturedOutput();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
// verify the output xml file
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var outputXml = Path.Combine(outputDir, "Debug", DefaultFramework, "TestLibrary.xml");
|
2016-01-20 23:41:46 +00:00
|
|
|
|
Console.WriteLine("OUTPUT XML PATH: " + outputXml);
|
2016-01-08 19:03:14 +00:00
|
|
|
|
Assert.True(File.Exists(outputXml));
|
|
|
|
|
Assert.Contains("Gets the message from the helper", File.ReadAllText(outputXml));
|
|
|
|
|
}
|
2016-02-09 00:06:13 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SatelliteAssemblyIsGeneratedByDotnetBuild()
|
|
|
|
|
{
|
|
|
|
|
// create unique directories in the 'temp' folder
|
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
var testLibDir = root.CreateDirectory("TestProjectWithCultureSpecificResource");
|
|
|
|
|
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestProjectWithCultureSpecificResource");
|
|
|
|
|
|
|
|
|
|
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
|
|
|
|
|
|
|
|
|
// run compile on a project with resources
|
|
|
|
|
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
|
|
|
|
var testProject = GetProjectPath(testLibDir);
|
|
|
|
|
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
|
|
|
|
var result = buildCmd.ExecuteWithCapturedOutput();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var generatedSatelliteAssemblyPath = Path.Combine(
|
|
|
|
|
outputDir,
|
|
|
|
|
"Debug",
|
|
|
|
|
DefaultFramework,
|
|
|
|
|
"fr",
|
|
|
|
|
"TestProjectWithCultureSpecificResource.resources.dll");
|
|
|
|
|
Assert.True(File.Exists(generatedSatelliteAssemblyPath), $"File {generatedSatelliteAssemblyPath} was not found.");
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 23:14:19 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void LibraryWithAnalyzer()
|
2016-01-29 00:16:50 +00:00
|
|
|
|
{
|
2016-01-18 23:14:19 +00:00
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
2016-01-29 00:16:50 +00:00
|
|
|
|
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
|
|
|
|
|
|
|
|
|
|
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
2016-01-18 23:14:19 +00:00
|
|
|
|
|
|
|
|
|
// run compile
|
|
|
|
|
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
|
|
|
|
var testProject = GetProjectPath(testLibDir);
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
2016-01-18 23:14:19 +00:00
|
|
|
|
var result = buildCmd.ExecuteWithCapturedOutput();
|
|
|
|
|
result.Should().Pass();
|
2016-02-09 02:01:27 +00:00
|
|
|
|
|
|
|
|
|
Assert.Contains("CA1018", result.StdErr);
|
2016-01-18 23:14:19 +00:00
|
|
|
|
}
|
2016-01-08 19:03:14 +00:00
|
|
|
|
|
2016-02-18 18:26:00 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CompilingAppWithPreserveCompilationContextWithSpaceInThePathShouldSucceed()
|
|
|
|
|
{
|
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
|
|
|
|
|
var spaceBufferDirectory = root.CreateDirectory("space directory");
|
|
|
|
|
var testAppDir = spaceBufferDirectory.CreateDirectory("TestAppCompilationContext");
|
|
|
|
|
|
|
|
|
|
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);
|
|
|
|
|
|
|
|
|
|
var testProjectDir = Path.Combine(_testProjectsRoot, "TestAppCompilationContext", "TestApp");
|
|
|
|
|
var testProject = Path.Combine(testProjectDir, "project.json");
|
|
|
|
|
|
|
|
|
|
var buildCommand = new BuildCommand(testProject);
|
|
|
|
|
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 18:08:27 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ContentFilesAreCopied()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithContentPackage")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
var root = testInstance.TestRoot;
|
|
|
|
|
|
|
|
|
|
// run compile
|
|
|
|
|
var outputDir = Path.Combine(root, "bin");
|
|
|
|
|
var testProject = ProjectUtils.GetProjectJson(root, "TestAppWithContentPackage");
|
|
|
|
|
var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
|
|
|
|
var result = buildCommand.ExecuteWithCapturedOutput();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
result = Command.Create(Path.Combine(outputDir, buildCommand.GetOutputExecutableName()), new string [0])
|
|
|
|
|
.CaptureStdErr()
|
|
|
|
|
.CaptureStdOut()
|
|
|
|
|
.Execute();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
// verify the output xml file
|
|
|
|
|
new DirectoryInfo(outputDir).Sub("scripts").Should()
|
|
|
|
|
.Exist()
|
|
|
|
|
.And.HaveFile("run.cmd");
|
|
|
|
|
new DirectoryInfo(outputDir).Should()
|
|
|
|
|
.HaveFile("config.xml");
|
|
|
|
|
// verify embedded resources
|
|
|
|
|
result.StdOut.Should().Contain("TestAppWithContentPackage.dnf.png");
|
|
|
|
|
result.StdOut.Should().Contain("TestAppWithContentPackage.ui.png");
|
|
|
|
|
// verify 'all' language files not included
|
|
|
|
|
result.StdOut.Should().NotContain("TestAppWithContentPackage.dnf_all.png");
|
|
|
|
|
result.StdOut.Should().NotContain("TestAppWithContentPackage.ui_all.png");
|
|
|
|
|
// verify classes
|
|
|
|
|
result.StdOut.Should().Contain("TestAppWithContentPackage.Foo");
|
|
|
|
|
result.StdOut.Should().Contain("MyNamespace.Util");
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-20 00:48:43 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void EmbeddedDependencyContextIsValidOnBuild()
|
|
|
|
|
{
|
|
|
|
|
var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestApp");
|
|
|
|
|
var testProject = Path.Combine(testProjectPath, "project.json");
|
|
|
|
|
|
|
|
|
|
var runCommand = new RunCommand(testProject);
|
|
|
|
|
runCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DepsDependencyContextIsValidOnBuild()
|
|
|
|
|
{
|
|
|
|
|
var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestAppDeps");
|
|
|
|
|
var testProject = Path.Combine(testProjectPath, "project.json");
|
|
|
|
|
|
|
|
|
|
var runCommand = new RunCommand(testProject);
|
|
|
|
|
runCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-08 19:03:14 +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-13 23:56:02 +00:00
|
|
|
|
}
|