Skip to content

Commit

Permalink
AOT
Browse files Browse the repository at this point in the history
  • Loading branch information
psfinaki committed Feb 28, 2024
1 parent d26c79f commit 6d4638c
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 3 deletions.
2 changes: 1 addition & 1 deletion eng/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ try {
}

if ($testAOT) {
Push-Location "$RepoRoot\tests\AheadOfTime\Trimming"
Push-Location "$RepoRoot\tests\AheadOfTime"
./check.cmd
Pop-Location
}
Expand Down
35 changes: 35 additions & 0 deletions tests/AheadOfTime/Equality/Equality.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
<PublishTrimmed>true</PublishTrimmed>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup>
<DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Release/net8.0/fsc.dll</DotnetFscCompilerPath>
<Fsc_DotNET_DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Release/net8.0/fsc.dll</Fsc_DotNET_DotnetFscCompilerPath>
<FSharpPreferNetFrameworkTools>False</FSharpPreferNetFrameworkTools>
<FSharpPrefer64BitTools>True</FSharpPrefer64BitTools>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)../../../eng/Versions.props" />

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="$(FSharpCorePreviewPackageVersionValue)"/>
</ItemGroup>

</Project>
77 changes: 77 additions & 0 deletions tests/AheadOfTime/Equality/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
open System.Collections.Generic
open NonStructuralComparison

let failures = HashSet<string>()

let reportFailure (s: string) =
stderr.Write " NO: "
stderr.WriteLine s
failures.Add s |> ignore

let test testName x y =
let result = HashIdentity.Structural.Equals(x, y)
if result = false
then
stderr.WriteLine($"\n***** {testName}: Expected: 'true' Result: '{result}' = FAIL\n");
reportFailure testName

module BasicTypes =
test "test000" true true
test "test001" 1y 1y
test "test002" 1uy 1uy
test "test003" 1s 1s
test "test004" 1us 1us
test "test005" 1 1
test "test006" 1u 1u
test "test007" 1L 1L
test "test008" 1UL 1UL
test "test009" (nativeint 1) (nativeint 1)
test "test010" (unativeint 1) (unativeint 1)
test "test011" 'a' 'a'
test "test012" "a" "a"
test "test013" 1m 1m
test "test014" 1.0 1.0
test "test015" 1.0f 1.0f

module Arrays =
test "test100" [|1|] [|1|]
test "test101" [|1L|] [|1L|]
test "test102" [|1uy|] [|1uy|]
test "test103" [|box 1|] [|box 1|]

module Structs =
test "test200" struct (1, 1) struct (1, 1)
test "test201" struct (1, 1, 1) struct (1, 1, 1)
test "test202" struct (1, 1, 1, 1) struct (1, 1, 1, 1)
test "test203" struct (1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1)
test "test204" struct (1, 1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1, 1)
test "test205" struct (1, 1, 1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1, 1, 1)
test "test206" struct (1, 1, 1, 1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1, 1, 1, 1)

module OptionsAndCo =
open System

test "test301" (Some 1) (Some 1)
test "test302" (ValueSome 1) (ValueSome 1)
test "test303" (Ok 1) (Ok 1)
test "test304" (Nullable 1) (Nullable 1)

module Enums =
open System

type SomeEnum =
| Case0 = 0
| Case1 = 1

test "test401" (enum<SomeEnum>(1)) (enum<SomeEnum>(1))
test "test402" (enum<DayOfWeek>(1)) (enum<DayOfWeek>(1))

[<EntryPoint>]
let main _ =
match failures with
| set when set.Count = 0 ->
stdout.WriteLine "All tests passed"
exit 0
| _ ->
stdout.WriteLine "Some tests failed"
exit 1
32 changes: 32 additions & 0 deletions tests/AheadOfTime/Equality/check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Write-Host "Publish and Execute: net8.0 - Equality"

$build_output = dotnet publish -restore -c release -f:net8.0 $(Join-Path $PSScriptRoot Equality.fsproj)

# Checking that the build succeeded
if ($LASTEXITCODE -ne 0)
{
Write-Error "Build failed with exit code ${LASTEXITCODE}"
Write-Error "${build_output}" -ErrorAction Stop
}

$process = Start-Process `
-FilePath $(Join-Path $PSScriptRoot bin\release\net8.0\win-x64\publish\Equality.exe) `
-Wait `
-NoNewWindow `
-PassThru `
-RedirectStandardOutput $(Join-Path $PSScriptRoot output.txt)

$output = Get-Content $(Join-Path $PSScriptRoot output.txt)

# Checking that it is actually running.
if ($LASTEXITCODE -ne 0)
{
Write-Error "Test failed with exit code ${LASTEXITCODE}" -ErrorAction Stop
}

# Checking that the output is as expected.
$expected = "All tests passed"
if ($output -ne $expected)
{
Write-Error "Test failed with unexpected output:`nExpected:`n`t${expected}`nActual`n`t${output}" -ErrorAction Stop
}
2 changes: 0 additions & 2 deletions tests/AheadOfTime/Trimming/check.cmd

This file was deleted.

3 changes: 3 additions & 0 deletions tests/AheadOfTime/check.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Trimming\check.ps1""""
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Equality\check.ps1""""

0 comments on commit 6d4638c

Please sign in to comment.