diff --git a/KoreBuild-dotnet/build/KoreBuild.cmd b/KoreBuild-dotnet/build/KoreBuild.cmd index a2d66c4c78..75dbe4edaf 100644 --- a/KoreBuild-dotnet/build/KoreBuild.cmd +++ b/KoreBuild-dotnet/build/KoreBuild.cmd @@ -17,15 +17,15 @@ IF "%KOREBUILD_DOTNET_VERSION%"=="" ( SET KOREBUILD_DOTNET_VERSION=1.0.0.001496 ) -IF NOT EXIST Sake ( +IF NOT EXIST %~dp0Sake ( "%NUGET_PATH%" install Sake -ExcludeVersion -Source https://api.nuget.org/v3/index.json -o %~dp0 ) -IF NOT EXIST xunit.runner.console ( +IF NOT EXIST %~dp0xunit.runner.console ( "%NUGET_PATH%" install xunit.runner.console -ExcludeVersion -Source https://api.nuget.org/v3/index.json -o %~dp0 ) -IF NOT EXIST xunit.core ( +IF NOT EXIST %~dp0xunit.core ( "%NUGET_PATH%" install xunit.core -ExcludeVersion -Source https://api.nuget.org/v3/index.json -o %~dp0 ) diff --git a/KoreBuild-dotnet/build/_dnx-test.shade b/KoreBuild-dotnet/build/_dnx-test.shade index 9d56b4b2a0..f7cf3c0769 100644 --- a/KoreBuild-dotnet/build/_dnx-test.shade +++ b/KoreBuild-dotnet/build/_dnx-test.shade @@ -2,7 +2,6 @@ use import="Json" use import="Environment" default NO_PARALLEL_TEST_PROJECTS='${E("NO_PARALLEL_TEST_PROJECTS")}' -default KOREBUILD_TEST_SKIPMONO='${E("KOREBUILD_TEST_SKIPMONO")}' @{/* @@ -12,44 +11,25 @@ dnx-test projectFile='' Required. Path to the test project.json to execute +framework='' + Required. The TFM to run tests for + */} @{ - var projectText = File.ReadAllText(projectFile); - var project = (JsonObject)Json.Deserialize(projectText); + var projectFolder = Path.GetDirectoryName(projectFile); + var projectName = Path.GetFileName(projectFolder); - var commands = project.ValueAsJsonObject("commands"); + var noParallelTestProjects = new HashSet(StringComparer.OrdinalIgnoreCase); + if (!string.IsNullOrEmpty(NO_PARALLEL_TEST_PROJECTS)) + { + noParallelTestProjects.UnionWith(NO_PARALLEL_TEST_PROJECTS.Split((char)',')); + } - if (commands != null && commands.Keys.Contains("test")) - { - var projectFolder = Path.GetDirectoryName(projectFile); - var projectName = Path.GetFileName(projectFolder); + var testArgs = noParallelTestProjects.Contains(projectName) || IsLinux ? " -parallel none" : ""; - var noParallelTestProjects = new HashSet(StringComparer.OrdinalIgnoreCase); - if (!string.IsNullOrEmpty(NO_PARALLEL_TEST_PROJECTS)) - { - noParallelTestProjects.UnionWith(NO_PARALLEL_TEST_PROJECTS.Split((char)',')); - } - - var configs = project.ValueAsJsonObject("frameworks"); - IEnumerable targetFrameworks = configs == null? - new string[0]: - configs.Keys.Where(k => k.StartsWith("dnx", StringComparison.OrdinalIgnoreCase)); - - foreach (var framework in targetFrameworks) - { - var testArgs = noParallelTestProjects.Contains(projectName) ? " -parallel none" : ""; - - if (framework.StartsWith("dnxcore", StringComparison.OrdinalIgnoreCase)) - { - if (IsLinux) - { - // Work around issue with testing in parallel on Mono. - testArgs = " -parallel none"; - } - - Dnx("test" + testArgs, projectFolder, "default -runtime coreclr"); - } - } + if (framework.StartsWith("dnxcore", StringComparison.OrdinalIgnoreCase)) + { + Dnx("test" + testArgs, projectFolder, "default -runtime coreclr"); } } diff --git a/KoreBuild-dotnet/build/_dotnet-test.shade b/KoreBuild-dotnet/build/_dotnet-test.shade index 99cdce363e..79552be8d7 100644 --- a/KoreBuild-dotnet/build/_dotnet-test.shade +++ b/KoreBuild-dotnet/build/_dotnet-test.shade @@ -1,4 +1,3 @@ -use import="Json" use import="Environment" default NO_PARALLEL_TEST_PROJECTS='${E("NO_PARALLEL_TEST_PROJECTS")}' @@ -11,6 +10,9 @@ dotnet-test projectFile='' Required. Path to the test project.json to execute +framework='' + Required. The TFM to run tests for + configuration='' Optional. The configuration to build in. Defaults to 'Debug'. */} @@ -18,31 +20,8 @@ configuration='' default configuration = 'Debug' @{ - var projectText = File.ReadAllText(projectFile); - var project = (JsonObject)Json.Deserialize(projectText); - - // This check is just used to transition from dnx to dotnet - var commands = project.ValueAsJsonObject("commands"); - - if (commands == null && project.Keys.Contains("testRunner")) - { - var projectFolder = Path.GetDirectoryName(projectFile); - var projectName = Path.GetFileName(projectFolder); - - var testArgs = "--configuration " + configuration; - - var configs = project.ValueAsJsonObject("frameworks"); - IEnumerable targetFrameworks = configs == null? - new string[0]: - configs.Keys.Where(k => k.StartsWith("dnx", StringComparison.OrdinalIgnoreCase)); - - foreach (var framework in targetFrameworks) - { - if (framework.StartsWith("dnxcore")) - { - Dotnet("test " + testArgs, projectFolder); - } - } - } + var projectFolder = Path.GetDirectoryName(projectFile); + var testArgs = "--configuration " + configuration + " --framework " + framework; + Dotnet("test " + testArgs, projectFolder); } diff --git a/KoreBuild-dotnet/build/_k-standard-goals.shade b/KoreBuild-dotnet/build/_k-standard-goals.shade index 9815ebd161..703a760bb3 100644 --- a/KoreBuild-dotnet/build/_k-standard-goals.shade +++ b/KoreBuild-dotnet/build/_k-standard-goals.shade @@ -179,12 +179,45 @@ default NUGET_FEED = 'https://api.nuget.org/v3/index.json' #xunit-test target='test' if='Directory.Exists("test")' @{ - var projectFiles = Files.Include("test/**/project.json").Exclude("**/bin/*/app/project.json").ToList(); - projectFiles.ForEach(projectFile => XunitTest(projectFile, testParallel: false, configuration: Configuration)); - projectFiles.ForEach(projectFile => DotnetTest(projectFile, testParallel: false, configuration: Configuration)); - projectFiles.ForEach(projectFile => DnxTest(projectFile, testParallel: false)); + var projectFiles = Files.Include("test/**/project.json").Exclude("**/bin/*/app/project.json"); + foreach (var projectFile in projectFiles) + { + var projectText = File.ReadAllText(projectFile); + var project = (JsonObject)Json.Deserialize(projectText); + var configs = project.ValueAsJsonObject("frameworks"); + var targetFrameworks = configs == null ? new string[0] : configs.Keys; + + var net45TFM = targetFrameworks.FirstOrDefault(t => t.StartsWith("net45", StringComparison.OrdinalIgnoreCase)); + var dnx451TFM = targetFrameworks.FirstOrDefault(t => t.Equals("dnx451", StringComparison.OrdinalIgnoreCase)); + var dnxCore50TFM = targetFrameworks.FirstOrDefault(t => t.Equals("dnxcore50", StringComparison.OrdinalIgnoreCase)); + if (dnxCore50TFM != null) + { + var hasTestCommand = project.Keys.Contains("commands") && project.ValueAsJsonObject("commands").Keys.Contains("test"); + if (projectText.Contains("dotnet-test-xunit")) + { + DotnetTest(projectFile, dnxCore50TFM, Configuration); + } + else if (hasTestCommand) + { + DnxTest(projectFile, dnxCore50TFM, Configuration); + } + } + + if (project.Keys.Contains("testRunner")) + { + if (net45TFM != null) + { + XunitTest(projectFile, net45TFM, Configuration); + } + else if (dnx451TFM != null) + { + XunitTest(projectFile, dnx451TFM, Configuration); + } + } + } } + #make-roslyn-fast ngen-roslyn @@ -355,22 +388,19 @@ macro name="DotnetBuild" projectFile='string' configuration='string' macro name="DotnetPack" projectFile='string' dotnetPackOutputDir='string' configuration='string' dotnet-pack -macro name="DotnetPublish" projectFile='string' outputFolder='string' framework='string' - dotnet-publish - macro name="DotnetPublish" projectFile='string' outputFolder='string' framework='string' configuration='string' dotnet-publish -macro name="DotnetTest" projectFile='string' testParallel='bool' configuration='string' +macro name="DotnetTest" projectFile='string' framework='string' configuration='string' dotnet-test -macro name="XunitTest" projectFile='string' testParallel='bool' configuration='string' +macro name="XunitTest" projectFile='string' framework='string' configuration='string' xunit-test macro name='Dnx' command='string' dnxDir='string' dnvmUse='string' dnx -macro name="DnxTest" projectFile='string' testParallel='bool' +macro name="DnxTest" projectFile='string' framework='string' configuration='string' dnx-test macro name="UpdateResx" resxFile='string' diff --git a/KoreBuild-dotnet/build/_xunit-test.shade b/KoreBuild-dotnet/build/_xunit-test.shade index d54c12605f..0e43836435 100644 --- a/KoreBuild-dotnet/build/_xunit-test.shade +++ b/KoreBuild-dotnet/build/_xunit-test.shade @@ -12,74 +12,45 @@ xunit-test projectFile='' Required. Path to the test project.json to execute -configuration='' - Optional. The configuration to build in. Defaults to 'Debug'. -*/} +framework='' + Required. The TFM to run tests for -default configuration = 'Debug' +configuration='' + Required. The configuration to build in. Defaults to 'Debug'. +*/} @{ if (!string.Equals(KOREBUILD_TEST_SKIPMONO, "1") && !string.Equals(KOREBUILD_TEST_SKIPMONO, "true")) { - var projectText = File.ReadAllText(projectFile); - var project = (JsonObject)Json.Deserialize(projectText); + var projectFolder = Path.GetDirectoryName(projectFile); + var projectName = Path.GetFileName(projectFolder); - if (project.Keys.Contains("testRunner")) + var noParallelTestProjects = new HashSet(StringComparer.OrdinalIgnoreCase); + if (!string.IsNullOrEmpty(NO_PARALLEL_TEST_PROJECTS)) { - var projectFolder = Path.GetDirectoryName(projectFile); - var projectName = Path.GetFileName(projectFolder); - - var noParallelTestProjects = new HashSet(StringComparer.OrdinalIgnoreCase); - if (!string.IsNullOrEmpty(NO_PARALLEL_TEST_PROJECTS)) - { - noParallelTestProjects.UnionWith(NO_PARALLEL_TEST_PROJECTS.Split((char)',')); - } - - var testArgs = noParallelTestProjects.Contains(projectName) ? " -parallel none" : ""; - - var configs = project.ValueAsJsonObject("frameworks"); - var targetFrameworks = configs == null - ? new string[0] - : configs.Keys - .Where(k => k.StartsWith("dnx4", StringComparison.OrdinalIgnoreCase) - || k.StartsWith("net4", StringComparison.OrdinalIgnoreCase)); - - var runnerFolder = Path.GetFullPath(Path.Combine(KoreBuildFolderPath, "build", "xunit.runner.console", "tools")); - var xunitCoreFolder = Path.GetFullPath(Path.Combine(KoreBuildFolderPath, "build", "xunit.core", "build", "_desktop")); - - foreach (var framework in targetFrameworks) - { - if (IsLinux) - { - // Work around issue with testing in parallel on Mono. - testArgs = " -parallel none"; - } - - var publishFolder = Path.Combine(projectFolder, "obj", "testPublish-" + framework); - DotnetPublish(projectFile, publishFolder, framework, configuration); - - var runnerExe = "xunit.console.exe"; - string runnerFullPath; - - // Copy xunit.execution.desktop. This is required in order to load the binding - // redirects for dlls. See this thread for more details: - // https://github.com/xunit/xunit/issues/732 - // Furthermore, xunit.console.exe must be launched in the same folder as the test dll - if (framework.StartsWith("dnx", StringComparison.OrdinalIgnoreCase)) - { - Copy(runnerFolder, publishFolder, "*.*", true); - Copy(xunitCoreFolder, publishFolder, "*.*", true); - runnerFullPath = Path.GetFullPath(Path.Combine(publishFolder, runnerExe)); - } - else - { - runnerFullPath = Path.Combine(runnerFolder, runnerExe); - } - - var targetTestDll = projectName + ".dll"; - - ExecClr(runnerFullPath, targetTestDll + " " + testArgs, publishFolder); - } + noParallelTestProjects.UnionWith(NO_PARALLEL_TEST_PROJECTS.Split((char)',')); } + + var testArgs = noParallelTestProjects.Contains(projectName) ? " -parallel none" : ""; + var runnerFolder = Path.GetFullPath(Path.Combine(KoreBuildFolderPath, "build", "xunit.runner.console", "tools")); + var xunitCoreFolder = Path.GetFullPath(Path.Combine(KoreBuildFolderPath, "build", "xunit.core", "build", "_desktop")); + + if (IsLinux) + { + // Work around issue with testing in parallel on Mono. + testArgs = " -parallel none"; + } + + var publishFolder = Path.Combine(projectFolder, "obj", "testPublish-" + framework); + DotnetPublish(projectFile, publishFolder, framework, configuration); + + var runnerExe = "xunit.console.exe"; + Copy(runnerFolder, publishFolder, "*.*", true); + Copy(xunitCoreFolder, publishFolder, "*.*", true); + var runnerFullPath = Path.GetFullPath(Path.Combine(publishFolder, runnerExe)); + + var targetTestDll = projectName + ".dll"; + + ExecClr(runnerFullPath, targetTestDll + " " + testArgs, publishFolder); } }