From 4d5ca46e4d7906fa8f3515f1ed8088273c9072ee Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Mon, 13 Jan 2025 18:23:10 -0800 Subject: [PATCH 1/4] Initial --- .config/dotnet-tools.json | 16 ++--- .../Events/Basic/Basic.fs | 4 +- tests/FSharp.Test.Utilities/Compiler.fs | 2 - tests/FSharp.Test.Utilities/Peverifier.fs | 59 ++++++++++++------- tests/FSharp.Test.Utilities/TestFramework.fs | 5 +- 5 files changed, 50 insertions(+), 36 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 88f8c3d1576..46cb8a756ca 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -44,19 +44,19 @@ ], "rollForward": true }, - "dotnet-ilverify": { - "version": "9.0.0-rc.2.24473.5", - "commands": [ - "ilverify" - ], - "rollForward": true - }, "fantomas": { "version": "6.2.3", "commands": [ "fantomas" ], "rollForward": true + }, + "dotnet-ilverify": { + "version": "9.0.0", + "commands": [ + "ilverify" + ], + "rollForward": false } } -} +} \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs index caede79cd6b..e111cb7346a 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs @@ -87,13 +87,11 @@ module Events = |> verifyCompileAndRun |> shouldSucceed -#if false && !NETCOREAPP && !NETSTANDARD // SOURCE=SanityCheck02.fs PEVER=/MD # SanityCheck02.fs - /MD [] let ``SanityCheck02_fs_peverify`` compilation = compilation |> asExe |> withOptions ["--nowarn:988"] - |> PEVerifier.verifyPEFile + |> PEVerifier.verifyPEFileWithSystemDlls |> PEVerifier.shouldSucceed -#endif diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 7de76521d83..f437d11923c 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -1468,7 +1468,6 @@ Actual: failwith $"Expected imports are different from PDB.\nExpected:\n%A{expectedScope}\nActual:%A{imports}" let private verifySequencePoints (reader: MetadataReader) expectedSequencePoints = - let sequencePoints = [ for sp in reader.MethodDebugInformation do let mdi = reader.GetMethodDebugInformation sp @@ -1480,7 +1479,6 @@ Actual: failwith $"Expected sequence points are different from PDB.\nExpected: %A{expectedSequencePoints}\nActual: %A{sequencePoints}" let private verifyDocuments (reader: MetadataReader) expectedDocuments = - let documents = [ for doc in reader.Documents do if not doc.IsNil then diff --git a/tests/FSharp.Test.Utilities/Peverifier.fs b/tests/FSharp.Test.Utilities/Peverifier.fs index 0591a435484..aff44b3d749 100644 --- a/tests/FSharp.Test.Utilities/Peverifier.fs +++ b/tests/FSharp.Test.Utilities/Peverifier.fs @@ -6,10 +6,10 @@ open System open System.IO open TestFramework -type PEVerifyOutput = - { +type PEVerifyOutput ={ ExitCode: int - Lines: string array + OutputLines: string array + ErrorLines: string array } [] @@ -19,36 +19,45 @@ type PEVerifyResult = [] module PEVerifier = - let config = initializeSuite () - let private exec exe args = + let private exec (dotnetExe: string) args workingDirectory = let arguments = args |> String.concat " " - let exitCode, _output, errors = Commands.executeProcess exe arguments "" + let exitCode, _output, errors = Commands.executeProcess dotnetExe arguments workingDirectory let errors = errors |> String.concat Environment.NewLine errors, exitCode - let private verifyPEFileCore peverifierArgs dllFilePath = + let private verifyPEFileCore peverifierArgs (dllFilePath: string) = let mutable errors = ResizeArray () - let peverifierPath = config.PEVERIFY - let peverifyFullArgs = [ yield dllFilePath; yield "/NOLOGO"; yield! peverifierArgs ] - let stdErr, exitCode = - let peverifierCommandPath = Path.ChangeExtension(dllFilePath, ".peverifierCommandPath") - File.WriteAllLines(peverifierCommandPath, [| $"{peverifierPath} {peverifyFullArgs}" |] ) + let peverifyFullArgs = [ yield "--verbose"; yield dllFilePath; yield! peverifierArgs ] + let workingDirectory = Path.GetDirectoryName dllFilePath + let _, exitCode = + let peverifierCommandPath = Path.ChangeExtension(dllFilePath, ".peverifierCommandPath.cmd") + let args = peverifyFullArgs |> Seq.fold(fun a acc -> $"{a} " + acc) "" + File.WriteAllLines(peverifierCommandPath, [| $"{args}" |] ) File.Copy(typeof.Assembly.Location, Path.GetDirectoryName(dllFilePath) ++ "FSharp.Core.dll", true) - exec peverifierPath peverifyFullArgs + let profile = Environment.GetEnvironmentVariable("USERPROFILE") + exec $"{profile}/.dotnet/tools/ilverify.exe" peverifyFullArgs workingDirectory + + // Grab output + let outputLines = File.ReadAllLines(Path.Combine(workingDirectory, "StandardOutput.txt")) + let errorLines = File.ReadAllLines(Path.Combine(workingDirectory, "StandardError.txt")) - if exitCode <> 0 then - errors.Add (sprintf "PEVERIFIER failed with error code: %d" exitCode) + let result = { + ExitCode = exitCode + OutputLines = outputLines + ErrorLines = errorLines + } - if not (String.IsNullOrWhiteSpace stdErr) then - errors.Add (sprintf "PEVERIFIER stderr is not empty:\n %s" stdErr) + if result.ExitCode <> 0 then + errors.Add ($"PEVERIFIER failed with error code: {exitCode}") - let error = { ExitCode=exitCode; Lines = errors.ToArray() } + if result.ErrorLines |> Array.length <= 0 then + errors.Add ($"PEVERIFIER stderr is not empty:\n {result.ErrorLines}") match errors.Count with - | 0 -> PEVerifyResult.Success error - | _ -> PEVerifyResult.Failure error + | 0 -> PEVerifyResult.Success result + | _ -> PEVerifyResult.Failure result let private verifyPEFileAux cUnit args = let result = @@ -69,6 +78,16 @@ module PEVerifier = let verifyPEFileWithArgs cUnit args = verifyPEFileCore cUnit args + let verifyPEFileWithSystemDlls cUnit = + // Get the path containing mecorlib.dll or System.Core.Private.dll + let fsharpCorePath = typeof.Assembly.Location + let systemPath = Path.GetDirectoryName(typeof.Assembly.Location) + let systemDllPaths = + DirectoryInfo(systemPath).GetFiles("*.dll") + |> Array.map (fun dll -> $"--reference \"{Path.Combine(systemPath, dll.FullName)}\"") + |> Array.toList + verifyPEFileAux cUnit ($"--reference \"{fsharpCorePath}\"" :: systemDllPaths) + let shouldFail result = match result with | PEVerifyResult.Success _ -> failwith $"Expected to Fail - {result}" diff --git a/tests/FSharp.Test.Utilities/TestFramework.fs b/tests/FSharp.Test.Utilities/TestFramework.fs index 38976846a4a..54e5fb8293b 100644 --- a/tests/FSharp.Test.Utilities/TestFramework.fs +++ b/tests/FSharp.Test.Utilities/TestFramework.fs @@ -103,7 +103,7 @@ module Commands = p.BeginOutputReadLine() p.BeginErrorReadLine() p.WaitForExit() -#if DEBUG + let workingDir' = if workingDir = "" then @@ -118,7 +118,6 @@ module Commands = File.WriteAllLines(Path.Combine(workingDir', "StandardOutput.txt"), outputList) File.WriteAllLines(Path.Combine(workingDir', "StandardError.txt"), errorsList) ) -#endif p.ExitCode, outputList.ToArray(), errorsList.ToArray() let getfullpath workDir (path:string) = @@ -329,7 +328,7 @@ let config configurationName envVars = let ILASM_EXE = if operatingSystem = "win" then "ilasm.exe" else "ilasm" let ILASM = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.ILAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ ILASM_EXE) //let PEVERIFY_EXE = if operatingSystem = "win" then "PEVerify.exe" elif operatingSystem = "osx" then "PEVerify.dll" else "PEVerify" - let PEVERIFY = "dummy" //requireArtifact ("PEVerify" ++ configurationName ++ peverifyArchitecture ++ PEVERIFY_EXE) + let PEVERIFY = "ilverify" //requireArtifact ("PEVerify" ++ configurationName ++ peverifyArchitecture ++ PEVERIFY_EXE) // let FSI_FOR_SCRIPTS = artifactsBinPath ++ "fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.exe" let FSharpBuild = requireArtifact ("FSharp.Build" ++ configurationName ++ fsharpBuildArchitecture ++ "FSharp.Build.dll") let FSharpCompilerInteractiveSettings = requireArtifact ("FSharp.Compiler.Interactive.Settings" ++ configurationName ++ fsharpCompilerInteractiveSettingsArchitecture ++ "FSharp.Compiler.Interactive.Settings.dll") From 22ee306bedcfeb2dce79b6d3b8d54356cbf78187 Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Thu, 23 Jan 2025 10:36:36 -0800 Subject: [PATCH 2/4] verification --- .../Events/Basic/Basic.fs | 17 ++- .../ClassTypeInitialization.fs | 109 +++++++++++++++++- .../ClassTypeVisibilityModuleRoot.fs | 85 +++++++++++++- .../ClassTypeVisibilityNamespaceRoot.fs | 70 +++++++++++ tests/FSharp.Test.Utilities/Compiler.fs | 46 +++++++- tests/FSharp.Test.Utilities/CompilerAssert.fs | 2 + .../FSharp.Test.Utilities.fsproj | 4 +- .../FSharp.Test.Utilities/ILVerifierModule.fs | 74 ++++++++++++ tests/FSharp.Test.Utilities/Peverifier.fs | 99 ---------------- tests/FSharp.Test.Utilities/TestFramework.fs | 11 +- 10 files changed, 385 insertions(+), 132 deletions(-) create mode 100644 tests/FSharp.Test.Utilities/ILVerifierModule.fs delete mode 100644 tests/FSharp.Test.Utilities/Peverifier.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs index e111cb7346a..590e707751d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs @@ -80,18 +80,15 @@ module Events = |> verifyCompileAndRun |> shouldSucceed - // NoMT SOURCE=SanityCheck02.fs # SanityCheck02.fs - [] - let ``SanityCheck02_fs`` compilation = - compilation - |> verifyCompileAndRun - |> shouldSucceed - // SOURCE=SanityCheck02.fs PEVER=/MD # SanityCheck02.fs - /MD [] - let ``SanityCheck02_fs_peverify`` compilation = + let ``SanityCheck02`` compilation = compilation |> asExe |> withOptions ["--nowarn:988"] - |> PEVerifier.verifyPEFileWithSystemDlls - |> PEVerifier.shouldSucceed + |> verifyCompileAndRun + |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*SanityCheck02.exe Verified." + ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs index fd9eb1848d4..981b2e5d95a 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs @@ -34,6 +34,7 @@ module MyModule = printfn "Hello from main method" 0 """ + |> withName "SimpleTypesInNamespace" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed @@ -42,6 +43,11 @@ module MyModule = "Hello, World from MyLibrary.MySecondType" "Hello from main method" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*SimpleTypesInNamespace.exe Verified." + ] + [] // RealSig @@ -60,6 +66,7 @@ type MySecondType = printfn "Hello from implicit main method" """ + |> withName "SimpleTypesInImplicitMain" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed @@ -68,6 +75,10 @@ printfn "Hello from implicit main method" "Hello, World from MyProgram.MySecondType" "Hello from implicit main method" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*SimpleTypesInImplicitMain.exe Verified." + ] [] // RealSig @@ -91,6 +102,7 @@ module MyModule = printfn "Hello from main method" 0 """ + |> withName "SimpleTypeOneAndTypeTwoInNamespace" |> withRealInternalSignature realSig |> compileExeAndRun |> withStdOutContainsAllInOrder [ @@ -99,6 +111,10 @@ module MyModule = "Hello from main method" ] |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*SimpleTypeOneAndTypeTwoInNamespace.exe Verified." + ] [] // RealSig [] // Regular @@ -130,12 +146,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PublicTypePublicCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypePublicCtor.exe Verified." + ] [] // RealSig @@ -168,12 +189,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PublicTypeInternalCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeInternalCtor.exe Verified." + ] [] // RealSig @@ -206,12 +232,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PublicTypePrivateCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypePrivateCtor.exe Verified." + ] [] // RealSig [] // Regular @@ -243,12 +274,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PublicTypeUnspecifiedCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeUnspecifiedCtor.exe Verified." + ] [] // RealSig [] // Regular @@ -280,13 +316,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PrivateTypePublicCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] - + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypePublicCtor.exe Verified." + ] [] // RealSig [] // Regular @@ -318,12 +358,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PrivateTypeInternalCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> withStdOutContainsAllInOrder [ "Main program" ] |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInternalCtor.exe Verified." + ] [] // RealSig [] // Regular @@ -362,12 +407,17 @@ type FSharpSource with module doit = printfn "Main program" """ + |> withName "PrivateTypePrivateCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypePrivateCtor.exe Verified." + ] [] // RealSig [] // Regular @@ -399,12 +449,17 @@ module doit = FSharpSource.CreateFromFile("Hello") |> ignore printfn "Main program" """ + |> withName "PrivateTypeUnspecifiedCtor" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Main program" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeUnspecifiedCtor.exe Verified." + ] [] // RealSig [] // Regular @@ -439,12 +494,17 @@ let message = FSharpSourceFromFile.SetIt ("Here is something") printfn $"{message}" """ + |> withName "StaticInitializationNoInlinePrivateField" |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed |> withStdOutContainsAllInOrder [ "Here is something" ] + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*StaticInitializationNoInlinePrivateField.exe Verified." + ] [] // RealSig [] // Regular @@ -476,6 +536,7 @@ type MyClass = printfn "%A" (MyClass.result()) """ + |> withName "ComputationExpressionAccessPrivateBinding" |> withRealInternalSignature realSig |> withNoOptimize |> compileExeAndRun @@ -483,7 +544,10 @@ printfn "%A" (MyClass.result()) |> withStdOutContainsAllInOrder [ "Some 3" ] - + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*ComputationExpressionAccessPrivateBinding.exe Verified." + ] [] // RealSig Optimize [] // RealSig NoOptimize @@ -495,11 +559,16 @@ printfn "%A" (MyClass.result()) let source = File.ReadAllText (path) FSharp source + |> withName "NestedGenericClosure" |> asExe |> withRealInternalSignature realSig |> withOptimization optimize |> compileAndRun |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*NestedGenericClosure.exe Verified." + ] [] // RealSig Optimize [] // RealSig NoOptimize @@ -538,11 +607,16 @@ module doIt = for i in enumerator.MoveNext() do printfn "%A" i """ + |> withName "GenericClassWithClosureWithConstraints" |> asExe |> withRealInternalSignature realSig |> withOptimization optimize |> compileAndRun |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*GenericClassWithClosureWithConstraints.exe Verified." + ] [] // RealSig Optimize [] // RealSig NoOptimize @@ -700,11 +774,16 @@ type internal AgedLookup<'Token, 'Key, 'Value when 'Value: not struct>(keepStron let keep = FilterAndHold(tok) AssignWithStrength(tok, keep) """ + |> withName "AgedLookup" |> asLibrary |> withRealInternalSignature realSig |> withOptimization optimize |> compile |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*AgedLookup.dll Verified." + ] [] // RealSig Optimize [] // RealSig NoOptimize @@ -718,11 +797,16 @@ namespace Equality type BigGenericTuple<'a> = BigGenericTuple of int * 'a * byte * int * 'a * byte """ + |> withName "BigTuples" |> asLibrary |> withRealInternalSignature realSig |> withOptimization optimize |> compile |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*BigTuples.dll Verified." + ] [] // RealSig Optimize [] // RealSig NoOptimize @@ -735,14 +819,18 @@ type BigGenericTuple<'a> = BigGenericTuple of int * 'a * byte * int * 'a * byte module GroupByTest let ``for _ in Array groupBy id [||] do ...`` () = [|for _ in Array.groupBy id [||] do 0|] """ + |> withName "ArrayGroupById" |> asLibrary |> withRealInternalSignature realSig |> withOptimization optimize |> compile |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*ArrayGroupById.dll Verified." + ] - - let roundTripWithInterfaceGeneration(realsig, optimize, implementationFile) = + let roundTripWithInterfaceGeneration(realsig, optimize, implementationFile, name) = let generatedSignature = Fs implementationFile @@ -751,6 +839,7 @@ let ``for _ in Array groupBy id [||] do ...`` () = [|for _ in Array.groupBy id [ |> printSignatures Fsi generatedSignature + |> withName name |> asLibrary |> withAdditionalSourceFile (FsSource implementationFile) |> withRealInternalSignature realsig @@ -774,7 +863,11 @@ type IMonad<'a> = abstract bind : #IMonad<'a> -> ('a -> #IMonad<'b>) -> IMonad<'b> end""" - roundTripWithInterfaceGeneration(realsig, optimize, implementationFile) + roundTripWithInterfaceGeneration(realsig, optimize, implementationFile, "GenericParameterOrderRoundtrip") + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*GenericParameterOrderRoundtrip.dll Verified." + ] [] // RealSig Optimize [] // RealSig NoOptimize @@ -803,4 +896,8 @@ namespace GenericInterfaceTest new(x) = { store = x } end""" - roundTripWithInterfaceGeneration(realsig, optimize, implementationFile) + roundTripWithInterfaceGeneration(realsig, optimize, implementationFile, "MembersBasicRoundtrip") + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*MembersBasicRoundtrip.dll Verified." + ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs index 763bbc9c33e..a7ba195e02f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs @@ -24,9 +24,14 @@ type public TypeTwo internal () = class end type public TypeThree private () = class end type public TypeFour () = class end """ + |> withName "PublicTypeConstructors" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeConstructors.dll Verified." + ] |> withILContains [ if realSig then """ .class auto ansi serializable nested public TypeOne @@ -91,9 +96,14 @@ type private TypeOne public () = class end type private TypeTwo internal () = class end type private TypeThree private () = class end type private TypeFour () = class end""" + |> withName "PrivateTypeConstructors" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeConstructors.dll Verified." + ] |> withILContains [ if realSig then """ @@ -254,9 +264,14 @@ type public TestType () = member private _.PrivateMethod() = () member _.DefaultMethod() = () """ + |> withName "PublicTypeInstanceMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeInstanceMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig instance void PublicMethod() cil managed" @@ -285,9 +300,14 @@ type public TestType () = member private _.PrivateMethod() = () member _.DefaultMethod() = () """ + |> withName "PrivateTypeInstanceMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig instance void PublicMethod() cil managed" @@ -317,9 +337,14 @@ type public TestType () = member val private PrivateProperty = 0 with get, set member val DefaultProperty = 0 with get, set """ + |> withName "PublicTypeInstanceProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeInstanceProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_PublicProperty() cil managed" @@ -357,9 +382,14 @@ type public TestType () = member val private PrivateProperty = 0 with get, set member val DefaultProperty = 0 with get, set """ + |> withName "PrivateTypeInstanceMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_PublicProperty() cil managed" @@ -405,9 +435,14 @@ type public TestType () = member _.MixedPropertyEleven with internal get() = 0 and set (_:int) = () member _.MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PublicTypeInstanceMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeInstanceMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_MixedPropertyOne() cil managed" @@ -460,7 +495,6 @@ type public TestType () = ".method public hidebysig specialname instance void set_MixedPropertyEleven(int32 _arg11) cil managed" ".method assembly hidebysig specialname instance int32 get_MixedPropertyTwelve() cil managed" ".method public hidebysig specialname instance void set_MixedPropertyTwelve(int32 _arg12) cil managed" - ] |> shouldSucceed @@ -485,9 +519,14 @@ type private TestType () = member _.MixedPropertyEleven with internal get() = 0 and set (_:int) = () member _.MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PrivateTypeInstanceMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_MixedPropertyOne() cil managed" @@ -557,9 +596,14 @@ type public TestType () = static member private PrivateMethod() = () static member DefaultMethod() = () """ + |> withName "PublicTypeStaticMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeStaticMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public static void PublicMethod() cil managed" @@ -589,16 +633,20 @@ type private TestType () = static member private PrivateMethod() = () static member DefaultMethod() = () """ + |> withName "PrivateTypeStaticMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeStaticMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public static void PublicMethod() cil managed" ".method assembly static void InternalMethod() cil managed" ".method private static void PrivateMethod() cil managed" ".method public static void DefaultMethod() cil managed" - else ".method assembly static void PublicMethod() cil managed" ".method assembly static void InternalMethod() cil managed" @@ -620,9 +668,14 @@ type public TestType () = static member val internal InternalProperty = 0 with get, set static member val private PrivateProperty = 0 with get, set static member val DefaultProperty = 0 with get, set""" + |> withName "PublicTypeStaticProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeStaticProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_PublicProperty() cil managed" @@ -658,9 +711,14 @@ type private TestType () = static member val internal InternalProperty = 0 with get, set static member val private PrivateProperty = 0 with get, set static member val DefaultProperty = 0 with get, set""" + |> withName "PrivateTypeStaticProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeStaticProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_PublicProperty() cil managed" @@ -705,9 +763,14 @@ type public TestType () = static member MixedPropertyEleven with internal get() = 0 and set (_:int) = () static member MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PublicTypeStaticMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeStaticMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_MixedPropertyOne() cil managed" @@ -785,9 +848,14 @@ type private TestType () = static member MixedPropertyEleven with internal get() = 0 and set (_:int) = () static member MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PrivateTypeStaticMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeStaticMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_MixedPropertyOne() cil managed" @@ -844,12 +912,12 @@ type private TestType () = ] |> shouldSucceed - [] // RealSig - [] // Regular + [] // RealSig + [] // Regular [] // RealSig [] // Regular - [] // RealSig - [] // Regular + [] // RealSig + [] // Regular [] let ``lazy operation - member with various visibilities`` (realSig, scope) = FSharp $""" @@ -858,8 +926,13 @@ module internal SR = let getLazyThing () = lazyThing.Force() SR.getLazyThing () """ + |> withName "LazyOperationMemberWithVariousVisibilities" |> asExe |> withOptimize |> withRealInternalSignature realSig |> compileExeAndRun |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*LazyOperationMemberWithVariousVisibilities.exe Verified." + ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs index 695d6cd8ba2..bfddf645779 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs @@ -24,9 +24,14 @@ type public TypeTwo internal () = class end type public TypeThree private () = class end type public TypeFour () = class end """ + |> withName "PublicTypeConstructors" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeConstructors.dll Verified." + ] |> withILContains [ if realSig then """ @@ -189,9 +194,14 @@ type private TypeTwo internal () = class end type private TypeThree private () = class end type private TypeFour () = class end """ + |> withName "PrivateTypeConstructors" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeConstructors.dll Verified." + ] |> withILContains [ """ .class private auto ansi serializable RealInternalSignature.TypeOne @@ -282,9 +292,14 @@ type public TestType () = member private _.PrivateMethod() = () member _.DefaultMethod() = () """ + |> withName "PublicTypeInstanceMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeInstanceMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig instance void PublicMethod() cil managed" @@ -313,9 +328,14 @@ type private TestType () = member private _.PrivateMethod() = () member _.DefaultMethod() = () """ + |> withName "PrivateTypeInstanceMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig instance void PublicMethod() cil managed" @@ -345,9 +365,14 @@ type public TestType () = member val private PrivateProperty = 0 with get, set member val DefaultProperty = 0 with get, set """ + |> withName "PrivateTypeInstanceMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_PublicProperty() cil managed" @@ -385,9 +410,14 @@ type public TestType () = member val private PrivateProperty = 0 with get, set member val DefaultProperty = 0 with get, set """ + |> withName "PrivateTypeInstanceProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_PublicProperty() cil managed" @@ -433,9 +463,14 @@ type public TestType () = member _.MixedPropertyEleven with internal get() = 0 and set (_:int) = () member _.MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PublicTypeInstanceMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeInstanceMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname rtspecialname instance void .ctor() cil managed" @@ -515,9 +550,14 @@ type private TestType () = member _.MixedPropertyEleven with internal get() = 0 and set (_:int) = () member _.MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PrivateTypeInstanceMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeInstanceMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public hidebysig specialname instance int32 get_MixedPropertyOne() cil managed" @@ -586,9 +626,14 @@ type public TestType () = static member private PrivateMethod() = () static member DefaultMethod() = () """ + |> withName "PublicTypeStaticMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeStaticMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public static void PublicMethod() cil managed" @@ -617,9 +662,14 @@ type public TestType () = static member private PrivateMethod() = () static member DefaultMethod() = () """ + |> withName "PrivateTypeStaticMethods" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeStaticMethods.dll Verified." + ] |> withILContains [ if realSig then ".method public static void PublicMethod() cil managed" @@ -648,9 +698,14 @@ type public TestType () = static member val internal InternalProperty = 0 with get, set static member val private PrivateProperty = 0 with get, set static member val DefaultProperty = 0 with get, set""" + |> withName "PublicTypeStaticProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeStaticProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_PublicProperty() cil managed" @@ -687,9 +742,14 @@ type private TestType () = static member val internal InternalProperty = 0 with get, set static member val private PrivateProperty = 0 with get, set static member val DefaultProperty = 0 with get, set""" + |> withName "PrivateTypeStaticProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeStaticProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_PublicProperty() cil managed" @@ -735,9 +795,14 @@ type public TestType () = static member MixedPropertyEleven with internal get() = 0 and set (_:int) = () static member MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PublicTypeStatiMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PublicTypeStatiMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_MixedPropertyOne() cil managed" @@ -815,9 +880,14 @@ type private TestType () = static member MixedPropertyEleven with internal get() = 0 and set (_:int) = () static member MixedPropertyTwelve with private get() = 0 and set (_:int) = () """ + |> withName "PrivateTypeStatiMixedProperties" |> asLibrary |> withRealInternalSignature realSig |> compile + |> verifyPEFileWithSystemDlls + |> withOutputContainsAllInOrderWithWildcards [ + "All Classes and Methods in*PrivateTypeStatiMixedProperties.dll Verified." + ] |> withILContains [ if realSig then ".method public specialname static int32 get_MixedPropertyOne() cil managed" diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index f437d11923c..1c9fca26592 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -204,6 +204,8 @@ module rec Compiler = with member this.Output = match this with Success o | Failure o -> o member this.RunOutput = this.Output.Output + member this.Compilation = this.Output.Compilation + member this.OutputPath = this.Output.OutputPath type ExecutionPlatform = | Anycpu = 0 @@ -1817,7 +1819,20 @@ Actual: | _ -> failwith "Cannot check exit code on this run result." result - let private checkOutputInOrder (category: string) (substrings: string list) (selector: ExecutionOutput -> string) (result: CompilationResult) : CompilationResult = + let private getMatch (input: string) (pattern: string) useWildcards= + // Escape special characters and replace wildcards with regex equivalents + if useWildcards then + let input = input.Replace("\r\n", "\n") + let pattern = $"""^{Regex.Escape(pattern).Replace("\\*", ".*").Replace("\\?", ".")}$""" + let m = Regex(pattern, RegexOptions.Multiline).Match(input) + if m.Success then + m.Index + else + -1 + else + input.IndexOf(pattern) + + let private checkOutputInOrderCore useWildcards (category: string) (substrings: string list) (selector: ExecutionOutput -> string) (result: CompilationResult) : CompilationResult = match result.RunOutput with | None -> printfn "Execution output is missing cannot check \"%A\"" category @@ -1825,20 +1840,23 @@ Actual: | Some o -> match o with | ExecutionOutput e -> - let where = selector e + let input = selector e let mutable searchPos = 0 for substring in substrings do - match where.IndexOf(substring, searchPos) with - | -1 -> failwith (sprintf "\nThe following substring:\n %A\nwas not found in the %A\nOutput:\n %A" substring category where) + match getMatch (input.Substring(searchPos)) substring useWildcards with + | -1 -> failwith (sprintf "\nThe following substring:\n %A\nwas not found in the %A\nOutput:\n %A" substring category input) | pos -> searchPos <- pos + substring.Length | _ -> failwith "Cannot check output on this run result." result + let private checkOutputInOrder category substrings selector result = + checkOutputInOrderCore false category substrings selector result + let withOutputContainsAllInOrder (substrings: string list) (result: CompilationResult) : CompilationResult = checkOutputInOrder "STDERR/STDOUT" substrings (fun o -> o.StdOut + "\n" + o.StdErr) result let withStdOutContains (substring: string) (result: CompilationResult) : CompilationResult = - checkOutputInOrder "STDOUT" [substring] (fun o -> o.StdOut) result + checkOutputInOrder "STDOUT" [substring] (fun o -> o.StdOut) result let withStdOutContainsAllInOrder (substrings: string list) (result: CompilationResult) : CompilationResult = checkOutputInOrder "STDOUT" substrings (fun o -> o.StdOut) result @@ -1849,6 +1867,24 @@ Actual: let withStdErrContains (substring: string) (result: CompilationResult) : CompilationResult = checkOutputInOrder "STDERR" [substring] (fun o -> o.StdErr) result + let private checkOutputInOrderWithWildcards category substrings selector result = + checkOutputInOrderCore true category substrings selector result + + let withOutputContainsAllInOrderWithWildcards (substrings: string list) (result: CompilationResult) : CompilationResult = + checkOutputInOrderWithWildcards "STDERR/STDOUT" substrings (fun o -> o.StdOut + "\n" + o.StdErr) result + + let withStdOutContainsWithWildcards (substring: string) (result: CompilationResult) : CompilationResult = + checkOutputInOrderWithWildcards "STDOUT" [substring] (fun o -> o.StdOut) result + + let withStdOutContainsAllInOrderWithWildcards (substrings: string list) (result: CompilationResult) : CompilationResult = + checkOutputInOrderWithWildcards "STDOUT" substrings (fun o -> o.StdOut) result + + let withStdErrContainsAllInOrderWithWildcards (substrings: string list) (result: CompilationResult) : CompilationResult = + checkOutputInOrderWithWildcards "STDERR" substrings (fun o -> o.StdErr) result + + let withStdErrContainsWithWildcards (substring: string) (result: CompilationResult) : CompilationResult = + checkOutputInOrderWithWildcards "STDERR" [substring] (fun o -> o.StdErr) result + let private assertEvalOutput (selector: FsiValue -> 'T) (value: 'T) (result: CompilationResult) : CompilationResult = match result.RunOutput with | None -> failwith "Execution output is missing cannot check value." diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index cc5fb4c3e9b..0f7baf597fb 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -59,6 +59,8 @@ module AssemblyResolver = match found() with | None -> Unchecked.defaultof | Some name -> Assembly.Load(name) ) + + do addResolver() #endif type ExecutionOutcome = diff --git a/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj b/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj index 192783edd57..37c1940b7a9 100644 --- a/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj +++ b/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj @@ -40,7 +40,7 @@ - + @@ -106,7 +106,7 @@ - + diff --git a/tests/FSharp.Test.Utilities/ILVerifierModule.fs b/tests/FSharp.Test.Utilities/ILVerifierModule.fs new file mode 100644 index 00000000000..f2b2e74eaf8 --- /dev/null +++ b/tests/FSharp.Test.Utilities/ILVerifierModule.fs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. +namespace FSharp.Test + +open FSharp.Test.Compiler +open System +open System.IO +open TestFramework + +[] +module ILVerifierModule = + let config = initializeSuite () + + let private exec (dotnetExe: string) args workingDirectory = + let arguments = args |> String.concat " " + let exitCode, _output, errors = Commands.executeProcess dotnetExe arguments workingDirectory + let errors = errors |> String.concat Environment.NewLine + errors, exitCode + + let private verifyPEFileCore peverifierArgs (dllFilePath: string) = + let nuget_packages = + match Environment.GetEnvironmentVariable("NUGET_PACKAGES") with + | null -> + let profile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + $"""{profile}/.nuget/packages""" + | path -> path + let peverifyFullArgs = [ yield "exec"; yield $"""{nuget_packages}/dotnet-ilverify/9.0.0/tools/net9.0/any/ILVerify.dll"""; yield "--verbose"; yield dllFilePath; yield! peverifierArgs ] + let workingDirectory = Path.GetDirectoryName dllFilePath + let _, exitCode = + let peverifierCommandPath = Path.ChangeExtension(dllFilePath, ".peverifierCommandPath.cmd") + let args = peverifyFullArgs |> Seq.fold(fun a acc -> $"{a} " + acc) "" + File.WriteAllLines(peverifierCommandPath, [| $"{args}" |] ) + File.Copy(typeof.Assembly.Location, Path.GetDirectoryName(dllFilePath) ++ "FSharp.Core.dll", true) + exec config.DotNetExe peverifyFullArgs workingDirectory + + // Grab output + let outputText = File.ReadAllText(Path.Combine(workingDirectory, "StandardOutput.txt")) + let errorText = File.ReadAllText(Path.Combine(workingDirectory, "StandardError.txt")) + + match exitCode with + | 0 -> {Outcome = NoExitCode; StdOut = outputText; StdErr = errorText } + | _ -> {Outcome = ExitCode exitCode; StdOut = outputText; StdErr = errorText } + + let private verifyPEFileAux (compilationResult: CompilationResult) args = + let result = + match compilationResult.Compilation with + | FS _ -> + match compilationResult, compilationResult.OutputPath with + | CompilationResult.Success result, Some name -> + let verifyResult = verifyPEFileCore args name + match verifyResult.Outcome with + | NoExitCode -> CompilationResult.Success {result with Output = Some (ExecutionOutput verifyResult)} + | ExitCode _ -> CompilationResult.Failure {result with Output = Some (ExecutionOutput verifyResult)} + | failed -> failwith $"Compilation must succeed in order to verify IL.{failed}" + | failed -> + failwith $"""Compilation must succeed in order to verify IL.{failed}""" + | _ -> + failwith "PEVerify is only supported for F#." + result + + let verifyPEFile compilationResult = + verifyPEFileAux compilationResult [||] + + let verifyPEFileWithArgs compilationResult args = + verifyPEFileCore compilationResult args + + let verifyPEFileWithSystemDlls compilationResult = + // Get the path containing mecorlib.dll or System.Core.Private.dll + let fsharpCorePath = typeof.Assembly.Location + let systemPath = Path.GetDirectoryName(typeof.Assembly.Location) + let systemDllPaths = + DirectoryInfo(systemPath).GetFiles("*.dll") + |> Array.map (fun dll -> $"--reference \"{Path.Combine(systemPath, dll.FullName)}\"") + |> Array.toList + verifyPEFileAux compilationResult ($"--reference \"{fsharpCorePath}\"" :: systemDllPaths) diff --git a/tests/FSharp.Test.Utilities/Peverifier.fs b/tests/FSharp.Test.Utilities/Peverifier.fs deleted file mode 100644 index aff44b3d749..00000000000 --- a/tests/FSharp.Test.Utilities/Peverifier.fs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Test - -open FSharp.Test.Compiler -open System -open System.IO -open TestFramework - -type PEVerifyOutput ={ - ExitCode: int - OutputLines: string array - ErrorLines: string array - } - -[] -type PEVerifyResult = - | Success of PEVerifyOutput - | Failure of PEVerifyOutput - -[] -module PEVerifier = - let config = initializeSuite () - - let private exec (dotnetExe: string) args workingDirectory = - let arguments = args |> String.concat " " - let exitCode, _output, errors = Commands.executeProcess dotnetExe arguments workingDirectory - let errors = errors |> String.concat Environment.NewLine - errors, exitCode - - let private verifyPEFileCore peverifierArgs (dllFilePath: string) = - let mutable errors = ResizeArray () - let peverifyFullArgs = [ yield "--verbose"; yield dllFilePath; yield! peverifierArgs ] - let workingDirectory = Path.GetDirectoryName dllFilePath - let _, exitCode = - let peverifierCommandPath = Path.ChangeExtension(dllFilePath, ".peverifierCommandPath.cmd") - let args = peverifyFullArgs |> Seq.fold(fun a acc -> $"{a} " + acc) "" - File.WriteAllLines(peverifierCommandPath, [| $"{args}" |] ) - File.Copy(typeof.Assembly.Location, Path.GetDirectoryName(dllFilePath) ++ "FSharp.Core.dll", true) - let profile = Environment.GetEnvironmentVariable("USERPROFILE") - exec $"{profile}/.dotnet/tools/ilverify.exe" peverifyFullArgs workingDirectory - - // Grab output - let outputLines = File.ReadAllLines(Path.Combine(workingDirectory, "StandardOutput.txt")) - let errorLines = File.ReadAllLines(Path.Combine(workingDirectory, "StandardError.txt")) - - let result = { - ExitCode = exitCode - OutputLines = outputLines - ErrorLines = errorLines - } - - if result.ExitCode <> 0 then - errors.Add ($"PEVERIFIER failed with error code: {exitCode}") - - if result.ErrorLines |> Array.length <= 0 then - errors.Add ($"PEVERIFIER stderr is not empty:\n {result.ErrorLines}") - - match errors.Count with - | 0 -> PEVerifyResult.Success result - | _ -> PEVerifyResult.Failure result - - let private verifyPEFileAux cUnit args = - let result = - match cUnit with - | FS fs -> - match compile cUnit, fs.OutputFileName with - | CompilationResult.Success _, Some name -> - verifyPEFileCore args name - | failed -> - failwith $"""Compilation must succeed in order to verify IL.{failed}""" - | _ -> - failwith "PEVerify is only supported for F#." - result - - let verifyPEFile cUnit = - verifyPEFileAux cUnit [||] - - let verifyPEFileWithArgs cUnit args = - verifyPEFileCore cUnit args - - let verifyPEFileWithSystemDlls cUnit = - // Get the path containing mecorlib.dll or System.Core.Private.dll - let fsharpCorePath = typeof.Assembly.Location - let systemPath = Path.GetDirectoryName(typeof.Assembly.Location) - let systemDllPaths = - DirectoryInfo(systemPath).GetFiles("*.dll") - |> Array.map (fun dll -> $"--reference \"{Path.Combine(systemPath, dll.FullName)}\"") - |> Array.toList - verifyPEFileAux cUnit ($"--reference \"{fsharpCorePath}\"" :: systemDllPaths) - - let shouldFail result = - match result with - | PEVerifyResult.Success _ -> failwith $"Expected to Fail - {result}" - | PEVerifyResult.Failure _ -> () - - let shouldSucceed result = - match result with - | PEVerifyResult.Success _ -> () - | PEVerifyResult.Failure _ -> failwith $"Expected to Succeed - {result}" diff --git a/tests/FSharp.Test.Utilities/TestFramework.fs b/tests/FSharp.Test.Utilities/TestFramework.fs index 54e5fb8293b..06b454005c2 100644 --- a/tests/FSharp.Test.Utilities/TestFramework.fs +++ b/tests/FSharp.Test.Utilities/TestFramework.fs @@ -14,12 +14,12 @@ let getShortId() = Guid.NewGuid().ToString().[..7] // Temporary directory is TempPath + "/FSharp.Test.Utilities/xxxxxxx/" let tempDirectoryOfThisTestRun = - let temp = Path.GetTempPath() - lazy DirectoryInfo(temp).CreateSubdirectory($"FSharp.Test.Utilities/{getShortId()}") + let temp = DirectoryInfo(Path.Combine(__SOURCE_DIRECTORY__, @"../../artifacts/Temp/FSharp.Test.Utilities", $"{getShortId()}")) + lazy (temp.Create(); temp) let cleanUpTemporaryDirectoryOfThisTestRun () = if tempDirectoryOfThisTestRun.IsValueCreated then - try tempDirectoryOfThisTestRun.Value.Delete(true) with _ -> () + ()//try tempDirectoryOfThisTestRun.Value.Delete(true) with _ -> () let createTemporaryDirectory () = tempDirectoryOfThisTestRun.Value @@ -87,10 +87,13 @@ module Commands = psi.RedirectStandardError <- true psi.Arguments <- arguments psi.CreateNoWindow <- true + // When running tests, we want to roll forward to minor versions (including previews). psi.EnvironmentVariables["DOTNET_ROLL_FORWARD"] <- "LatestMajor" psi.EnvironmentVariables["DOTNET_ROLL_FORWARD_TO_PRERELEASE"] <- "1" - psi.EnvironmentVariables.Remove("MSBuildSDKsPath") // Host can sometimes add this, and it can break things + + // Host can sometimes add this, and it can break things + psi.EnvironmentVariables.Remove("MSBuildSDKsPath") psi.UseShellExecute <- false use p = new Process() From 29868c0472def191177fb48cacc3ab47cc5a48cb Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Thu, 23 Jan 2025 17:31:17 -0800 Subject: [PATCH 3/4] verifyil --- ...ify_FSharp.Compiler.Service_Debug_net9.0.bsl | 17 ----------------- ...rp.Compiler.Service_Debug_netstandard2.0.bsl | 17 ----------------- ...y_FSharp.Compiler.Service_Release_net9.0.bsl | 12 ------------ ....Compiler.Service_Release_netstandard2.0.bsl | 12 ------------ 4 files changed, 58 deletions(-) diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl index d301673c927..41e393f5f30 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl @@ -71,20 +71,3 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.IO.FileSystemUtils::trimQuotes(string)][offset 0x00000014][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.String::lowerCaseFirstChar(string)][offset 0x0000003F][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.Array+loop@276-4::Invoke(int32)][offset 0x00000012][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Choose([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, !!0[])][offset 0x000000A0][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000029][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Partition([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000038][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+Pipe #2 input at line 2241@2245-1::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000030][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+Pipe #2 input at line 2571@2575-1::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000022][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x00000020][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x00000031][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000029][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000033][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x00000075][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.Operators::castToString(!!0)][offset 0x00000001][found value 'T'][expected ref 'string'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives::retype(!!0)][offset 0x00000001][found value 'T'][expected value 'TResult'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x0000001C][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x00000023][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.BasicInlinedOperations::castclassPrim(object)][offset 0x00000006][found ref 'T'][expected value 'T'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.BasicInlinedOperations::notnullPrim(!!0)][offset 0x00000002][found Nullobjref 'NullReference'][expected value 'T'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.BasicInlinedOperations::iscastPrim(object)][offset 0x00000006][found ref 'T'][expected value 'T'] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl index 81cc143b139..23bfed609bb 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl @@ -96,20 +96,3 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.IO.FileSystemUtils::trimQuotes(string)][offset 0x00000014][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.String::lowerCaseFirstChar(string)][offset 0x0000003F][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.Array+loop@276-4::Invoke(int32)][offset 0x00000012][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Choose([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, !!0[])][offset 0x000000A0][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000029][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Partition([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000038][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+Pipe #2 input at line 2241@2245-1::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000030][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+Pipe #2 input at line 2571@2575-1::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000022][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x00000020][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x00000031][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000029][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000033][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x00000075][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.Operators::castToString(!!0)][offset 0x00000001][found value 'T'][expected ref 'string'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives::retype(!!0)][offset 0x00000001][found value 'T'][expected value 'TResult'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x0000001C][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x00000023][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.BasicInlinedOperations::castclassPrim(object)][offset 0x00000006][found ref 'T'][expected value 'T'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.BasicInlinedOperations::notnullPrim(!!0)][offset 0x00000002][found Nullobjref 'NullReference'][expected value 'T'] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.BasicInlinedOperations::iscastPrim(object)][offset 0x00000006][found ref 'T'][expected value 'T'] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl index 8c2b6a97465..d1ac4690f8b 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl @@ -97,15 +97,3 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.IO.FileSystemUtils::trimQuotes(string)][offset 0x00000014][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.String::lowerCaseFirstChar(string)][offset 0x0000003A][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.Array::loop@275-3(bool[], int32)][offset 0x00000008][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Choose([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, !!0[])][offset 0x00000081][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000029][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Partition([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000038][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+Choose@2245-2::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000030][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+countAndCollectTrueItems@2575-1::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000022][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x0000001E][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x0000002D][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000029][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000033][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x0000006C][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x0000001C][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x00000023][found Short] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl index 588f29f5a96..15bc7aba394 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl @@ -123,15 +123,3 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.IO.FileSystemUtils::trimQuotes(string)][offset 0x00000014][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.String::lowerCaseFirstChar(string)][offset 0x0000003A][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Library.Array::loop@275-3(bool[], int32)][offset 0x00000008][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Choose([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, !!0[])][offset 0x00000081][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000029][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel::Partition([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, !!0[])][offset 0x00000038][found Byte] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+Choose@2245-2::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000030][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Collections.ArrayModule+Parallel+countAndCollectTrueItems@2575-1::Invoke(int32, [System.Threading.Tasks.Parallel]System.Threading.Tasks.ParallelLoopState, int32)][offset 0x00000022][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x0000001E][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Map([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x0000002D][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000029][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::MapIndexed([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, string)][offset 0x00000033][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.StringModule::Filter([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, string)][offset 0x0000006C][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x0000001C][found Short] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Microsoft.FSharp.Core.LanguagePrimitives+HashCompare::GenericEqualityCharArray(char[], char[])][offset 0x00000023][found Short] Unexpected type on the stack. From 0c4c2a1013926073dae899dbc66264b9af70c022 Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Fri, 24 Jan 2025 11:41:19 -0800 Subject: [PATCH 4/4] feedback --- .../FSharp.Test.Utilities/ILVerifierModule.fs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/FSharp.Test.Utilities/ILVerifierModule.fs b/tests/FSharp.Test.Utilities/ILVerifierModule.fs index f2b2e74eaf8..8610476f217 100644 --- a/tests/FSharp.Test.Utilities/ILVerifierModule.fs +++ b/tests/FSharp.Test.Utilities/ILVerifierModule.fs @@ -10,6 +10,17 @@ open TestFramework module ILVerifierModule = let config = initializeSuite () + let fsharpCoreReference = $"--reference \"{typeof.Assembly.Location}\"" + + let private systemDllReferences = + // Get the path containing mecorlib.dll or System.Core.Private.dll + let refs = + let systemPath = Path.GetDirectoryName(typeof.Assembly.Location) + DirectoryInfo(systemPath).GetFiles("*.dll") + |> Array.map (fun dll -> $"--reference \"{Path.Combine(systemPath, dll.FullName)}\"") + |> Array.toList + (fsharpCoreReference :: refs) + let private exec (dotnetExe: string) args workingDirectory = let arguments = args |> String.concat " " let exitCode, _output, errors = Commands.executeProcess dotnetExe arguments workingDirectory @@ -58,17 +69,10 @@ module ILVerifierModule = result let verifyPEFile compilationResult = - verifyPEFileAux compilationResult [||] + verifyPEFileAux compilationResult [| fsharpCoreReference |] let verifyPEFileWithArgs compilationResult args = - verifyPEFileCore compilationResult args + verifyPEFileAux compilationResult (fsharpCoreReference :: args) let verifyPEFileWithSystemDlls compilationResult = - // Get the path containing mecorlib.dll or System.Core.Private.dll - let fsharpCorePath = typeof.Assembly.Location - let systemPath = Path.GetDirectoryName(typeof.Assembly.Location) - let systemDllPaths = - DirectoryInfo(systemPath).GetFiles("*.dll") - |> Array.map (fun dll -> $"--reference \"{Path.Combine(systemPath, dll.FullName)}\"") - |> Array.toList - verifyPEFileAux compilationResult ($"--reference \"{fsharpCorePath}\"" :: systemDllPaths) + verifyPEFileAux compilationResult systemDllReferences