Use Corehost instead of CoreRun, refactor tests for individual commands

This commit is contained in:
Bryan Thornbury 2015-11-25 19:46:01 -08:00
parent 5c31655317
commit 8db6b797d2
4 changed files with 118 additions and 65 deletions

View file

@ -32,7 +32,8 @@ popd
# Run the app and check the exit code
pushd "$RepoRoot\artifacts\$Rid\e2etest"
& "CoreRun.exe" "xunit.console.netcore.exe" "E2E.dll" -xml ..\..\e2etest.xml
mv E2E.exe corehost.exe
& "corehost.exe" "xunit.console.netcore.exe" "E2E.dll" -xml ..\..\e2etest.xml
if (!$?) {
Write-Host "E2E Test Failure"
popd

View file

@ -23,5 +23,6 @@ dotnet publish --framework dnxcore50 --runtime "$RID" --output "$REPOROOT/artifa
# set -e will abort if the exit code of this is non-zero
pushd "$REPOROOT/artifacts/$RID/e2etest"
./corerun xunit.console.netcore.exe E2E.dll
mv ./E2E ./corehost
./corehost xunit.console.netcore.exe E2E.dll
popd

View file

@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Xunit;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.ProjectModel;
@ -11,59 +12,119 @@ namespace ConsoleApplication
{
public class E2ETest
{
private static readonly string EXPECTED_OUTPUT = "Hello World!";
private static readonly string TEST_PROJECT_NAME = "hellotest";
private static readonly string OUTPUT_FOLDER_NAME = "testbin";
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; }
public static void Main()
{
Console.WriteLine("Dummy Entrypoint.");
}
[Fact]
public static void TestE2E()
public E2ETest()
{
// Setup Paths
var rootPath = GetRootPath();
var testDir = Path.Combine(rootPath, TEST_PROJECT_NAME);
var outputDir = Path.Combine(testDir, OUTPUT_FOLDER_NAME);
if (RootPath == null)
{
RootPath = Directory.GetCurrentDirectory();
}
// Setup RID
var rid = RuntimeIdentifier.Current;
TestDirectory = Path.Combine(RootPath, TESTDIR_NAME);
OutputDirectory = Path.Combine(RootPath, OUTPUTDIR_NAME);
// Create Test Directory and cd there
CleanOrCreateDirectory(testDir);
Directory.SetCurrentDirectory(TEST_PROJECT_NAME);
// Base Set of Commands
TestRunCommand("dotnet", "init");
TestRunCommand("dotnet", "restore");
TestRunCommand("dotnet", "run");
// Compile
TestRunCommand("dotnet", $"compile -o {outputDir}");
TestOutputExecutable(outputDir);
// Native Compilation
CleanOrCreateDirectory(outputDir);
TestRunCommand("dotnet", $"compile --native -o {outputDir}");
TestOutputExecutable(outputDir);
// Native Compilation w/ CPP backend
CleanOrCreateDirectory(outputDir);
TestRunCommand("dotnet", $"compile --native --cpp -o {outputDir}");
TestOutputExecutable(outputDir);
// Publish
CleanOrCreateDirectory(outputDir);
TestRunCommand("dotnet", $"publish --framework dnxcore50 --runtime {rid} -o {outputDir}");
TestOutputExecutable(outputDir);
TestRunCommand("dotnet", "pack");
Rid = RuntimeIdentifier.Current;
}
public static void TestRunCommand(string command, string args)
[Fact]
public void TestDotnetCompile()
{
TestSetup();
TestRunCommand("dotnet", $"compile -o {OutputDirectory}");
TestOutputExecutable(OutputDirectory);
}
[Fact]
public void TestDotnetCompileNativeRyuJit()
{
// Skip this test on mac
if(SkipForOS(OSPlatform.OSX, "https://github.com/dotnet/cli/issues/246"))
{
return;
}
TestSetup();
TestRunCommand("dotnet", $"compile --native -o {OutputDirectory}");
var nativeOut = Path.Combine(OutputDirectory, "native");
TestOutputExecutable(nativeOut);
}
[Fact]
public void TestDotnetCompileNativeCpp()
{
TestSetup();
TestRunCommand("dotnet", $"compile --native --cpp -o {OutputDirectory}");
var nativeOut = Path.Combine(OutputDirectory, "native");
TestOutputExecutable(nativeOut);
}
[Fact]
public void TestDotnetRun()
{
TestSetup();
TestRunCommand("dotnet", $"run");
}
[Fact(Skip="https://github.com/dotnet/cli/issues/333")]
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");
TestRunCommand("dotnet", "restore");
}
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)
{
var result = Command.Create(command, args)
.ForwardStdErr()
@ -73,9 +134,9 @@ namespace ConsoleApplication
Assert.Equal(0, result.ExitCode);
}
public static void TestOutputExecutable(string outputDir)
private void TestOutputExecutable(string outputDir)
{
var executableName = TEST_PROJECT_NAME + Constants.ExeSuffix;
var executableName = TESTDIR_NAME + Constants.ExeSuffix;
var executablePath = Path.Combine(outputDir, executableName);
@ -85,19 +146,10 @@ namespace ConsoleApplication
.Execute();
var outText = result.StdOut;
var expectedText = EXPECTED_OUTPUT + Environment.NewLine;
Assert.Equal(expectedText, outText);
Assert.Equal(EXPECTED_OUTPUT, outText);
}
public static string GetRootPath()
{
var cwd = Directory.GetCurrentDirectory();
return cwd;
}
public static void CleanOrCreateDirectory(string path)
private void CleanOrCreateDirectory(string path)
{
if (Directory.Exists(path))
{

View file

@ -6,21 +6,20 @@
"dependencies": {
"Microsoft.NETCore.Platforms":"1.0.1-beta-*",
"Microsoft.NETCore.TestHost": "1.0.0-beta-*",
"Microsoft.NETCore.Runtime": "1.0.1-beta-*",
"Microsoft.NETCore.Console": "1.0.0-beta-*",
"System.IO": "4.0.11-beta-*",
"System.Console": "4.0.0-beta-*",
"System.Runtime": "4.0.21-beta-*",
"System.AppContext": "4.0.1-beta-*",
"xunit": "2.1.0",
"xunit.console.netcore": "1.0.2-prerelease-00101",
"xunit.runner.utility": "2.1.0",
"Microsoft.DotNet.ProjectModel": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
},
"System.AppContext": "4.0.1-beta-*",
"xunit.console.netcore": "1.0.2-prerelease-00101",
"xunit.runner.utility": "2.1.0",
"Microsoft.DotNet.ProjectModel": { "target": "project" }
},
"frameworks": {