Skip to content

Commit

Permalink
Start to add F# code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
StachuDotNet committed Apr 30, 2022
1 parent d275510 commit afec7a3
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 32 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
#############
Expand Down
5 changes: 5 additions & 0 deletions fsharp-backend/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions fsharp-backend/paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
136 changes: 104 additions & 32 deletions fsharp-backend/tests/Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,112 @@ open Prelude

module Telemetry = LibService.Telemetry

// [<EntryPoint>]
// 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


[<Tests>]
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"


[<EntryPoint>]
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
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions fsharp-backend/tests/Tests/Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<PublishTrimmed>false</PublishTrimmed>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Prelude/Prelude.fsproj" />
Expand Down
3 changes: 3 additions & 0 deletions fsharp-backend/tests/Tests/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Expecto
FsCheck
Expecto.FsCheck
SimpleBase
Microsoft.NET.Test.Sdk
YoloDev.Expecto.TestSdk
altcover

0 comments on commit afec7a3

Please sign in to comment.