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-12-07 22:18:09 +00:00
|
|
|
|
using System.Collections.Generic;
|
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-07 22:18:09 +00:00
|
|
|
|
using System.Text;
|
2015-11-25 01:47:33 +00:00
|
|
|
|
using Xunit;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2015-11-30 19:25:13 +00:00
|
|
|
|
using Microsoft.DotNet.ProjectModel;
|
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;
|
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";
|
|
|
|
|
private static readonly string s_outputdirName = "testbin";
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Dummy Entrypoint.");
|
|
|
|
|
}
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
public EndToEndTest()
|
2015-11-26 03:46:01 +00:00
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
TestSetup();
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2015-12-19 00:39:43 +00:00
|
|
|
|
Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
|
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
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory);
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
TestSetup();
|
|
|
|
|
|
|
|
|
|
// first build
|
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory);
|
|
|
|
|
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-20 23:41:46 +00:00
|
|
|
|
var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(
|
|
|
|
|
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-20 23:41:46 +00:00
|
|
|
|
var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(
|
|
|
|
|
binariesOutputDirectory);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
|
|
|
|
|
|
|
|
|
|
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-20 23:41:46 +00:00
|
|
|
|
var latestWriteTimeThirdBuild = GetLastWriteTimeOfDirectoryFiles(
|
|
|
|
|
binariesOutputDirectory);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
Assert.NotEqual(latestWriteTimeSecondBuild, latestWriteTimeThirdBuild);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
2015-12-31 01:02:59 +00:00
|
|
|
|
[ActiveIssue(712, PlatformID.Windows | PlatformID.OSX | PlatformID.Linux)]
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// first build
|
|
|
|
|
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true);
|
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);
|
|
|
|
|
|
|
|
|
|
var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(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);
|
|
|
|
|
|
|
|
|
|
var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory);
|
2015-12-21 18:42:41 +00:00
|
|
|
|
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
|
|
|
|
|
}
|
|
|
|
|
|
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-14 19:52:54 +00:00
|
|
|
|
TestOutputExecutable(OutputDirectory, publishCommand.GetOutputExecutable(), s_expectedOutput);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TestSetup()
|
|
|
|
|
{
|
2015-12-31 01:02:59 +00:00
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
|
|
|
|
|
TestDirectory = root.CreateDirectory(s_testdirName).Path;
|
|
|
|
|
TestProject = Path.Combine(TestDirectory, "project.json");
|
|
|
|
|
OutputDirectory = Path.Combine(TestDirectory, s_outputdirName);
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
InitializeTestDirectory();
|
|
|
|
|
}
|
2015-11-26 03:46:01 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
private void InitializeTestDirectory()
|
|
|
|
|
{
|
|
|
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
2015-11-26 03:46:01 +00:00
|
|
|
|
Directory.SetCurrentDirectory(TestDirectory);
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
private static DateTime GetLastWriteTimeOfDirectoryFiles(string outputDirectory)
|
|
|
|
|
{
|
|
|
|
|
return Directory.EnumerateFiles(outputDirectory).Max(f => File.GetLastWriteTime(f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-01-06 23:30:56 +00:00
|
|
|
|
}
|