From c3deb8415ff948a8fe442b9e5e56000e6136a730 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 2 Feb 2016 02:33:43 +0200 Subject: [PATCH] [Tests] Added the test run to the Cake script --- build.cake | 36 +++++++---- cake.packages.config | 1 + common.cake | 64 ++++++++++++++++++- .../Skia.WindowsDesktop.Demo.sln | 14 ---- .../SkiaSharp.WindowsDesktop.Tests.csproj | 2 +- 5 files changed, 90 insertions(+), 27 deletions(-) diff --git a/build.cake b/build.cake index 7e1fe4f1e..ef5b9f680 100644 --- a/build.cake +++ b/build.cake @@ -115,6 +115,27 @@ CakeSpec.Samples = new ISolutionBuilder [] { }, }; +CakeSpec.Tests = new SolutionTestRunner [] { + new SolutionTestRunner { + SolutionBuilder = new DefaultSolutionBuilder { + IsWindowsCompatible = true, + IsMacCompatible = false, + SolutionPath = "./tests/SkiaSharp.WindowsDesktop.Tests/SkiaSharp.WindowsDesktop.Tests.sln", + Platform = "x86", + }, + TestAssembly = "./tests/SkiaSharp.WindowsDesktop.Tests/bin/x86/Release/SkiaSharp.WindowsDesktop.Tests.dll", + }, + new SolutionTestRunner { + SolutionBuilder = new DefaultSolutionBuilder { + IsWindowsCompatible = true, + IsMacCompatible = false, + SolutionPath = "./tests/SkiaSharp.WindowsDesktop.Tests/SkiaSharp.WindowsDesktop.Tests.sln", + Platform = "x64", + }, + TestAssembly = "./tests/SkiaSharp.WindowsDesktop.Tests/bin/x64/Release/SkiaSharp.WindowsDesktop.Tests.dll", + }, +}; + CakeSpec.NuSpecs = new [] { "./nuget/Xamarin.SkiaSharp.nuspec" }; @@ -136,17 +157,10 @@ Task ("externals") FilePath input = "binding/SkiaSharp.Generic/bin/Release/SkiaSharp.dll"; var libPath = "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/,."; - if (IsRunningOnUnix ()) { - StartProcess ("mono", new ProcessSettings { - Arguments = string.Format("\"{0}\" -libPath:{3} -out \"{1}\" \"{2}\"", CakeStealer.GenApiToolPath, input.GetFilename () + ".cs", input.GetFilename (), libPath), - WorkingDirectory = input.GetDirectory ().FullPath, - }); - } else { - StartProcess (CakeStealer.GenApiToolPath, new ProcessSettings { - Arguments = string.Format("-libPath:{2} -out \"{0}\" \"{1}\"", input.GetFilename () + ".cs", input.GetFilename (), libPath), - WorkingDirectory = input.GetDirectory ().FullPath, - }); - } + StartProcess (CakeStealer.GenApiToolPath, new ProcessSettings { + Arguments = string.Format("-libPath:{2} -out \"{0}\" \"{1}\"", input.GetFilename () + ".cs", input.GetFilename (), libPath), + WorkingDirectory = input.GetDirectory ().FullPath, + }); CopyFile ("binding/SkiaSharp.Generic/bin/Release/SkiaSharp.dll.cs", "binding/SkiaSharp.Portable/SkiaPortable.cs"); }); diff --git a/cake.packages.config b/cake.packages.config index 5982bc1ff..e3d50c217 100644 --- a/cake.packages.config +++ b/cake.packages.config @@ -1,4 +1,5 @@ + diff --git a/common.cake b/common.cake index e0f3ac2c6..1469b0ebb 100644 --- a/common.cake +++ b/common.cake @@ -21,6 +21,18 @@ FilePath GetCakeToolPath () return new FilePath (p.Modules[0].FileName); } +FilePath GetNUnitConsoleToolPath () +{ + var appRoot = Context.Environment.GetApplicationRoot (); + + var consolePath = appRoot.Combine ("../").CombineWithFilePath ("NUnit.Console/tools/nunit3-console.exe"); + + if (FileExists (consolePath)) + return consolePath; + + return GetFiles ("../../../**/nunit3-console.exe").FirstOrDefault (); +} + FilePath GetNugetToolPath () { if (IsRunningOnUnix ()) @@ -97,9 +109,11 @@ CakeStealer.NuGetSources = NUGET_RESTORE_SOURCES; CakeStealer.NugetToolPath = GetNugetToolPath (); CakeStealer.XamarinComponentToolPath = GetXamarinComponentToolPath (); CakeStealer.CakeToolPath = GetCakeToolPath (); +CakeStealer.NUnitConsoleToolPath = GetNUnitConsoleToolPath (); CakeStealer.GenApiToolPath = GetGenApiToolPath (); Information ("Cake.exe ToolPath: {0}", CakeStealer.CakeToolPath); +Information ("Cake.exe NUnitConsoleToolPath: {0}", CakeStealer.NUnitConsoleToolPath); Information ("NuGet.exe ToolPath: {0}", CakeStealer.NugetToolPath); Information ("Xamarin-Component.exe ToolPath: {0}", CakeStealer.XamarinComponentToolPath); Information ("genapi.exe ToolPath: {0}", CakeStealer.GenApiToolPath); @@ -120,6 +134,7 @@ public class CakeStealer static public FilePath NugetToolPath { get;set; } static public FilePath XamarinComponentToolPath { get; set; } static public FilePath CakeToolPath { get;set; } + static public FilePath NUnitConsoleToolPath { get;set; } static public FilePath GenApiToolPath { get;set; } } @@ -168,7 +183,7 @@ public class DefaultSolutionBuilder : CakeStealer, ISolutionBuilder public Action PreBuildAction { get;set; } public Action PostBuildAction { get;set; } - protected virtual bool CanBuildOnPlatform { + public virtual bool CanBuildOnPlatform { get { if (CakeContext.IsRunningOnWindows () && !IsWindowsCompatible) return false; @@ -332,16 +347,50 @@ public class WpSolutionBuilder : DefaultSolutionBuilder } } +public class SolutionTestRunner : CakeStealer +{ + public DefaultSolutionBuilder SolutionBuilder { get; set; } + + public FilePath TestAssembly { get; set; } + + public DirectoryPath TestDiectory { get; set; } + + public void BuildSolution () + { + SolutionBuilder.BuildSolution (); + SolutionBuilder.CopyOutput (); + } + + public void RunTests () + { + if (!SolutionBuilder.CanBuildOnPlatform) { + CakeContext.Information ("Solution is not configured to run test on this platform: {0}", SolutionBuilder.SolutionPath); + return; + } + + var dir = TestDiectory == null ? TestAssembly.GetDirectory() : TestDiectory; + var result = CakeContext.StartProcess(NUnitConsoleToolPath, new ProcessSettings { + Arguments = string.Format ("\"{0}\" --work=\"{1}\"", TestAssembly, dir), + }); + + if (result != 0) { + throw new Exception ("NUnit test failed with error: " + result); + } + } +} + class CakeSpec { static CakeSpec () { Libs = new ISolutionBuilder [] {}; + Tests = new SolutionTestRunner [] {}; Samples = new ISolutionBuilder [] {}; NuSpecs = new string [] {}; } static public ISolutionBuilder [] Libs { get; set; } + static public SolutionTestRunner [] Tests { get; set; } static public ISolutionBuilder [] Samples { get; set; } static public string [] NuSpecs { get; set; } } @@ -482,6 +531,19 @@ void DefineDefaultTasks () Task ("libs").IsDependentOn ("externals").IsDependentOn ("libs-base"); } + Task ("tests-base").Does (() => + { + foreach (var t in CakeSpec.Tests) { + t.BuildSolution (); + t.RunTests (); + } + }); + + if (!Tasks.Where (tsk => tsk.Name == "tests").Any ()) + { + Task ("tests").IsDependentOn ("libs").IsDependentOn ("tests-base"); + } + Task ("samples-base").Does (() => { foreach (var s in CakeSpec.Samples) { diff --git a/samples/Skia.WindowsDesktop.Demo/Skia.WindowsDesktop.Demo.sln b/samples/Skia.WindowsDesktop.Demo/Skia.WindowsDesktop.Demo.sln index 9e7b0da0a..d0d7c0678 100644 --- a/samples/Skia.WindowsDesktop.Demo/Skia.WindowsDesktop.Demo.sln +++ b/samples/Skia.WindowsDesktop.Demo/Skia.WindowsDesktop.Demo.sln @@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skia.WindowsDesktop.Demo", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.WindowsDesktop", "..\..\binding\SkiaSharp.WindowsDesktop\SkiaSharp.WindowsDesktop.csproj", "{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.WindowsDesktop.Tests", "..\..\tests\SkiaSharp.WindowsDesktop.Tests\SkiaSharp.WindowsDesktop.Tests.csproj", "{F0179CDB-9435-4FB4-8E52-DBF191079491}" -EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution ..\..\binding\Binding\Binding.projitems*{9c502b9a-25d4-473f-89bd-5a13dde16354}*SharedItemsImports = 13 @@ -49,18 +47,6 @@ Global {EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x64.Build.0 = Release|x64 {EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x86.ActiveCfg = Release|x86 {EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x86.Build.0 = Release|x86 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x64.ActiveCfg = Debug|x64 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x64.Build.0 = Debug|x64 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x86.ActiveCfg = Debug|x86 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x86.Build.0 = Debug|x86 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|Any CPU.Build.0 = Release|Any CPU - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x64.ActiveCfg = Release|x64 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x64.Build.0 = Release|x64 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x86.ActiveCfg = Release|x86 - {F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/tests/SkiaSharp.WindowsDesktop.Tests/SkiaSharp.WindowsDesktop.Tests.csproj b/tests/SkiaSharp.WindowsDesktop.Tests/SkiaSharp.WindowsDesktop.Tests.csproj index 31b3e9c6d..2df520681 100644 --- a/tests/SkiaSharp.WindowsDesktop.Tests/SkiaSharp.WindowsDesktop.Tests.csproj +++ b/tests/SkiaSharp.WindowsDesktop.Tests/SkiaSharp.WindowsDesktop.Tests.csproj @@ -59,7 +59,7 @@ pdbonly true - bin\x64\Release\ + bin\x86\Release\ TRACE x86 prompt