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-11-26 03:46:01 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
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-11-25 01:47:33 +00:00
|
|
|
|
|
|
|
|
|
namespace ConsoleApplication
|
|
|
|
|
{
|
|
|
|
|
public class E2ETest
|
|
|
|
|
{
|
2015-11-26 03:46:01 +00:00
|
|
|
|
private static readonly string EXPECTED_OUTPUT = "Hello World!" + Environment.NewLine;
|
|
|
|
|
private static readonly string TESTDIR_NAME = "hellotest";
|
|
|
|
|
private static readonly string OUTPUTDIR_NAME = "testbin";
|
|
|
|
|
|
|
|
|
|
private static string RootPath { get; set; }
|
|
|
|
|
private string TestDirectory { get; set; }
|
|
|
|
|
private string OutputDirectory { get; set; }
|
|
|
|
|
private string Rid { 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
|
|
|
|
|
|
|
|
|
public E2ETest()
|
|
|
|
|
{
|
|
|
|
|
if (RootPath == null)
|
|
|
|
|
{
|
|
|
|
|
RootPath = Directory.GetCurrentDirectory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestDirectory = Path.Combine(RootPath, TESTDIR_NAME);
|
|
|
|
|
OutputDirectory = Path.Combine(RootPath, OUTPUTDIR_NAME);
|
|
|
|
|
|
|
|
|
|
Rid = RuntimeIdentifier.Current;
|
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2015-11-26 03:46:01 +00:00
|
|
|
|
public void TestDotnetCompile()
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestSetup();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestRunCommand("dotnet", $"compile -o {OutputDirectory}");
|
|
|
|
|
TestOutputExecutable(OutputDirectory);
|
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetCompileNativeRyuJit()
|
|
|
|
|
{
|
|
|
|
|
// Skip this test on mac
|
|
|
|
|
if(SkipForOS(OSPlatform.OSX, "https://github.com/dotnet/cli/issues/246"))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestSetup();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestRunCommand("dotnet", $"compile --native -o {OutputDirectory}");
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
var nativeOut = Path.Combine(OutputDirectory, "native");
|
|
|
|
|
TestOutputExecutable(nativeOut);
|
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetCompileNativeCpp()
|
|
|
|
|
{
|
2015-11-30 18:39:25 +00:00
|
|
|
|
// Skip this test on windows
|
|
|
|
|
if(SkipForOS(OSPlatform.Windows, "https://github.com/dotnet/cli/issues/335"))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestSetup();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestRunCommand("dotnet", $"compile --native --cpp -o {OutputDirectory}");
|
|
|
|
|
|
|
|
|
|
var nativeOut = Path.Combine(OutputDirectory, "native");
|
|
|
|
|
TestOutputExecutable(nativeOut);
|
|
|
|
|
}
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetRun()
|
|
|
|
|
{
|
|
|
|
|
TestSetup();
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
TestRunCommand("dotnet", $"run");
|
2015-11-25 01:47:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
public void TestDotnetPack()
|
|
|
|
|
{
|
|
|
|
|
TestSetup();
|
|
|
|
|
|
|
|
|
|
TestRunCommand("dotnet", $"pack");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDotnetPublish()
|
|
|
|
|
{
|
|
|
|
|
TestSetup();
|
|
|
|
|
|
|
|
|
|
TestRunCommand("dotnet", $"publish --framework dnxcore50 --runtime {Rid} -o {OutputDirectory}");
|
|
|
|
|
TestOutputExecutable(OutputDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TestSetup()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(RootPath);
|
|
|
|
|
|
|
|
|
|
CleanOrCreateDirectory(TestDirectory);
|
|
|
|
|
CleanOrCreateDirectory(OutputDirectory);
|
|
|
|
|
|
|
|
|
|
Directory.SetCurrentDirectory(TestDirectory);
|
|
|
|
|
|
|
|
|
|
TestRunCommand("dotnet", "init");
|
2015-12-03 00:01:19 +00:00
|
|
|
|
TestRunCommand("dotnet", "restore --quiet");
|
2015-11-26 03:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SkipForOS(OSPlatform os, string reason)
|
|
|
|
|
{
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(os))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Skipping Test for reason: " + reason);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TestRunCommand(string command, string args)
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
|
|
|
|
var result = Command.Create(command, args)
|
|
|
|
|
.ForwardStdErr()
|
|
|
|
|
.ForwardStdOut()
|
|
|
|
|
.Execute();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, result.ExitCode);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
private void TestOutputExecutable(string outputDir)
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
2015-11-26 03:46:01 +00:00
|
|
|
|
var executableName = TESTDIR_NAME + Constants.ExeSuffix;
|
2015-11-25 01:47:33 +00:00
|
|
|
|
|
|
|
|
|
var executablePath = Path.Combine(outputDir, executableName);
|
|
|
|
|
|
|
|
|
|
var result = Command.Create(executablePath, "")
|
|
|
|
|
.CaptureStdErr()
|
|
|
|
|
.CaptureStdOut()
|
|
|
|
|
.Execute();
|
|
|
|
|
|
|
|
|
|
var outText = result.StdOut;
|
2015-11-26 03:46:01 +00:00
|
|
|
|
Assert.Equal(EXPECTED_OUTPUT, outText);
|
2015-11-25 01:47:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:46:01 +00:00
|
|
|
|
private void CleanOrCreateDirectory(string path)
|
2015-11-25 01:47:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(path, true);
|
|
|
|
|
}
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|