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 11, 2023
1 parent dfb8301 commit 4b5eb97
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -151,6 +153,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -178,6 +182,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -216,6 +222,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -256,6 +264,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -283,6 +293,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -310,6 +322,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -348,6 +362,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -388,6 +404,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: fsharpi --define:LEGACY_FRAMEWORK scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -422,6 +440,8 @@ jobs:
./configure.sh && sudo make install
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx
- name: run tests
run: make check
- name: compile this repo's .fsx scripts with fsx
Expand Down Expand Up @@ -464,6 +484,8 @@ jobs:
.\make.bat install
- name: run unit tests
run: dotnet fsi scripts/runUnitTests.fsx
- name: run tests
run: .\make.bat check
- name: compile this repo's .fsx scripts with fsx
Expand Down
71 changes: 71 additions & 0 deletions Fsdk.Tests/Fsdk.Tests-legacy.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>4634f264-784e-42da-b5a1-fe72125deafc</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Fsdk.Tests</RootNamespace>
<AssemblyName>Fsdk.Tests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Fsdk</Name>
<TargetFrameworkProfile />
</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>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="coverlet.collector" />
</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>
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
1 change: 1 addition & 0 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let FsdkDir = Path.Combine(RootDir.FullName, "Fsdk") |> DirectoryInfo
let NugetDir = Path.Combine(RootDir.FullName, ".nuget") |> DirectoryInfo
let NugetExe = Path.Combine(NugetDir.FullName, "nuget.exe") |> FileInfo


type BinaryConfig =
| Debug
| Release
Expand Down
119 changes: 119 additions & 0 deletions scripts/runUnitTests.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
open System
open System.IO
open System.Net
open System.Linq
open System.Diagnostics

#r "System.Configuration"
open System.Configuration

#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
}
| _ ->
//if not NugetExe.Exists then
// MakeAll() |> ignore

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 4b5eb97

Please sign in to comment.