diff --git a/.gitignore b/.gitignore index 97ba28c02d..da3704a29a 100644 --- a/.gitignore +++ b/.gitignore @@ -285,4 +285,9 @@ tools/** *.btp.cs *.btm.cs *.odx.cs -*.xsd.cs \ No newline at end of file +*.xsd.cs + + + + +/coverage.xml \ No newline at end of file diff --git a/BencodeNET.Tests/BencodeNET.Tests.csproj b/BencodeNET.Tests/BencodeNET.Tests.csproj index cfc4c1c075..4ce52f2378 100644 --- a/BencodeNET.Tests/BencodeNET.Tests.csproj +++ b/BencodeNET.Tests/BencodeNET.Tests.csproj @@ -9,6 +9,9 @@ PreserveNewest + + PreserveNewest + @@ -23,11 +26,11 @@ - - - - - + + + + + diff --git a/BencodeNET.Tests/xunit.runner.json b/BencodeNET.Tests/xunit.runner.json new file mode 100644 index 0000000000..2c2dfba788 --- /dev/null +++ b/BencodeNET.Tests/xunit.runner.json @@ -0,0 +1,3 @@ +{ + "shadowCopy": false +} \ No newline at end of file diff --git a/BencodeNET/BencodeNET.csproj b/BencodeNET/BencodeNET.csproj index 4ab2e23302..2a900352d9 100644 --- a/BencodeNET/BencodeNET.csproj +++ b/BencodeNET/BencodeNET.csproj @@ -6,6 +6,11 @@ True + + + full + + BencodeNET 2.2.0 diff --git a/build.cake b/build.cake index 59f4ff387d..698b0986ca 100644 --- a/build.cake +++ b/build.cake @@ -1,35 +1,144 @@ -var target = Argument("target", "Default"); +// Install addins. +#addin "nuget:?package=Cake.Coveralls&version=0.5.0" -Task("Set-Build-Version") +// Install tools. +#tool "nuget:?package=OpenCover&version=4.6.519" +#tool "nuget:?package=coveralls.io&version=1.3.4" +#tool "nuget:?package=xunit.runner.console&version=2.2.0" + + +/////////////////////////////////////////////////////////////////////////////// +// ARGUMENTS +/////////////////////////////////////////////////////////////////////////////// + +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); + + +/////////////////////////////////////////////////////////////////////////////// +// GLOBAL VARIABLES +/////////////////////////////////////////////////////////////////////////////// + +var libraryName = "BencodeNET"; + +var sourceFolder = "./"; + +var projectFile = "./BencodeNET/BencodeNET.csproj"; + +var testProjectFile = "./BencodeNET.Tests/BencodeNET.Tests.csproj"; +var codeCoverageOutput = "coverage.xml"; +var codeCoverageFilter = "+[*]* -[*.Tests]*"; + +var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString(); + + +/////////////////////////////////////////////////////////////////////////////// +// SETUP / TEARDOWN +/////////////////////////////////////////////////////////////////////////////// + +Setup(context => +{ + Information($"Building using version {cakeVersion} of Cake"); +}); + + +/////////////////////////////////////////////////////////////////////////////// +// TASK DEFINITIONS +/////////////////////////////////////////////////////////////////////////////// + +Task("Update-Build-Version") + .WithCriteria(() => AppVeyor.IsRunningOnAppVeyor) .Does(() => { - var projectFile = "./BencodeNET/BencodeNET.csproj"; var versionPeekXpath = "/Project/PropertyGroup/Version/text()"; var versionPokeXpath = "/Project/PropertyGroup/Version"; + var buildNumber = AppVeyor.Environment.Build.Number; var version = XmlPeek(projectFile, versionPeekXpath); + + Information("AppVeyor build version is " + AppVeyor.Environment.Build.Version); + Information("Project version is " + version); + var parts = version.Split('.'); + version = string.Join(".", parts[0], parts[1], buildNumber); + + Information("Changing versions to " + version); + + AppVeyor.UpdateBuildVersion(version); + XmlPoke(projectFile, versionPokeXpath, version); +}); - var buildNumber = 0; +Task("Restore-NuGet-Packages") + .Does(() => +{ + DotNetCoreRestore(); +}); - if (BuildSystem.IsRunningOnAppVeyor) +Task("Build") + .IsDependentOn("Restore-NuGet-Packages") + .Does(() => +{ + DotNetCoreBuild(sourceFolder + libraryName + ".sln", new DotNetCoreBuildSettings { - buildNumber = AppVeyor.Environment.Build.Number; - } + Configuration = configuration + }); +}); - version = string.Join(".", parts[0], parts[1], buildNumber); +Task("Run-Unit-Tests") + .IsDependentOn("Build") + .Does(() => +{ + DotNetCoreTest(testProjectFile, new DotNetCoreTestSettings + { + NoBuild = true, + Configuration = configuration + }); +}); - if (BuildSystem.IsRunningOnAppVeyor) +Task("Run-Code-Coverage") + .IsDependentOn("Build") + .Does(() => +{ + Action testAction = ctx => ctx.DotNetCoreTest(testProjectFile, new DotNetCoreTestSettings { - AppVeyor.UpdateBuildVersion(version); - Information("Updated AppVeyor build version to " + version); - } + NoBuild = true, + Configuration = configuration + }); - XmlPoke(projectFile, versionPokeXpath, version); - Information("Set project version to " + version); + OpenCover(testAction, + codeCoverageOutput, + new OpenCoverSettings + { + OldStyle = true, + SkipAutoProps = true, + MergeOutput = false + } + .WithFilter(codeCoverageFilter) + ); +}); + +Task("Upload-Coverage-Result") + .Does(() => +{ + CoverallsIo(codeCoverageOutput); }); + +/////////////////////////////////////////////////////////////////////////////// +// TARGETS +/////////////////////////////////////////////////////////////////////////////// + +Task("AppVeyor") + .IsDependentOn("Update-Build-Version") + .IsDependentOn("Run-Code-Coverage") + .IsDependentOn("Upload-Coverage-Result"); + Task("Default") - .IsDependentOn("Set-Build-Version"); + .IsDependentOn("AppVeyor"); + + +/////////////////////////////////////////////////////////////////////////////// +// EXECUTION +/////////////////////////////////////////////////////////////////////////////// RunTarget(target); \ No newline at end of file diff --git a/tools/packages.config b/tools/packages.config new file mode 100644 index 0000000000..ba021c5340 --- /dev/null +++ b/tools/packages.config @@ -0,0 +1,4 @@ + + + +