2015-11-25 02:48:31 +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;
|
2015-11-25 01:47:33 +00:00
|
|
|
|
using System.IO;
|
2015-12-21 18:42:41 +00:00
|
|
|
|
using System.Linq;
|
2015-11-26 03:46:01 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2015-12-31 01:02:59 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2015-12-19 00:39:43 +00:00
|
|
|
|
using Microsoft.Extensions.PlatformAbstractions;
|
2016-01-28 00:20:26 +00:00
|
|
|
|
using Xunit;
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
namespace Microsoft.DotNet.Tests.EndToEnd
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
public class EndToEndTest : TestBase
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
private static readonly string s_expectedOutput = "Hello World!" + Environment.NewLine;
|
|
|
|
|
private static readonly string s_testdirName = "e2etestroot";
|
2016-01-22 22:05:02 +00:00
|
|
|
|
private static readonly string s_outputdirName = "test space/bin";
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
private static string RestoredTestProjectDirectory { get; set; }
|
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
private string Rid { get; set; }
|
2015-11-26 03:46:01 +00:00
|
|
|
|
private string TestDirectory { get; set; }
|
2015-12-31 01:02:59 +00:00
|
|
|
|
private string TestProject { get; set; }
|
2015-11-26 03:46:01 +00:00
|
|
|
|
private string OutputDirectory { get; set; }
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
static EndToEndTest()
|
|
|
|
|
{
|
|
|
|
|
EndToEndTest.SetupStaticTestProject();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-25 01:47:33 +00:00
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Dummy Entrypoint.");
|
|
|
|
|
}
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
public EndToEndTest()
|
2015-11-26 03:46:01 +00:00
|
|
|
|
{
|
2016-01-30 01:37:08 +00:00
|
|
|
|
TestInstanceSetup();
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2015-12-31 01:02:59 +00:00
|
|
|
|
public void TestDotnetBuild()
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework);
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2016-01-14 19:52:54 +00:00
|
|
|
|
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-12-21 18:42:41 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetIncrementalBuild()
|
|
|
|
|
{
|
|
|
|
|
// first build
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
buildCommand.Execute().Should().Pass();
|
2016-01-14 19:52:54 +00:00
|
|
|
|
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
2016-01-21 23:01:21 +00:00
|
|
|
|
var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);
|
2016-01-28 00:20:26 +00:00
|
|
|
|
var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(
|
2016-01-20 23:41:46 +00:00
|
|
|
|
binariesOutputDirectory);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
|
|
|
|
// second build; should get skipped (incremental because no inputs changed)
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
2016-01-14 19:52:54 +00:00
|
|
|
|
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
2016-01-28 00:20:26 +00:00
|
|
|
|
var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(
|
2016-01-20 23:41:46 +00:00
|
|
|
|
binariesOutputDirectory);
|
2016-01-28 00:20:26 +00:00
|
|
|
|
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeUtcSecondBuild);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
|
|
|
|
TouchSourceFileInDirectory(TestDirectory);
|
|
|
|
|
|
|
|
|
|
// third build; should get compiled because the source file got touched
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
2016-01-14 19:52:54 +00:00
|
|
|
|
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
2016-01-28 00:20:26 +00:00
|
|
|
|
var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles(
|
2016-01-20 23:41:46 +00:00
|
|
|
|
binariesOutputDirectory);
|
2016-01-28 00:20:26 +00:00
|
|
|
|
Assert.NotEqual(latestWriteTimeUtcSecondBuild, latestWriteTimeUtcThirdBuild);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
2015-12-31 01:02:59 +00:00
|
|
|
|
public void TestDotnetBuildNativeRyuJit()
|
2015-11-26 03:46:01 +00:00
|
|
|
|
{
|
2016-01-06 02:11:38 +00:00
|
|
|
|
if(IsCentOS())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 02:04:49 +00:00
|
|
|
|
if (IsWinX86())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping native compilation tests on Windows x86 - https://github.com/dotnet/cli/issues/1550");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, framework: DefaultFramework);
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
buildCommand.Execute().Should().Pass();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2016-01-20 23:41:46 +00:00
|
|
|
|
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
2015-12-31 01:02:59 +00:00
|
|
|
|
public void TestDotnetBuildNativeCpp()
|
2015-11-26 03:46:01 +00:00
|
|
|
|
{
|
2016-01-06 02:11:38 +00:00
|
|
|
|
if(IsCentOS())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 02:04:49 +00:00
|
|
|
|
if (IsWinX86())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping native compilation tests on Windows x86 - https://github.com/dotnet/cli/issues/1550");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true, framework: DefaultFramework);
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2016-01-20 23:41:46 +00:00
|
|
|
|
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-12-21 18:42:41 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetCompileNativeCppIncremental()
|
|
|
|
|
{
|
|
|
|
|
if (IsCentOS())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 02:04:49 +00:00
|
|
|
|
if (IsWinX86())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping native compilation tests on Windows x86 - https://github.com/dotnet/cli/issues/1550");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-21 18:42:41 +00:00
|
|
|
|
// first build
|
2016-02-03 18:57:25 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true, framework: DefaultFramework);
|
2016-01-21 23:01:21 +00:00
|
|
|
|
var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);
|
2016-01-20 23:41:46 +00:00
|
|
|
|
|
2015-12-21 18:42:41 +00:00
|
|
|
|
buildCommand.Execute().Should().Pass();
|
|
|
|
|
|
2016-01-20 23:41:46 +00:00
|
|
|
|
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
|
|
|
|
|
2016-01-28 00:20:26 +00:00
|
|
|
|
var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
|
|
|
|
// second build; should be skipped because nothing changed
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
|
|
|
|
|
2016-01-20 23:41:46 +00:00
|
|
|
|
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
|
|
|
|
|
2016-01-28 00:20:26 +00:00
|
|
|
|
var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
|
|
|
|
|
Assert.Equal(latestWriteTimeUtcFirstBuild, latestWriteTimeUtcSecondBuild);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetRun()
|
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var runCommand = new RunCommand(TestProject);
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
runCommand.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
}
|
2015-12-18 19:34:55 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2015-11-26 03:46:01 +00:00
|
|
|
|
public void TestDotnetPack()
|
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var packCommand = new PackCommand(TestDirectory, output: OutputDirectory);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
packCommand.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetPublish()
|
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var publishCommand = new PublishCommand(TestProject, output: OutputDirectory);
|
|
|
|
|
publishCommand.Execute().Should().Pass();
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2016-01-26 14:39:13 +00:00
|
|
|
|
TestExecutable(OutputDirectory, publishCommand.GetOutputExecutable(), s_expectedOutput);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-04 20:41:50 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetHelp()
|
|
|
|
|
{
|
|
|
|
|
var helpCommand = new HelpCommand();
|
|
|
|
|
helpCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetHelpBuild()
|
|
|
|
|
{
|
|
|
|
|
var helpCommand = new HelpCommand();
|
|
|
|
|
helpCommand.Execute("build").Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
private void TestInstanceSetup()
|
2015-11-26 03:46:01 +00:00
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
var testInstanceDir = root.CopyDirectory(RestoredTestProjectDirectory);
|
|
|
|
|
|
|
|
|
|
TestDirectory = testInstanceDir.Path;
|
2015-12-31 01:02:59 +00:00
|
|
|
|
TestProject = Path.Combine(TestDirectory, "project.json");
|
|
|
|
|
OutputDirectory = Path.Combine(TestDirectory, s_outputdirName);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
|
2015-12-31 01:02:59 +00:00
|
|
|
|
}
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2016-01-30 01:37:08 +00:00
|
|
|
|
private static void SetupStaticTestProject()
|
2015-12-31 01:02:59 +00:00
|
|
|
|
{
|
2016-01-30 01:37:08 +00:00
|
|
|
|
RestoredTestProjectDirectory = Path.Combine(AppContext.BaseDirectory, "bin", s_testdirName);
|
|
|
|
|
|
|
|
|
|
// Ignore Delete Failure
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(RestoredTestProjectDirectory, true);
|
|
|
|
|
}
|
2016-02-02 18:04:50 +00:00
|
|
|
|
catch(Exception) {}
|
2016-01-30 01:37:08 +00:00
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(RestoredTestProjectDirectory);
|
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
2016-01-30 01:37:08 +00:00
|
|
|
|
Directory.SetCurrentDirectory(RestoredTestProjectDirectory);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
new NewCommand().Execute().Should().Pass();
|
|
|
|
|
new RestoreCommand().Execute("--quiet").Should().Pass();
|
|
|
|
|
|
|
|
|
|
Directory.SetCurrentDirectory(currentDirectory);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 02:11:38 +00:00
|
|
|
|
private bool IsCentOS()
|
|
|
|
|
{
|
|
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
const string OSIDFILE = "/etc/os-release";
|
|
|
|
|
|
|
|
|
|
if(File.Exists(OSIDFILE))
|
|
|
|
|
{
|
|
|
|
|
return File.ReadAllText(OSIDFILE).ToLower().Contains("centos");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-12-21 18:42:41 +00:00
|
|
|
|
|
2016-02-24 02:04:49 +00:00
|
|
|
|
private bool IsWinX86()
|
|
|
|
|
{
|
|
|
|
|
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
|
|
|
|
|
RuntimeInformation.ProcessArchitecture == Architecture.X86;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 00:20:26 +00:00
|
|
|
|
private static DateTime GetLastWriteTimeUtcOfDirectoryFiles(string outputDirectory)
|
2015-12-21 18:42:41 +00:00
|
|
|
|
{
|
2016-01-28 00:20:26 +00:00
|
|
|
|
return Directory.EnumerateFiles(outputDirectory).Max(f => File.GetLastWriteTimeUtc(f));
|
2015-12-21 18:42:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void TouchSourceFileInDirectory(string directory)
|
|
|
|
|
{
|
|
|
|
|
var csFile = Directory.EnumerateFiles(directory).First(f => Path.GetExtension(f).Equals(".cs"));
|
|
|
|
|
File.SetLastWriteTimeUtc(csFile, DateTime.UtcNow);
|
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
}
|
2016-02-02 18:04:50 +00:00
|
|
|
|
}
|