Skip to content

Commit

Permalink
CI: run unit tests
Browse files Browse the repository at this point in the history
Run unit tests from Fsdk.Tests projects.
  • Loading branch information
webwarrior-ws committed Jan 12, 2023
1 parent 31b2909 commit 0cb6dbe
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 13 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -143,6 +145,8 @@ jobs:
run: ./configure.sh && cat build.config
- name: build in DEBUG mode
run: make
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -170,6 +174,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -208,6 +214,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -248,6 +256,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -275,6 +285,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -302,6 +314,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -340,6 +354,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -380,6 +396,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -414,6 +432,8 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down Expand Up @@ -456,6 +476,8 @@ jobs:
dotnet-version: '6.0.x'
- name: build in DEBUG mode
run: .\make.bat
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx

- name: install
run: |
Expand Down
12 changes: 0 additions & 12 deletions Fsdk.Tests/FSharpUtil.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ open Fsdk
type UnexpectedTaskCanceledException(message: string, innerException) =
inherit TaskCanceledException(message, innerException)

type TypeWithStringOverridenManually =
| FOO
| BAR

override self.ToString() =
match self with
| FOO -> "FOO"
| BAR -> "BAR"

type TypeWithNoToStringOverriden =
| FOO
| BAR

[<TestFixture>]
type FSharpUtilCoverage() =
Expand Down
66 changes: 66 additions & 0 deletions Fsdk.Tests/Fsdk.Tests-legacy.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Fsdk.Tests</RootNamespace>
<AssemblyName>Fsdk.Tests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFSharpCoreVersion>5.0.0.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Fsdk.Tests</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\Fsdk.Tests.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\Fsdk.Tests.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);LEGACY_FRAMEWORK</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FSharpUtil.fs" />
<Compile Include="AsyncExtensions.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fsdk\Fsdk-legacy.fsproj" />
</ItemGroup>
<Import Project="..\CommonBuildProps-legacy.proj" />
<Import Condition="'$(FSharpTargetsPath)' != ''" Project="$(FSharpTargetsPath)" />
<Target Name="BeforeBuild">
<Message Condition="'$(FSharpTargetsPath)' == ''" Importance="High" Text="F# SDK path was not found!" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
2 changes: 2 additions & 0 deletions Fsdk.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Fsdk.Tests

module Program =

[<EntryPoint>]
Expand Down
6 changes: 6 additions & 0 deletions Fsdk.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net46" />
<package id="NUnitTestAdapter" version="2.1.1" targetFramework="net46" />
<package id="FSharp.Core" version="5.0.0.0" />
</packages>
3 changes: 2 additions & 1 deletion Fsdk/Fsdk-legacy.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RootNamespace>Fsdk</RootNamespace>
<AssemblyName>Fsdk</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<TargetFSharpCoreVersion>5.0.0.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Fsdk</Name>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -51,6 +51,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="FSharpUtil.fs" />
<Compile Include="Misc.fs" />
<Compile Include="Process.fs" />
<Compile Include="Unix.fs" />
Expand Down
4 changes: 4 additions & 0 deletions Fsdk/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Core" version="5.0.0.0" />
</packages>
6 changes: 6 additions & 0 deletions fsx-legacy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DBAE02AB
scripts\fsx.bat = scripts\fsx.bat
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fsdk.Tests", "Fsdk.Tests\Fsdk.Tests-legacy.fsproj", "{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -65,6 +67,10 @@ Global
{56DA5F03-8F7F-44AB-B692-5A24DB134A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56DA5F03-8F7F-44AB-B692-5A24DB134A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56DA5F03-8F7F-44AB-B692-5A24DB134A8B}.Release|Any CPU.Build.0 = Release|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions fsx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Global
{B532D664-2864-4532-9673-3E52DD363BB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B532D664-2864-4532-9673-3E52DD363BB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B532D664-2864-4532-9673-3E52DD363BB9}.Release|Any CPU.Build.0 = Release|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43BA7E25-975B-4DF9-B274-EEF6C806C1D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
113 changes: 113 additions & 0 deletions scripts/runUnitTests.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
open System
open System.IO
open System.Net
open System.Linq
open System.Diagnostics

#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Network.fs"
#load "../Fsdk/Git.fs"

open Fsdk
open Fsdk.Process

let ScriptsDir = __SOURCE_DIRECTORY__ |> DirectoryInfo
let RootDir = Path.Combine(ScriptsDir.FullName, "..") |> DirectoryInfo
let TestDir = Path.Combine(RootDir.FullName, "test") |> DirectoryInfo
let NugetDir = Path.Combine(RootDir.FullName, ".nuget") |> DirectoryInfo
let NugetExe = Path.Combine(NugetDir.FullName, "nuget.exe") |> FileInfo
let NugetPackages = Path.Combine(RootDir.FullName, "packages") |> DirectoryInfo

let NugetScriptsPackagesDir() =
let dir = Path.Combine(NugetDir.FullName, "packages") |> DirectoryInfo

if not dir.Exists then
Directory.CreateDirectory dir.FullName |> ignore

dir

let MakeCheckCommand(commandName: string) =
if not(Process.CommandWorksInShell commandName) then
Console.Error.WriteLine(
sprintf "%s not found, please install it first" commandName
)

Environment.Exit 1

let RunUnitTests() =
Console.WriteLine "Running unit tests...\n"

let testProjectName = "Fsdk.Tests"
#if !LEGACY_FRAMEWORK
let testTarget =
Path.Combine(
RootDir.FullName,
testProjectName,
testProjectName + ".fsproj"
)
|> FileInfo
#else
// so that we get file names in stack traces
Environment.SetEnvironmentVariable("MONO_ENV_OPTIONS", "--debug")

let testTarget =
Path.Combine(
RootDir.FullName,
testProjectName,
"bin",
"Debug",
testProjectName + ".dll"
)
|> FileInfo
#endif

if not testTarget.Exists then
failwithf "File not found: %s" testTarget.FullName

let runnerCommand =
#if !LEGACY_FRAMEWORK
{
Command = "dotnet"
Arguments = "test " + testTarget.FullName
}
#else
match Misc.GuessPlatform() with
| Misc.Platform.Linux ->
let nunitCommand = "nunit-console"
MakeCheckCommand nunitCommand

{
Command = nunitCommand
Arguments = testTarget.FullName
}
| _ ->
let nunitVersion = "2.7.1"
let pkgOutputDir = NugetScriptsPackagesDir()

Network.InstallNugetPackage
NugetExe
pkgOutputDir
"NUnit.Runners"
(Some nunitVersion)
Echo.All
|> ignore

{
Command =
Path.Combine(
NugetScriptsPackagesDir().FullName,
sprintf "NUnit.Runners.%s" nunitVersion,
"tools",
"nunit-console.exe"
)
Arguments = testTarget.FullName
}
#endif

Process
.Execute(runnerCommand, Echo.All)
.UnwrapDefault()
|> ignore

RunUnitTests()

0 comments on commit 0cb6dbe

Please sign in to comment.