From 8db6b797d2c7a9aeab71141a488f1112677829b4 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Wed, 25 Nov 2015 19:46:01 -0800 Subject: [PATCH] Use Corehost instead of CoreRun, refactor tests for individual commands --- scripts/test/e2e-test.ps1 | 3 +- scripts/test/e2e-test.sh | 3 +- test/E2E/E2ETest.cs | 164 +++++++++++++++++++++++++------------- test/E2E/project.json | 13 ++- 4 files changed, 118 insertions(+), 65 deletions(-) diff --git a/scripts/test/e2e-test.ps1 b/scripts/test/e2e-test.ps1 index 9624ad6b4..aa6503004 100644 --- a/scripts/test/e2e-test.ps1 +++ b/scripts/test/e2e-test.ps1 @@ -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 diff --git a/scripts/test/e2e-test.sh b/scripts/test/e2e-test.sh index afb887284..b5dc8d295 100755 --- a/scripts/test/e2e-test.sh +++ b/scripts/test/e2e-test.sh @@ -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 diff --git a/test/E2E/E2ETest.cs b/test/E2E/E2ETest.cs index a51f5fdbd..31507cf9b 100644 --- a/test/E2E/E2ETest.cs +++ b/test/E2E/E2ETest.cs @@ -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)) { diff --git a/test/E2E/project.json b/test/E2E/project.json index 340430e08..e21cac468 100644 --- a/test/E2E/project.json +++ b/test/E2E/project.json @@ -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": {