Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Add .NET version of the fsharp test. #12359

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/common/mac/MacMain.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Xamarin.Mac.Tests

open System
open System.Collections.Generic
open System.Runtime.InteropServices
open System.Threading
open System.Threading.Tasks

module PInvokes =
[<DllImport ("/usr/lib/libSystem.dylib")>]
extern void _exit (int exit_code)

type MainClass =
static member ThreadMonitor(obj : System.Object) =
let exit_code = obj :?> int
Thread.Sleep (3000)
Console.WriteLine ($"The process didn't exist within 3s of returning from Main. Assuming something is deadlocked, and will now exit immediately and forcefully (with exit code {exit_code}).")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exist -> exit

PInvokes._exit (exit_code)

static member asyncMainTask (args: string[]) : Async<int> =
async {
// Skip arguments added by VSfM/macOS when running from the IDE
let mutable arguments = new List<string> (args)
arguments.RemoveAll (fun (arg) -> arg.StartsWith ("-psn_", StringComparison.Ordinal)) |> ignore

let! exit_code = MonoTouch.NUnit.UI.MacRunner.MainAsync (arguments, true, PInvokes._exit, typedefof<MainClass>.Assembly) |> Async.AwaitTask

let del = ParameterizedThreadStart(MainClass.ThreadMonitor)
let exit_monitor = new Thread (del)
exit_monitor.Name <- "Exit monitor"
exit_monitor.IsBackground <- true
exit_monitor.Start (exit_code)

return exit_code
}

module Program =
[<EntryPoint>]
let main args =
async {
return! MainClass.asyncMainTask (args)
} |> Async.RunSynchronously
1 change: 0 additions & 1 deletion tests/fsharp/FSharpTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
open System
open System.Reflection

open UIKit
open Foundation

open NUnit.Framework
Expand Down
4 changes: 2 additions & 2 deletions tests/fsharp/Main.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Test
namespace fsharp

open UIKit

Expand All @@ -7,7 +7,7 @@ open UIKit
module Main =
[<EntryPoint>]
let main args =
UIApplication.Main(args, null, "AppDelegate")
UIApplication.Main(args, null, typedefof<AppDelegate>)
0

#endif
10 changes: 10 additions & 0 deletions tests/fsharp/dotnet/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.fsharp</string>
<key>LSMinimumSystemVersion</key>
<string>10.15</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/fsharp/dotnet/MacCatalyst/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
13 changes: 13 additions & 0 deletions tests/fsharp/dotnet/MacCatalyst/fsharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
</PropertyGroup>

<!-- Imports of the form '../shared.fsproj' will be processed by xharness -->
<Import Project="../shared.fsproj" />

<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions tests/fsharp/dotnet/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TOP=../../..
include $(TOP)/Make.config

build-all:
for platform in $(DOTNET_PLATFORMS); do \
echo "Building in $$platform"; \
$(MAKE) -C "$$platform" build; \
done
10 changes: 10 additions & 0 deletions tests/fsharp/dotnet/iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"[]>
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.fsharp</string>
<key>MinimumOSVersion</key>
<string>10.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/fsharp/dotnet/iOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
13 changes: 13 additions & 0 deletions tests/fsharp/dotnet/iOS/fsharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
</PropertyGroup>

<!-- Imports of the form '../shared.fsproj' will be processed by xharness -->
<Import Project="../shared.fsproj" />

<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions tests/fsharp/dotnet/macOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.fsharp</string>
<key>LSMinimumSystemVersion</key>
<string>10.14</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/fsharp/dotnet/macOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
13 changes: 13 additions & 0 deletions tests/fsharp/dotnet/macOS/fsharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-macos</TargetFramework>
</PropertyGroup>

<!-- Imports of the form '../shared.fsproj' will be processed by xharness -->
<Import Project="../shared.fsproj" />

<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions tests/fsharp/dotnet/shared.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<DefineConstants>$(DefineConstants);NET</DefineConstants>
<LangVersion>latest</LangVersion>
<RootNamespace>fsharp</RootNamespace>
<AssemblyName>fsharp</AssemblyName>

<ApplicationTitle>FSharp</ApplicationTitle>

<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..'))</RootTestsDirectory>
<TestLibrariesDirectory>$(RootTestsDirectory)\test-libraries</TestLibrariesDirectory>
<FSharpTestDirectory>$(RootTestsDirectory)\fsharp</FSharpTestDirectory>

<!-- Don't remove native symbols, because it makes debugging native crashes harder -->
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>

<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DEBUG</DefineConstants>
</PropertyGroup>

<Import Project="$(RootTestsDirectory)/common/shared-dotnet.csproj" />

<ItemGroup>
<PackageReference Include="NUnitLite" Version="3.12.0" />
<ProjectReference Include="$(RootTestsDirectory)\..\external\Touch.Unit\Touch.Client\dotnet\$(_PlatformName)\Touch.Client-$(_PlatformName).dotnet.csproj" />
<!-- MonoTouch.Dialog references System.Json, which isn't shipped with .NET5, so reference the NuGet instead -->
<PackageReference Include="System.Json" Version="4.7.1" />
<PackageReference Include="FSharp.Core" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(FSharpTestDirectory)/AppDelegate.fs" Condition="!$(TargetFramework.EndsWith('-macos'))" />
<Compile Include="$(FSharpTestDirectory)/FSharpTests.fs" />
<Compile Include="$(RootTestsDirectory)/common/mac/MacMain.fs" Condition="$(TargetFramework.EndsWith('-macos'))" />
<Compile Include="$(FSharpTestDirectory)/Main.fs" Condition="!$(TargetFramework.EndsWith('-macos'))" />
</ItemGroup>

<Import Project="$(RootTestsDirectory)\nunit.framework.targets" />
</Project>
29 changes: 29 additions & 0 deletions tests/fsharp/dotnet/shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
TOP=../../../..
include $(TOP)/Make.config
include $(TOP)/mk/colors.mk

prepare:
$(Q) $(MAKE) -C $(TOP)/tests/dotnet copy-dotnet-config

reload:
$(Q) rm -Rf $(TOP)/tests/dotnet/packages
$(Q) $(MAKE) -C $(TOP) -j8 all
$(Q) $(MAKE) -C $(TOP) -j8 install
$(Q) git clean -xfdq

reload-and-build:
$(Q) $(MAKE) reload
$(Q) $(MAKE) build

reload-and-run:
$(Q) $(MAKE) reload
$(Q) $(MAKE) run

build: prepare
$(Q) $(DOTNET6) build /bl *.fsproj $(MSBUILD_VERBOSITY) $(BUILD_ARGUMENTS)

run: prepare
$(Q) $(DOTNET6) build /bl *.fsproj $(MSBUILD_VERBOSITY) $(BUILD_ARGUMENTS) -t:Run

diag: prepare
$(Q) $(DOTNET6) build /v:diag msbuild.binlog
10 changes: 10 additions & 0 deletions tests/fsharp/dotnet/tvOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"[]>
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.fsharp</string>
<key>MinimumOSVersion</key>
<string>10.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/fsharp/dotnet/tvOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
13 changes: 13 additions & 0 deletions tests/fsharp/dotnet/tvOS/fsharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
</PropertyGroup>

<!-- Imports of the form '../shared.fsproj' will be processed by xharness -->
<Import Project="../shared.fsproj" />

<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions tests/xharness/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,24 @@ int AutoConfigureMac (bool generate_projects)
MacTestProjects.Add (macTestProject);
}

MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "fsharp", "dotnet", "macOS", "fsharp.fsproj"))) {
Name = "fsharp",
IsDotNetProject = true,
TargetFrameworkFlavors = MacFlavors.DotNet,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.Mac,
});

MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "fsharp", "dotnet", "MacCatalyst", "fsharp.fsproj"))) {
Name = "fsharp",
IsDotNetProject = true,
TargetFrameworkFlavors = MacFlavors.MacCatalyst,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.MacCatalyst,
});

var monoImportTestFactory = new BCLTestImportTargetFactory (this);
MacTestProjects.AddRange (monoImportTestFactory.GetMacBclTargets ());

Expand Down Expand Up @@ -482,6 +500,10 @@ void AutoConfigureIOS ()
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "iOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, TestPlatform = TestPlatform.iOS_Unified, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "tvOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = true, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, GenerateVariations = false, TestPlatform = TestPlatform.tvOS, });

// fsharp
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "fsharp", "dotnet", "iOS", "fsharp.fsproj"))) { Name = "fsharp", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, TestPlatform = TestPlatform.iOS_Unified, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "fsharp", "dotnet", "tvOS", "fsharp.fsproj"))) { Name = "fsharp", IsDotNetProject = true, SkipiOSVariation = true, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, GenerateVariations = false, TestPlatform = TestPlatform.tvOS, });

foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) {
var monoNativeInfo = new MonoNativeInfo (DevicePlatform.iOS, flavor, RootDirectory, Log);
var iosTestProject = new iOSTestProject (monoNativeInfo.ProjectPath) {
Expand Down
2 changes: 1 addition & 1 deletion tests/xharness/TestProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask
continue;

var project = node.Attributes ["Project"].Value;
if (project != "../shared.csproj")
if (project != "../shared.csproj" && project != "../shared.fsproj")
continue;

if (TestPlatform == TestPlatform.None)
Expand Down