From afec7a3c822fbacb66c92ccb85f21c00c62ec3e1 Mon Sep 17 00:00:00 2001 From: Stachu Korick Date: Fri, 29 Apr 2022 22:48:44 -0400 Subject: [PATCH] Start to add F# code coverage --- Dockerfile | 5 + fsharp-backend/paket.dependencies | 5 + fsharp-backend/paket.lock | 16 +++ fsharp-backend/tests/Tests/Tests.fs | 136 +++++++++++++++----- fsharp-backend/tests/Tests/Tests.fsproj | 1 + fsharp-backend/tests/Tests/paket.references | 3 + 6 files changed, 134 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1fce7357628..0f554f13008 100644 --- a/Dockerfile +++ b/Dockerfile @@ -357,6 +357,7 @@ RUN curl -SL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$ RUN sudo dotnet workload install wasm-tools RUN dotnet tool install -g dotnet-sos + # TODO: is this the right directory? RUN echo "plugin load /home/dark/.dotnet/tools/.store/dotnet-sos/5.0.160202/dotnet-sos/5.0.160202/tools/netcoreapp2.1/any/linux-x64/libsosplugin.so" > ~/.lldbinit @@ -365,6 +366,10 @@ RUN dotnet tool install fantomas-tool --version 4.6.3 -g RUN curl https://raw.githubusercontent.com/darklang/build-files/main/ocamlformat --output ~/bin/ocamlformat && chmod +x ~/bin/ocamlformat ENV PATH "$PATH:/home/dark/bin:/home/dark/.dotnet/tools" +# code coverage +RUN dotnet tool install -g altcover.global +RUN dotnet tool install -g dotnet-reportgenerator-globaltool + ############# # tunnel user ############# diff --git a/fsharp-backend/paket.dependencies b/fsharp-backend/paket.dependencies index e5074406249..f3d4ef83795 100644 --- a/fsharp-backend/paket.dependencies +++ b/fsharp-backend/paket.dependencies @@ -28,6 +28,11 @@ nuget FSharp.Compiler.Service = 41.0.3 nuget NReco.Logging.File = 1.1.3 nuget SimpleBase = 3.1.0 +// Code Coverage +nuget YoloDev.Expecto.TestSdk 0.12.12 +nuget Microsoft.NET.Test.Sdk 17.1.0-preview-20211109-03 +nuget altcover ~> 8.2.825 + // Services nuget Lib.AspNetCore.ServerTiming = 4.3.0 nuget PusherServer = 4.6.1 diff --git a/fsharp-backend/paket.lock b/fsharp-backend/paket.lock index a16a4418cb9..b70e1934193 100644 --- a/fsharp-backend/paket.lock +++ b/fsharp-backend/paket.lock @@ -2,6 +2,7 @@ STORAGE: NONE RESTRICTION: == net6.0 NUGET remote: https://api.nuget.org/v3/index.json + altcover (8.2.837) Argu (6.1.1) FSharp.Core (>= 4.3.2) System.Configuration.ConfigurationManager (>= 4.4) @@ -122,6 +123,7 @@ NUGET System.Configuration.ConfigurationManager (>= 4.7) System.Security.Permissions (>= 4.7) System.Text.Encoding.CodePages (>= 4.0.1) + Microsoft.CodeCoverage (17.1) Microsoft.Extensions.Configuration (6.0) Microsoft.Extensions.Configuration.Abstractions (>= 6.0) Microsoft.Extensions.Primitives (>= 6.0) @@ -193,8 +195,17 @@ NUGET Microsoft.NET.StringTools (1.0) System.Memory (>= 4.5.4) System.Runtime.CompilerServices.Unsafe (>= 5.0) + Microsoft.NET.Test.Sdk (17.1.0-preview-20211109-03) + Microsoft.CodeCoverage (>= 17.1.0-preview-20211109-03) + Microsoft.TestPlatform.TestHost (>= 17.1.0-preview-20211109-03) Microsoft.NETCore.Platforms (5.0.4) Microsoft.NETCore.Targets (5.0) + Microsoft.TestPlatform.ObjectModel (17.1) + NuGet.Frameworks (>= 5.11) + System.Reflection.Metadata (>= 1.6) + Microsoft.TestPlatform.TestHost (17.1) + Microsoft.TestPlatform.ObjectModel (>= 17.1) + Newtonsoft.Json (>= 9.0.1) Microsoft.Win32.Primitives (4.3) Microsoft.NETCore.Platforms (>= 1.1) Microsoft.NETCore.Targets (>= 1.1) @@ -225,6 +236,7 @@ NUGET Microsoft.Extensions.Logging (>= 2.0) Microsoft.Extensions.Logging.Configuration (>= 2.0) Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.0) + NuGet.Frameworks (6.1) OpenTelemetry (1.2.0-rc2) Microsoft.Extensions.Logging (>= 2.1) Microsoft.Extensions.Logging.Configuration (>= 2.1) @@ -759,6 +771,10 @@ NUGET System.ValueTuple (4.5) System.Windows.Extensions (5.0) System.Drawing.Common (>= 5.0) + YoloDev.Expecto.TestSdk (0.12.12) + Expecto (>= 9.0 < 10.0) + FSharp.Core (>= 4.6) + System.Collections.Immutable (>= 1.5) GROUP Wasm NUGET diff --git a/fsharp-backend/tests/Tests/Tests.fs b/fsharp-backend/tests/Tests/Tests.fs index 48ff60dd82c..491cdc1a84c 100644 --- a/fsharp-backend/tests/Tests/Tests.fs +++ b/fsharp-backend/tests/Tests/Tests.fs @@ -9,40 +9,112 @@ open Prelude module Telemetry = LibService.Telemetry +// [] +// let main (args : string array) : int = +// try +// let name = "Tests" +// LibService.Init.init name +// (LibBackend.Init.init LibBackend.Init.WaitForDB name).Result +// (LibRealExecution.Init.init name).Result +// (LibBackend.Account.initializeDevelopmentAccounts name).Result + +// let tests = +// [ Tests.Account.tests +// Tests.ApiServer.tests +// Tests.Authorization.tests +// Tests.BinarySerialization.tests +// Tests.BwdServer.tests +// Tests.Canvas.tests +// Tests.Cron.tests +// Tests.DvalReprExternal.tests +// Tests.EventQueue.tests +// Tests.Execution.tests +// Tests.FSharpToExpr.tests +// Tests.HttpClient.tests +// Tests.LibExecution.tests.Force() +// Tests.OCamlInterop.tests +// Tests.Prelude.tests +// Tests.ProgramTypes.tests +// Tests.Routing.tests +// Tests.SqlCompiler.tests +// Tests.StdLib.tests +// Tests.Traces.tests +// Tests.TypeChecker.tests +// Tests.Undo.tests +// Tests.UserDB.tests ] + +// let cancelationTokenSource = new System.Threading.CancellationTokenSource() +// let bwdServerTestsTask = Tests.BwdServer.init cancelationTokenSource.Token +// let httpClientTestsTask = Tests.HttpClient.init cancelationTokenSource.Token +// Telemetry.Console.loadTelemetry "tests" Telemetry.TraceDBQueries +// (LibBackend.Account.initTestAccounts ()).Wait() + +// // Generate this so that we can see if the format has changed in a git diff +// BinarySerialization.generateBinarySerializationTestFiles () + +// // this does async stuff within it, so do not run it from a task/async +// // context or it may hang +// let exitCode = runTestsWithCLIArgs [] args (testList "tests" tests) + +// NonBlockingConsole.wait () // flush stdout +// cancelationTokenSource.Cancel() +// bwdServerTestsTask.Wait() +// httpClientTestsTask.Wait() +// exitCode +// with +// | e -> +// print e.Message +// printMetadata (Exception.toMetadata e) +// print e.StackTrace +// NonBlockingConsole.wait () // flush stdout +// 1 + +let name = "Tests" +LibService.Init.init name +(LibBackend.Init.init LibBackend.Init.WaitForDB name).Result +(LibRealExecution.Init.init name).Result +(LibBackend.Account.initializeDevelopmentAccounts name).Result + + +[] +let tests = + [ // passes consistently with `dotnet test` + Tests.Account.tests // <- + Tests.Authorization.tests + Tests.BinarySerialization.tests + Tests.Cron.tests + Tests.Execution.tests + Tests.FSharpToExpr.tests + Tests.OCamlInterop.tests + Tests.Prelude.tests + Tests.ProgramTypes.tests + Tests.Routing.tests + Tests.SqlCompiler.tests + Tests.StdLib.tests + Tests.Traces.tests + Tests.TypeChecker.tests + Tests.Undo.tests + Tests.UserDB.tests + + // breaks when loading (before runtime) + Tests.BwdServer.tests + //Tests.DvalReprExternal.tests + //Tests.HttpClient.tests + + // loads OK, but breaks during runtime + //Tests.ApiServer.tests + //Tests.Canvas.tests // _one_ test breaks during runtime + //Tests.EventQueue.tests // 2 tests fail, likely due to sequenced aspect not being respected + + // untested + //Tests.LibExecution.tests.Force() + ] + |> testList "tests" + + [] let main (args : string array) : int = try - let name = "Tests" - LibService.Init.init name - (LibBackend.Init.init LibBackend.Init.WaitForDB name).Result - (LibRealExecution.Init.init name).Result - (LibBackend.Account.initializeDevelopmentAccounts name).Result - - let tests = - [ Tests.Account.tests - Tests.ApiServer.tests - Tests.Authorization.tests - Tests.BinarySerialization.tests - Tests.BwdServer.tests - Tests.Canvas.tests - Tests.Cron.tests - Tests.DvalReprExternal.tests - Tests.EventQueue.tests - Tests.Execution.tests - Tests.FSharpToExpr.tests - Tests.HttpClient.tests - Tests.LibExecution.tests.Force() - Tests.OCamlInterop.tests - Tests.Prelude.tests - Tests.ProgramTypes.tests - Tests.Routing.tests - Tests.SqlCompiler.tests - Tests.StdLib.tests - Tests.Traces.tests - Tests.TypeChecker.tests - Tests.Undo.tests - Tests.UserDB.tests ] - let cancelationTokenSource = new System.Threading.CancellationTokenSource() let bwdServerTestsTask = Tests.BwdServer.init cancelationTokenSource.Token let httpClientTestsTask = Tests.HttpClient.init cancelationTokenSource.Token @@ -54,7 +126,7 @@ let main (args : string array) : int = // this does async stuff within it, so do not run it from a task/async // context or it may hang - let exitCode = runTestsWithCLIArgs [] args (testList "tests" tests) + let exitCode = runTestsWithCLIArgs [] args tests NonBlockingConsole.wait () // flush stdout cancelationTokenSource.Cancel() diff --git a/fsharp-backend/tests/Tests/Tests.fsproj b/fsharp-backend/tests/Tests/Tests.fsproj index 9d8db50f6af..09d3034e2c8 100644 --- a/fsharp-backend/tests/Tests/Tests.fsproj +++ b/fsharp-backend/tests/Tests/Tests.fsproj @@ -11,6 +11,7 @@ false linux-x64 + false diff --git a/fsharp-backend/tests/Tests/paket.references b/fsharp-backend/tests/Tests/paket.references index 7bfda222d89..a0fbb0e84f3 100644 --- a/fsharp-backend/tests/Tests/paket.references +++ b/fsharp-backend/tests/Tests/paket.references @@ -4,3 +4,6 @@ Expecto FsCheck Expecto.FsCheck SimpleBase +Microsoft.NET.Test.Sdk +YoloDev.Expecto.TestSdk +altcover \ No newline at end of file