-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7192 from dotnet/merges/release/dev16.3-to-releas…
…e/fsharp47 Merge release/dev16.3 to release/fsharp47
- Loading branch information
Showing
11 changed files
with
3,936 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.UnitTests | ||
|
||
open System | ||
open System.IO | ||
open System.Diagnostics | ||
|
||
open NUnit.Framework | ||
open TestFramework | ||
|
||
[<RequireQualifiedAccess>] | ||
module ILChecker = | ||
|
||
let config = initializeSuite () | ||
|
||
let private exec exe args = | ||
let startInfo = ProcessStartInfo(exe, String.concat " " args) | ||
startInfo.RedirectStandardError <- true | ||
startInfo.UseShellExecute <- false | ||
use p = Process.Start(startInfo) | ||
p.WaitForExit() | ||
p.StandardError.ReadToEnd(), p.ExitCode | ||
|
||
/// Filters i.e ['The system type \'System.ReadOnlySpan`1\' was required but no referenced system DLL contained this type'] | ||
let private filterSpecialComment (text: string) = | ||
let pattern = @"(\[\'(.*?)\'\])" | ||
System.Text.RegularExpressions.Regex.Replace(text, pattern, | ||
(fun me -> String.Empty) | ||
) | ||
|
||
let private checkILAux ildasmArgs dllFilePath expectedIL = | ||
let ilFilePath = Path.ChangeExtension(dllFilePath, ".il") | ||
|
||
let mutable errorMsgOpt = None | ||
try | ||
let ildasmPath = config.ILDASM | ||
|
||
exec ildasmPath (ildasmArgs @ [ sprintf "%s /out=%s" dllFilePath ilFilePath ]) |> ignore | ||
|
||
let text = File.ReadAllText(ilFilePath) | ||
let blockComments = @"/\*(.*?)\*/" | ||
let lineComments = @"//(.*?)\r?\n" | ||
let strings = @"""((\\[^\n]|[^""\n])*)""" | ||
let verbatimStrings = @"@(""[^""]*"")+" | ||
let textNoComments = | ||
System.Text.RegularExpressions.Regex.Replace(text, | ||
blockComments + "|" + lineComments + "|" + strings + "|" + verbatimStrings, | ||
(fun me -> | ||
if (me.Value.StartsWith("/*") || me.Value.StartsWith("//")) then | ||
if me.Value.StartsWith("//") then Environment.NewLine else String.Empty | ||
else | ||
me.Value), System.Text.RegularExpressions.RegexOptions.Singleline) | ||
|> filterSpecialComment | ||
|
||
expectedIL | ||
|> List.iter (fun (ilCode: string) -> | ||
let expectedLines = ilCode.Split('\n') | ||
let startIndex = textNoComments.IndexOf(expectedLines.[0]) | ||
if startIndex = -1 || textNoComments.Length < startIndex + ilCode.Length then | ||
errorMsgOpt <- Some("==EXPECTED CONTAINS==\n" + ilCode + "\n") | ||
else | ||
let errors = ResizeArray() | ||
let actualLines = textNoComments.Substring(startIndex, textNoComments.Length - startIndex).Split('\n') | ||
for i = 0 to expectedLines.Length - 1 do | ||
let expected = expectedLines.[i].Trim() | ||
let actual = actualLines.[i].Trim() | ||
if expected <> actual then | ||
errors.Add(sprintf "\n==\nName: %s\n\nExpected:\t %s\nActual:\t\t %s\n==" actualLines.[0] expected actual) | ||
|
||
if errors.Count > 0 then | ||
let msg = String.concat "\n" errors + "\n\n\n==EXPECTED==\n" + ilCode + "\n" | ||
errorMsgOpt <- Some(msg + "\n\n\n==ACTUAL==\n" + String.Join("\n", actualLines, 0, expectedLines.Length)) | ||
) | ||
|
||
if expectedIL.Length = 0 then | ||
errorMsgOpt <- Some ("No Expected IL") | ||
|
||
match errorMsgOpt with | ||
| Some(msg) -> errorMsgOpt <- Some(msg + "\n\n\n==ENTIRE ACTUAL==\n" + textNoComments) | ||
| _ -> () | ||
finally | ||
try File.Delete(ilFilePath) with | _ -> () | ||
|
||
match errorMsgOpt with | ||
| Some(errorMsg) -> | ||
Assert.Fail(errorMsg) | ||
| _ -> () | ||
|
||
let checkILItem item dllFilePath expectedIL = | ||
checkILAux [ sprintf "/item:%s" item ] dllFilePath expectedIL | ||
|
||
let checkILItemWithLineNumbers item dllFilePath expectedIL = | ||
checkILAux [ sprintf "/item:\"%s\"" item; "/linenum" ] dllFilePath expectedIL | ||
|
||
let checkIL dllFilePath expectedIL = | ||
checkILAux [] dllFilePath expectedIL |
Oops, something went wrong.