From 6d4638c9f4ce70ee8e899afe1646852dd434fd4c Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 27 Feb 2024 17:08:55 +0100 Subject: [PATCH] AOT --- eng/Build.ps1 | 2 +- tests/AheadOfTime/Equality/Equality.fsproj | 35 ++++++++++ tests/AheadOfTime/Equality/Program.fs | 77 ++++++++++++++++++++++ tests/AheadOfTime/Equality/check.ps1 | 32 +++++++++ tests/AheadOfTime/Trimming/check.cmd | 2 - tests/AheadOfTime/check.cmd | 3 + 6 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 tests/AheadOfTime/Equality/Equality.fsproj create mode 100644 tests/AheadOfTime/Equality/Program.fs create mode 100644 tests/AheadOfTime/Equality/check.ps1 delete mode 100644 tests/AheadOfTime/Trimming/check.cmd create mode 100644 tests/AheadOfTime/check.cmd diff --git a/eng/Build.ps1 b/eng/Build.ps1 index 049ba91217dc..17be79be71ad 100644 --- a/eng/Build.ps1 +++ b/eng/Build.ps1 @@ -671,7 +671,7 @@ try { } if ($testAOT) { - Push-Location "$RepoRoot\tests\AheadOfTime\Trimming" + Push-Location "$RepoRoot\tests\AheadOfTime" ./check.cmd Pop-Location } diff --git a/tests/AheadOfTime/Equality/Equality.fsproj b/tests/AheadOfTime/Equality/Equality.fsproj new file mode 100644 index 000000000000..f5a243c65b96 --- /dev/null +++ b/tests/AheadOfTime/Equality/Equality.fsproj @@ -0,0 +1,35 @@ + + + + Exe + net8.0 + preview + true + + + + true + true + true + true + win-x64 + + + + $(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Release/net8.0/fsc.dll + $(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Release/net8.0/fsc.dll + False + True + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/AheadOfTime/Equality/Program.fs b/tests/AheadOfTime/Equality/Program.fs new file mode 100644 index 000000000000..052d2875da39 --- /dev/null +++ b/tests/AheadOfTime/Equality/Program.fs @@ -0,0 +1,77 @@ +open System.Collections.Generic +open NonStructuralComparison + +let failures = HashSet() + +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(1)) (enum(1)) + test "test402" (enum(1)) (enum(1)) + +[] +let main _ = + match failures with + | set when set.Count = 0 -> + stdout.WriteLine "All tests passed" + exit 0 + | _ -> + stdout.WriteLine "Some tests failed" + exit 1 diff --git a/tests/AheadOfTime/Equality/check.ps1 b/tests/AheadOfTime/Equality/check.ps1 new file mode 100644 index 000000000000..7913d24599ce --- /dev/null +++ b/tests/AheadOfTime/Equality/check.ps1 @@ -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 +} diff --git a/tests/AheadOfTime/Trimming/check.cmd b/tests/AheadOfTime/Trimming/check.cmd deleted file mode 100644 index 4eefff011c56..000000000000 --- a/tests/AheadOfTime/Trimming/check.cmd +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0check.ps1"""" diff --git a/tests/AheadOfTime/check.cmd b/tests/AheadOfTime/check.cmd new file mode 100644 index 000000000000..a52368e2c6ff --- /dev/null +++ b/tests/AheadOfTime/check.cmd @@ -0,0 +1,3 @@ +@echo off +powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Trimming\check.ps1"""" +powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Equality\check.ps1""""