From 2fba285a3cd81952ba036628104ed29243af7a2f Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 20:36:09 -0400 Subject: [PATCH 1/9] Code coverage --- Content/.gitignore | 1 + Content/.paket/Paket.Restore.targets | 13 +++--- Content/build.fsx | 33 +++++++++++++- Content/paket.dependencies | 3 ++ Content/paket.lock | 4 +- Content/src/MyLib/Library.fs | 4 ++ Content/tests/Directory.Build.targets | 48 ++++++++++++++++++++ Content/tests/MyLib.Tests/Main.fs | 42 ++++++++--------- Content/tests/MyLib.Tests/MyLib.Tests.fsproj | 4 ++ Content/tests/MyLib.Tests/Tests.fs | 5 ++ Content/tests/MyLib.Tests/paket.references | 2 +- 11 files changed, 129 insertions(+), 30 deletions(-) create mode 100644 Content/tests/Directory.Build.targets diff --git a/Content/.gitignore b/Content/.gitignore index b13edf91..61519363 100644 --- a/Content/.gitignore +++ b/Content/.gitignore @@ -254,3 +254,4 @@ paket-files/ TestResults.xml dist/ +lcov.info diff --git a/Content/.paket/Paket.Restore.targets b/Content/.paket/Paket.Restore.targets index e7c1bc0c..44afec51 100644 --- a/Content/.paket/Paket.Restore.targets +++ b/Content/.paket/Paket.Restore.targets @@ -48,16 +48,16 @@ - /usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }' - /usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }' + /usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }' + /usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }' - + - + @@ -127,6 +127,7 @@ %(PaketReferencesFileLinesInfo.PackageVersion) All + runtime @@ -183,8 +184,8 @@ - - + + Seq.exists ((=)"Release") Target "Clean" (fun _ -> - ["bin"; "temp" ; distDir] + ["bin"; "temp" ; distDir; coverageReportDir] |> CleanDirs !! srcGlob @@ -91,6 +94,33 @@ Target "DotnetTest" (fun _ -> }) ) +Target "GenerateCoverageReport" (fun _ -> + let reportGenerator = "packages/build/ReportGenerator/tools/ReportGenerator.exe" + let coverageReports = + !!"tests/**/_Reports/MSBuildTest.xml" + |> String.concat ";" + let sourceDirs = + !! srcGlob + |> Seq.map DirectoryName + |> String.concat ";" + + let args = + String.concat " " <| + [ + sprintf "-reports:%s" coverageReports + sprintf "-targetdir:%s" coverageReportDir + // Add source dir + sprintf "-sourcedirs:%s" sourceDirs + // Ignore Tests and if AltCover.Recorder.g sneaks in + sprintf "-assemblyfilters:%s" "-*.Tests;-AltCover.Recorder.g" + sprintf "-Reporttypes:%s" "Html" + ] + tracefn "%s %s" reportGenerator args + let exitCode = Shell.Exec(reportGenerator, args = args) + () + +) + Target "WatchTests" (fun _ -> !! testsGlob @@ -247,6 +277,7 @@ Target "Release" DoNothing "DotnetRestore" ==> "DotnetBuild" ==> "DotnetTest" + ==> "GenerateCoverageReport" ==> "DotnetPack" ==> "SourcelinkTest" ==> "Publish" diff --git a/Content/paket.dependencies b/Content/paket.dependencies index 479a3a08..687a324f 100644 --- a/Content/paket.dependencies +++ b/Content/paket.dependencies @@ -9,8 +9,11 @@ nuget SourceLink.Create.CommandLine 2.8.0 copy_local: true nuget YoloDev.Expecto.TestSdk nuget Microsoft.NET.Test.Sdk + group Build framework: >= net45 source https://www.nuget.org/api/v2 nuget FAKE github fsharp/FAKE modules/Octokit/Octokit.fsx + nuget altcover + nuget ReportGenerator diff --git a/Content/paket.lock b/Content/paket.lock index 18a0614f..cd3214f7 100644 --- a/Content/paket.lock +++ b/Content/paket.lock @@ -1345,9 +1345,11 @@ GROUP Build RESTRICTION: >= net45 NUGET remote: https://www.nuget.org/api/v2 + altcover (3.0.433) FAKE (4.64.11) Octokit (0.29) + ReportGenerator (3.1.2) GITHUB remote: fsharp/FAKE - modules/Octokit/Octokit.fsx (c160d4907360cfd42904008dab2bd22c0a4a9952) + modules/Octokit/Octokit.fsx (800579e69ce35b77345ee21923ddf117168067cd) Octokit (>= 0.20) \ No newline at end of file diff --git a/Content/src/MyLib/Library.fs b/Content/src/MyLib/Library.fs index 82d2a2a6..96a28af2 100755 --- a/Content/src/MyLib/Library.fs +++ b/Content/src/MyLib/Library.fs @@ -1,5 +1,9 @@ namespace MyLib module Say = + let nothing name = + name |> ignore + let hello name = sprintf "Hello %s" name + diff --git a/Content/tests/Directory.Build.targets b/Content/tests/Directory.Build.targets new file mode 100644 index 00000000..69ece877 --- /dev/null +++ b/Content/tests/Directory.Build.targets @@ -0,0 +1,48 @@ + + + <_TargetFramework Include="$(TargetFrameworks)" /> + + + + + + + + + + + + + diff --git a/Content/tests/MyLib.Tests/Main.fs b/Content/tests/MyLib.Tests/Main.fs index 83e06e0f..6c6c2365 100644 --- a/Content/tests/MyLib.Tests/Main.fs +++ b/Content/tests/MyLib.Tests/Main.fs @@ -3,31 +3,31 @@ open Expecto open System.Reflection -module AssemblyInfo = +// module AssemblyInfo = - let metaDataValue (mda : AssemblyMetadataAttribute) = mda.Value - let getMetaDataAttribute (assembly : Assembly) key = - assembly.GetCustomAttributes(typedefof) - |> Seq.cast - |> Seq.find(fun x -> x.Key = key) +// let metaDataValue (mda : AssemblyMetadataAttribute) = mda.Value +// let getMetaDataAttribute (assembly : Assembly) key = +// assembly.GetCustomAttributes(typedefof) +// |> Seq.cast +// |> Seq.find(fun x -> x.Key = key) - let getReleaseDate assembly = - "ReleaseDate" - |> getMetaDataAttribute assembly - |> metaDataValue +// let getReleaseDate assembly = +// "ReleaseDate" +// |> getMetaDataAttribute assembly +// |> metaDataValue - let getGitHash assembly = - "GitHash" - |> getMetaDataAttribute assembly - |> metaDataValue +// let getGitHash assembly = +// "GitHash" +// |> getMetaDataAttribute assembly +// |> metaDataValue [] let main argv = - if argv |> Seq.contains ("--version") then - let assembly = Assembly.GetEntryAssembly() - let name = assembly.GetName() - let version = assembly.GetName().Version - let releaseDate = AssemblyInfo.getReleaseDate assembly - let githash = AssemblyInfo.getGitHash assembly - printfn "%s - %A - %s - %s" name.Name version releaseDate githash + // if argv |> Seq.contains ("--version") then + // let assembly = Assembly.GetEntryAssembly() + // let name = assembly.GetName() + // let version = assembly.GetName().Version + // let releaseDate = AssemblyInfo.getReleaseDate assembly + // let githash = AssemblyInfo.getGitHash assembly + // printfn "%s - %A - %s - %s" name.Name version releaseDate githash Tests.runTestsInAssembly defaultConfig argv diff --git a/Content/tests/MyLib.Tests/MyLib.Tests.fsproj b/Content/tests/MyLib.Tests/MyLib.Tests.fsproj index 3256c7d0..99114a8b 100755 --- a/Content/tests/MyLib.Tests/MyLib.Tests.fsproj +++ b/Content/tests/MyLib.Tests/MyLib.Tests.fsproj @@ -4,6 +4,7 @@ Exe netcoreapp2.0;net461 + @@ -12,5 +13,8 @@ + + + diff --git a/Content/tests/MyLib.Tests/Tests.fs b/Content/tests/MyLib.Tests/Tests.fs index 6007272c..98147943 100755 --- a/Content/tests/MyLib.Tests/Tests.fs +++ b/Content/tests/MyLib.Tests/Tests.fs @@ -7,7 +7,12 @@ open MyLib [] let tests = testList "samples" [ + testCase "Say nothing" <| fun _ -> + let subject = Say.nothing () + Expect.equal subject () "You need a math class" testCase "Say hello all" <| fun _ -> let subject = Say.hello "all" Expect.equal subject "Hello all" "You didn't say hello" + + ] diff --git a/Content/tests/MyLib.Tests/paket.references b/Content/tests/MyLib.Tests/paket.references index 55b3c1ce..080c9064 100644 --- a/Content/tests/MyLib.Tests/paket.references +++ b/Content/tests/MyLib.Tests/paket.references @@ -2,5 +2,5 @@ Expecto FSharp.Core Microsoft.DotNet.Watcher.Tools dotnet-mono -YoloDev.Expecto.TestSdk Microsoft.NET.Test.Sdk +YoloDev.Expecto.TestSdk From c53bb597cd52e87541d499e4ee9c192dbe1a957f Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 20:39:02 -0400 Subject: [PATCH 2/9] Add AltCover to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 87e0b7e4..2e3458fe 100644 --- a/README.md +++ b/README.md @@ -174,3 +174,4 @@ This is because dotnet template loses permissions of files. (https://github.com/ * Heavily inspired by [Project Scaffold](https://github.com/fsprojects/ProjectScaffold) * [Buildstats.info](https://github.com/dustinmoris/CI-BuildStats) * [SourceLink](https://github.com/ctaggart/SourceLink) +* [AltCover](https://github.com/SteveGilham/altcover) From a937ac43cf0440bc15e73651307b81adba908f56 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 20:48:04 -0400 Subject: [PATCH 3/9] clean up tests main file --- Content/tests/MyLib.Tests/Main.fs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/Content/tests/MyLib.Tests/Main.fs b/Content/tests/MyLib.Tests/Main.fs index 6c6c2365..c378bd42 100644 --- a/Content/tests/MyLib.Tests/Main.fs +++ b/Content/tests/MyLib.Tests/Main.fs @@ -1,33 +1,6 @@ module ExpectoTemplate open Expecto -open System.Reflection - - -// module AssemblyInfo = - -// let metaDataValue (mda : AssemblyMetadataAttribute) = mda.Value -// let getMetaDataAttribute (assembly : Assembly) key = -// assembly.GetCustomAttributes(typedefof) -// |> Seq.cast -// |> Seq.find(fun x -> x.Key = key) - -// let getReleaseDate assembly = -// "ReleaseDate" -// |> getMetaDataAttribute assembly -// |> metaDataValue - -// let getGitHash assembly = -// "GitHash" -// |> getMetaDataAttribute assembly -// |> metaDataValue [] let main argv = - // if argv |> Seq.contains ("--version") then - // let assembly = Assembly.GetEntryAssembly() - // let name = assembly.GetName() - // let version = assembly.GetName().Version - // let releaseDate = AssemblyInfo.getReleaseDate assembly - // let githash = AssemblyInfo.getGitHash assembly - // printfn "%s - %A - %s - %s" name.Name version releaseDate githash Tests.runTestsInAssembly defaultConfig argv From daa39af80c6da692e9c0d39c316b0751d94462af Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 21:07:47 -0400 Subject: [PATCH 4/9] Cleaning up --- Content/build.fsx | 5 ++-- Content/tests/MyLib.Tests/MyLib.Tests.fsproj | 30 +++++++++----------- Content/tests/MyLib.Tests/Tests.fs | 4 +-- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Content/build.fsx b/Content/build.fsx index e11b500a..22103a7e 100644 --- a/Content/build.fsx +++ b/Content/build.fsx @@ -24,7 +24,6 @@ let configuration = EnvironmentHelper.environVarOrDefault "CONFIGURATION" "Release" - module dotnet = let watch program cmdParam args = let argConcat = @@ -117,8 +116,8 @@ Target "GenerateCoverageReport" (fun _ -> ] tracefn "%s %s" reportGenerator args let exitCode = Shell.Exec(reportGenerator, args = args) - () - + if exitCode <> 0 then + failwithf "%s failed with exit code: %d" reportGenerator exitCode ) diff --git a/Content/tests/MyLib.Tests/MyLib.Tests.fsproj b/Content/tests/MyLib.Tests/MyLib.Tests.fsproj index 99114a8b..41f6efc6 100755 --- a/Content/tests/MyLib.Tests/MyLib.Tests.fsproj +++ b/Content/tests/MyLib.Tests/MyLib.Tests.fsproj @@ -1,20 +1,16 @@ - - Exe - netcoreapp2.0;net461 - - - - - - - - - - - - - - + + Exe + netcoreapp2.0;net461 + + + + + + + + + + diff --git a/Content/tests/MyLib.Tests/Tests.fs b/Content/tests/MyLib.Tests/Tests.fs index 98147943..616b8641 100755 --- a/Content/tests/MyLib.Tests/Tests.fs +++ b/Content/tests/MyLib.Tests/Tests.fs @@ -9,10 +9,8 @@ let tests = testList "samples" [ testCase "Say nothing" <| fun _ -> let subject = Say.nothing () - Expect.equal subject () "You need a math class" + Expect.equal subject () "Not an absolute unit" testCase "Say hello all" <| fun _ -> let subject = Say.hello "all" Expect.equal subject "Hello all" "You didn't say hello" - - ] From 77f3d493674c2b7538e9414adde3a41aaf7fbd85 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 21:18:23 -0400 Subject: [PATCH 5/9] Update altcover --- Content/.paket/Paket.Restore.targets | 10 ++++++---- Content/paket.lock | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Content/.paket/Paket.Restore.targets b/Content/.paket/Paket.Restore.targets index 44afec51..3795978d 100644 --- a/Content/.paket/Paket.Restore.targets +++ b/Content/.paket/Paket.Restore.targets @@ -43,13 +43,13 @@ true - $(NoWarn);NU1603 + $(NoWarn);NU1603;NU1604;NU1605;NU1608 - /usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }' - /usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }' + /usr/bin/shasum "$(PaketRestoreCacheFile)" | /usr/bin/awk '{ print $1 }' + /usr/bin/shasum "$(PaketLockFilePath)" | /usr/bin/awk '{ print $1 }' @@ -69,9 +69,11 @@ true + - + + diff --git a/Content/paket.lock b/Content/paket.lock index cd3214f7..773491f2 100644 --- a/Content/paket.lock +++ b/Content/paket.lock @@ -1345,11 +1345,11 @@ GROUP Build RESTRICTION: >= net45 NUGET remote: https://www.nuget.org/api/v2 - altcover (3.0.433) + altcover (3.0.466) FAKE (4.64.11) Octokit (0.29) ReportGenerator (3.1.2) GITHUB remote: fsharp/FAKE - modules/Octokit/Octokit.fsx (800579e69ce35b77345ee21923ddf117168067cd) + modules/Octokit/Octokit.fsx (38b77b8d3ed67f0b9b0402f5c79774cb477c1c8d) Octokit (>= 0.20) \ No newline at end of file From ea596c7ecafe97dd93b71f3d8006b3244c20449a Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 21:28:33 -0400 Subject: [PATCH 6/9] debug windows altcover part1 --- Content/build.fsx | 1 + 1 file changed, 1 insertion(+) diff --git a/Content/build.fsx b/Content/build.fsx index 22103a7e..ef44548b 100644 --- a/Content/build.fsx +++ b/Content/build.fsx @@ -89,6 +89,7 @@ Target "DotnetTest" (fun _ -> AdditionalArgs = [ "--no-build" + "-v n" ] }) ) From 6c0c41a684832dc9439a9cb14620af12b4c45ae6 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 21:47:27 -0400 Subject: [PATCH 7/9] debug windows --- Content/build.fsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content/build.fsx b/Content/build.fsx index ef44548b..22c6e2c3 100644 --- a/Content/build.fsx +++ b/Content/build.fsx @@ -89,7 +89,7 @@ Target "DotnetTest" (fun _ -> AdditionalArgs = [ "--no-build" - "-v n" + "-v d" ] }) ) From f047c25d1a75024ce02d98c25a5082e92edb28d4 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Wed, 9 May 2018 22:14:20 -0400 Subject: [PATCH 8/9] fixing windows file paths --- Content/tests/Directory.Build.targets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Content/tests/Directory.Build.targets b/Content/tests/Directory.Build.targets index 69ece877..77217e1b 100644 --- a/Content/tests/Directory.Build.targets +++ b/Content/tests/Directory.Build.targets @@ -11,7 +11,7 @@ + Condition="$([MSBuild]::EnsureTrailingSlash('$([System.IO.Path]::Combine($(BaseOutputPath),$(Configuration)))')) == '$(OutputPath)'"> + Condition="$([MSBuild]::EnsureTrailingSlash('$([System.IO.Path]::Combine($(BaseOutputPath),$(Configuration)))')) == '$(OutputPath)'"> + Condition="$([MSBuild]::EnsureTrailingSlash('$([System.IO.Path]::Combine($(BaseOutputPath),$(Configuration)))')) != '$(OutputPath)'"> Date: Wed, 9 May 2018 22:21:06 -0400 Subject: [PATCH 9/9] undo verbose logging --- Content/build.fsx | 1 - 1 file changed, 1 deletion(-) diff --git a/Content/build.fsx b/Content/build.fsx index 22c6e2c3..22103a7e 100644 --- a/Content/build.fsx +++ b/Content/build.fsx @@ -89,7 +89,6 @@ Target "DotnetTest" (fun _ -> AdditionalArgs = [ "--no-build" - "-v d" ] }) )