Skip to content

Commit

Permalink
Merge pull request #387 from robertcoltheart/refactor/consolidate-tests
Browse files Browse the repository at this point in the history
Consolidate fsharp tests into main test assembly
  • Loading branch information
mcavigelli committed Mar 14, 2021
2 parents dcc85f3 + eb780ec commit 2c1f3b3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 45 deletions.
19 changes: 0 additions & 19 deletions FileHelpers.FSharp.Tests/FileHelpers.FSharp.Tests.csproj

This file was deleted.

1 change: 1 addition & 0 deletions FileHelpers.Tests/FileHelpers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="FSharp.Compiler.Service" Version="39.0.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if NETCOREAPP
using System;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -10,34 +11,40 @@
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;

namespace FileHelpers.FSharp.Tests.Helpers
namespace FileHelpers.Tests.Helpers
{
public static class CompileHelper
public static class FSharpHelper
{
public static Assembly Compile(string source)
{
var fileHelpersAssembly = typeof(EngineBase).Assembly;

var checker = FSharpChecker.Create(FSharpOption<int>.None,
var checker = FSharpChecker.Create(
FSharpOption<int>.None,
FSharpOption<bool>.None,
FSharpOption<bool>.None,
FSharpOption<ReferenceResolver.Resolver>.None,
FSharpOption<FSharpFunc<Tuple<string, DateTime>, FSharpOption<Tuple<object, IntPtr, int>>>>.None);
FSharpOption<LegacyReferenceResolver>.None,
FSharpOption<FSharpFunc<Tuple<string, DateTime>, FSharpOption<Tuple<object, IntPtr, int>>>>.None,
FSharpOption<bool>.None,
FSharpOption<bool>.None,
FSharpOption<bool>.None,
FSharpOption<bool>.None);

var file = Path.GetTempFileName();

File.WriteAllText(file + ".fs", source);

var action = checker.CompileToDynamicAssembly(new[] {"-o", file + ".dll", "-a", file + ".fs", "--reference:" + fileHelpersAssembly.Location},
var action = checker.CompileToDynamicAssembly(
new[] {"-o", file + ".dll", "-a", file + ".fs", "--reference:" + fileHelpersAssembly.Location},
FSharpOption<Tuple<TextWriter, TextWriter>>.None,
FSharpOption<string>.None);

Tuple<FSharpErrorInfo[], int, FSharpOption<Assembly>> compileResult = FSharpAsync
var compileResult = FSharpAsync
.StartAsTask(action, FSharpOption<TaskCreationOptions>.None, FSharpOption<CancellationToken>.None)
.Result;

int exitCode = compileResult.Item2;
FSharpErrorInfo[] compilationErrors = compileResult.Item1;
var exitCode = compileResult.Item2;
var compilationErrors = compileResult.Item1;

if (compilationErrors.Any() && exitCode != 0)
{
Expand All @@ -51,8 +58,8 @@ public static Assembly Compile(string source)
throw new InvalidOperationException($"Cannot compile fsharp: {errors}");
}

Assembly assembly = compileResult.Item3.Value;
return assembly;
return compileResult.Item3.Value;
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using FileHelpers.FSharp.Tests.Helpers;
#if NETCOREAPP
using FileHelpers.Tests.Helpers;
using NFluent;
using NUnit.Framework;

namespace FileHelpers.FSharp.Tests
namespace FileHelpers.Tests.FileHelpers
{
public class AutoPropertiesTests
public class FSharpAutoPropertiesTests
{
[Test]
public void AutoPropertiesFromFSharpAreHandled()
Expand Down Expand Up @@ -34,7 +35,7 @@ open FileHelpers
Field3: int }
";

var assembly = CompileHelper.Compile(source);
var assembly = FSharpHelper.Compile(source);
var type = assembly.GetType("FileHelpers.SampleFSharpType");

var fileHelpersAssembly = typeof(EngineBase).Assembly;
Expand All @@ -49,3 +50,4 @@ open FileHelpers
}
}
}
#endif
10 changes: 0 additions & 10 deletions FileHelpers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileHelpers.Benchmarks", "F
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileHelpers.ExcelNPOIStorage", "FileHelpers.ExcelNPOIStorage\FileHelpers.ExcelNPOIStorage.csproj", "{BEB0D823-6A7E-47FD-A275-1B3314F8412D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileHelpers.FSharp.Tests", "FileHelpers.FSharp.Tests\FileHelpers.FSharp.Tests.csproj", "{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileHelpers.ExcelNPOIStorage.Tests", "FileHelpers.ExcelNPOIStorage.Tests\FileHelpers.ExcelNPOIStorage.Tests.csproj", "{F14D7DE4-0DCA-4316-AE4C-CD1D06FF1D32}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileHelpers.Examples", "FileHelpers.Examples\FileHelpers.Examples.csproj", "{CF51E633-CB40-49F4-939F-5E9A858A0F91}"
Expand Down Expand Up @@ -64,14 +62,6 @@ Global
{BEB0D823-6A7E-47FD-A275-1B3314F8412D}.Release|Any CPU.Build.0 = Release|Any CPU
{BEB0D823-6A7E-47FD-A275-1B3314F8412D}.Release|x86.ActiveCfg = Release|Any CPU
{BEB0D823-6A7E-47FD-A275-1B3314F8412D}.Release|x86.Build.0 = Release|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Debug|x86.ActiveCfg = Debug|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Debug|x86.Build.0 = Debug|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Release|Any CPU.Build.0 = Release|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Release|x86.ActiveCfg = Release|Any CPU
{84897773-77C3-4A98-A2E4-E3C2AF2C6D35}.Release|x86.Build.0 = Release|Any CPU
{F14D7DE4-0DCA-4316-AE4C-CD1D06FF1D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F14D7DE4-0DCA-4316-AE4C-CD1D06FF1D32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F14D7DE4-0DCA-4316-AE4C-CD1D06FF1D32}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down

0 comments on commit 2c1f3b3

Please sign in to comment.