From e48bb0e640715441666fe1e25805ffdc6e55a8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20H=C3=A5kansson?= Date: Fri, 2 Jun 2017 10:24:00 +0200 Subject: [PATCH] Improved test execution task --- build.cake | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/build.cake b/build.cake index 875f6ec263..0d2c9a9940 100644 --- a/build.cake +++ b/build.cake @@ -68,14 +68,16 @@ Task("Compile") var content = System.IO.File.ReadAllText(project.FullPath, Encoding.UTF8); - if (IsRunningOnUnix() && content.Contains(">" + fullFrameworkTarget + "<")) { + if (IsRunningOnUnix() && content.Contains(">" + fullFrameworkTarget + "<")) + { Information(project.GetFilename() + " only supports " +fullFrameworkTarget + " and cannot be built on *nix. Skipping."); continue; } DotNetCoreBuild(project.GetDirectory().FullPath, new DotNetCoreBuildSettings { ArgumentCustomization = args => { - if (IsRunningOnUnix()) { + if (IsRunningOnUnix()) + { args.Append(string.Concat("-f ", project.GetDirectory().GetDirectoryName().Contains(".Tests") ? netCoreTarget : netStandardTarget)); } @@ -135,7 +137,8 @@ Task("Publish-NuGet") .Description("Pushes the nuget packages in the nuget folder to a NuGet source. Also publishes the packages into the feeds.") .Does(() => { - if(string.IsNullOrWhiteSpace(apiKey)) { + if(string.IsNullOrWhiteSpace(apiKey)) + { throw new CakeException("No NuGet API key provided. You need to pass in --apikey=\"xyz\""); } @@ -234,8 +237,15 @@ Task("Test") .IsDependentOn("Compile") .Does(() => { + /* + Exclude Nancy.ViewEngines.Spark.Tests from test execution until their problem + with duplicate assembly references (if the same assembly exists more than once + in the application domain, it fails to compile the views) has been fixed. + */ + var projects = - GetFiles("./test/**/*.csproj"); + GetFiles("./test/**/*.csproj") - + GetFiles("./test/Nancy.ViewEngines.Spark.Tests/Nancy.ViewEngines.Spark.Tests.csproj"); if (projects.Count == 0) { @@ -247,21 +257,28 @@ Task("Test") var content = System.IO.File.ReadAllText(project.FullPath, Encoding.UTF8); - if (IsRunningOnUnix() && content.Contains(">" + fullFrameworkTarget + "<")) { + if (IsRunningOnUnix() && content.Contains(">" + fullFrameworkTarget + "<")) + { Information(project.GetFilename() + " only supports " +fullFrameworkTarget + " and tests cannot be executed on *nix. Skipping."); continue; } var settings = new ProcessSettings { - Arguments = string.Concat("xunit -configuration ", configuration, " -nobuild -verbose"), + Arguments = string.Concat("xunit -configuration ", configuration, " -nobuild"), WorkingDirectory = project.GetDirectory() }; - if (IsRunningOnUnix()) { + if (IsRunningOnUnix()) + { settings.Arguments.Append(string.Concat("-framework ", netCoreTarget)); } - StartProcess("dotnet", settings); + Information("Executing tests for " + project.GetFilename() + " with arguments: " + settings.Arguments.Render()); + + if (StartProcess("dotnet", settings) != 0) + { + Error("One or more tests failed during execution of: " + project.GetFilename()); + } } }); @@ -270,7 +287,8 @@ Task("Update-Version") { Information("Setting version to " + version); - if(string.IsNullOrWhiteSpace(version)) { + if(string.IsNullOrWhiteSpace(version)) + { throw new CakeException("No version specified! You need to pass in --targetversion=\"x.y.z\""); }