Skip to content

Commit

Permalink
Fix FSharp tests (#3729)
Browse files Browse the repository at this point in the history
* Fix FSharp tests

* Do recursive copy as documented on msdn

* Don't run F# tests in parallel

* Fix test project to use DestinationFiles not DestinationFolder

* Exclude F# test data projects from test list

* Fix ordering issues in msbuild file
  • Loading branch information
Frassle authored and superyyrrzz committed Dec 10, 2018
1 parent 5a6d956 commit 874ee44
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
19 changes: 9 additions & 10 deletions build.ps1
Expand Up @@ -190,16 +190,15 @@ if (-not $skipTests) {

# Run unit test cases
Write-Host "Start running unit test"
foreach ($proj in (Get-ChildItem "test" -Include "*.csproj" -Recurse)) {
if (($proj.Name) -ne "docfx.E2E.Tests.csproj") {
if ($os -eq "Windows") {
& dotnet test $proj.FullName --no-build -c $configuration
ProcessLastExitCode $lastexitcode "dotnet test $($proj.FullName) --no-build -c $configuration"
}
else {
& mono ./TestTools/xunit.runner.console/tools/net452/xunit.console.exe "$($proj.DirectoryName)/bin/$configuration/$framework/$($proj.BaseName).dll"
ProcessLastExitCode $lastexitcode "mono ./TestTools/xunit.runner.console/tools/net452/xunit.console.exe '$($proj.DirectoryName)/bin/$configuration/$framework/$($proj.BaseName).dll'"
}
$exclude = @("docfx.E2E.Tests.csproj", "NetCoreLibProject.fsproj", "NetCoreProject.fsproj")
foreach ($proj in (Get-ChildItem "test" -Exclude $exclude -Include @("*.csproj", "*.fsproj") -Recurse)) {
if ($os -eq "Windows") {
& dotnet test $proj.FullName --no-build -c $configuration
ProcessLastExitCode $lastexitcode "dotnet test $($proj.FullName) --no-build -c $configuration"
}
else {
& mono ./TestTools/xunit.runner.console/tools/net452/xunit.console.exe "$($proj.DirectoryName)/bin/$configuration/$framework/$($proj.BaseName).dll"
ProcessLastExitCode $lastexitcode "mono ./TestTools/xunit.runner.console/tools/net452/xunit.console.exe '$($proj.DirectoryName)/bin/$configuration/$framework/$($proj.BaseName).dll'"
}
}
}
Expand Down
Expand Up @@ -15,7 +15,7 @@ open Microsoft.DocAsCode.Metadata.ManagedReference.FSharp
open Microsoft.DocAsCode.DataContracts.ManagedReference
open Microsoft.DocAsCode.DataContracts.Common


[<Collection("F# Test Collection")>]
type FSharpCompilationTests (output: ITestOutputHelper) =
let printfn format = Printf.kprintf (fun msg -> output.WriteLine(msg)) format

Expand Down
Expand Up @@ -13,6 +13,7 @@ open Microsoft.DocAsCode.Metadata.ManagedReference
open Microsoft.DocAsCode.Metadata.ManagedReference.FSharp


[<Collection("F# Test Collection")>]
type FSharpProjectTests (output: ITestOutputHelper) =
let printfn format = Printf.kprintf (fun msg -> output.WriteLine(msg)) format

Expand All @@ -29,17 +30,17 @@ type FSharpProjectTests (output: ITestOutputHelper) =
let projPath = "TestData/NetCoreProject/NetCoreProject.fsproj"

let proj = FSharpProject (projPath, msBuildProps, loader, checker)
Assert.Equal (proj.FilePath, Path.GetFullPath projPath)
Assert.Equal (Path.GetFullPath projPath, proj.FilePath)
Assert.True (proj.HasDocuments)
let docs = List.ofSeq proj.Documents
Assert.Equal (docs.Length, 3)
Assert.Equal (docs.[0].FilePath, Path.GetFullPath "TestData/NetCoreProject/Module1.fs")
Assert.Equal (docs.[1].FilePath, Path.GetFullPath "TestData/NetCoreProject/Module2.fs")
Assert.Equal (docs.[2].FilePath, Path.GetFullPath "TestData/NetCoreProject/Program.fs")
Assert.Equal (4, docs.Length)
Assert.Equal (Path.GetFullPath "TestData/NetCoreProject/Module1.fs", docs.[1].FilePath)
Assert.Equal (Path.GetFullPath "TestData/NetCoreProject/Module2.fs", docs.[2].FilePath)
Assert.Equal (Path.GetFullPath "TestData/NetCoreProject/Program.fs", docs.[3].FilePath)
let refs = List.ofSeq proj.ProjectReferences
Assert.Equal (refs.Length, 1)
Assert.Equal (1, refs.Length)
Assert.IsType<FSharpProject> refs.[0] |> ignore
Assert.Equal (refs.[0].FilePath, Path.GetFullPath "TestData/NetCoreLibProject/NetCoreLibProject.fsproj")
Assert.Equal (Path.GetFullPath "TestData/NetCoreLibProject/NetCoreLibProject.fsproj", refs.[0].FilePath)

[<Fact>]
let NetCoreProjectCompilation () =
Expand All @@ -56,12 +57,12 @@ type FSharpProjectTests (output: ITestOutputHelper) =
let projPath = "TestData/NetCoreLibProject/NetCoreLibProject.fsproj"

let proj = FSharpProject (projPath, msBuildProps, loader, checker)
Assert.Equal (proj.FilePath, Path.GetFullPath projPath)
Assert.Equal (Path.GetFullPath projPath, proj.FilePath)
Assert.True (proj.HasDocuments)
let docs = List.ofSeq proj.Documents
Assert.Equal (docs.Length, 1)
Assert.Equal (docs.[0].FilePath, Path.GetFullPath "TestData/NetCoreLibProject/Library.fs")
Assert.Equal (2, docs.Length)
Assert.Equal (Path.GetFullPath "TestData/NetCoreLibProject/Library.fs", docs.[1].FilePath)
let refs = List.ofSeq proj.ProjectReferences
Assert.Equal (refs.Length, 0)
Assert.Equal (0, refs.Length)


Expand Up @@ -6,11 +6,21 @@
<Compile Include="FSharpProjectTests.fs" />
</ItemGroup>

<ItemGroup>
<None Include="TestData/*/*.fsproj;TestData/**/*.fs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="RestoreTestProjects" BeforeTargets="Build">
<ItemGroup>
<TestProjects Include="TestData/**/*.fsproj" />
</ItemGroup>
<MSBuild Projects="@(TestProjects)" Targets="Restore" />
</Target>

<Target Name="CopyTestProjects" BeforeTargets="Build" AfterTargets="RestoreTestProjects">
<ItemGroup>
<TestData Include="TestData/**/*" />
</ItemGroup>
<Copy
SourceFiles="@(TestData)"
DestinationFiles="@(TestData->'$(OutputPath)\TestData\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.DocAsCode.DataContracts.Common\Microsoft.DocAsCode.DataContracts.Common.csproj" />
Expand Down

0 comments on commit 874ee44

Please sign in to comment.