From 9d6b227226ac800b038aa82d6af20c558ecd613c Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Fri, 28 Feb 2014 11:26:33 -0800 Subject: [PATCH] Run tests during build --- build/_k-standard-goals.shade | 3 +++ build/_k-test.shade | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 build/_k-test.shade diff --git a/build/_k-standard-goals.shade b/build/_k-standard-goals.shade index 6c303167dd..008375877b 100644 --- a/build/_k-standard-goals.shade +++ b/build/_k-standard-goals.shade @@ -60,6 +60,9 @@ default Configuration='Release' #nuget-install target='install' description='Copy NuGet packages to local repo' nuget-local-publish sourcePackagesDir='${BUILD_DIR}' +#xunit-test target='test' if='Directory.Exists("test")' + k-test each='var projectFile in Files.Include("test/**/project.json")' + #make-roslyn-fast ngen-roslyn diff --git a/build/_k-test.shade b/build/_k-test.shade new file mode 100644 index 0000000000..6182aeb514 --- /dev/null +++ b/build/_k-test.shade @@ -0,0 +1,33 @@ +use namespace='System.Web.Script.Serialization' +use assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" + +@{/* + +k-test + Run unit tests in your project. + +projectFile='' + Required. Path to the test project.json to execute + +*/} + +var projectFolder='${Path.GetDirectoryName(projectFile)}' + +k command='test' workingdir='${projectFolder}' if='HasTestCommand(projectFile)' + +functions + @{ + bool HasTestCommand(string projectFile) + { + var serializer = new JavaScriptSerializer(); + var projectText = File.ReadAllText(projectFile); + var project = (Dictionary)serializer.DeserializeObject(projectText); + + object commandsObject; + if (!project.TryGetValue("commands", out commandsObject)) + return false; + var commands = (Dictionary)commandsObject; + + return commands.Keys.Contains("test"); + } + }