From 45abdfb07e243eed3c645667b9199e8d30e7c8c8 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Mon, 10 Feb 2025 18:55:50 +0100 Subject: [PATCH] wip - see what breaks --- src/Compiler/Utilities/range.fs | 6 +++ .../ErrorMessages/NameResolutionTests.fs | 10 +++-- tests/FSharp.Test.Utilities/Compiler.fs | 11 ++--- tests/FSharp.Test.Utilities/CompilerAssert.fs | 41 ++++++++++++------- .../ProjectGeneration.fs | 2 +- tests/FSharp.Test.Utilities/XunitHelpers.fs | 1 + .../Compiler/Service/MultiProjectTests.fs | 2 +- 7 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/Compiler/Utilities/range.fs b/src/Compiler/Utilities/range.fs index 5e13752df0b..cc1e198deeb 100755 --- a/src/Compiler/Utilities/range.fs +++ b/src/Compiler/Utilities/range.fs @@ -193,6 +193,7 @@ type FileIndexTable() = // // TO move forward we should eventually introduce a new type NormalizedFileName that tracks this invariant. member t.FileToIndex normalize filePath = + match fileToIndexTable.TryGetValue filePath with | true, idx -> idx | _ -> @@ -203,6 +204,11 @@ type FileIndexTable() = else filePath + + //match normalizedFilePath with + //| "test.fs" | "test.fsx" | "test.fsi" -> failwith "FileToIndex naked test file" + //| _ -> () + match fileToIndexTable.TryGetValue normalizedFilePath with | true, idx -> // Record the non-normalized entry if necessary diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs index d40e5e8d43c..ce79ac956ee 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs @@ -10,6 +10,7 @@ module NameResolutionTests = [] let FieldNotInRecord () = FSharp """ +module Test type A = { Hello:string; World:string } type B = { Size:int; Height:int } type C = { Wheels:int } @@ -22,13 +23,14 @@ let r:F = { Size=3; Height=4; Wall=1 } |> typecheck |> shouldFail |> withDiagnostics [ - (Error 1129, Line 9, Col 31, Line 9, Col 35, "The record type 'F' does not contain a label 'Wall'. Maybe you want one of the following:" + System.Environment.NewLine + " Wallis") - (Error 764, Line 9, Col 11, Line 9, Col 39, "No assignment given for field 'Wallis' of type 'Test.F'") + (Error 1129, Line 10, Col 31, Line 10, Col 35, "The record type 'F' does not contain a label 'Wall'. Maybe you want one of the following:" + System.Environment.NewLine + " Wallis") + (Error 764, Line 10, Col 11, Line 10, Col 39, "No assignment given for field 'Wallis' of type 'Test.F'") ] [] let RecordFieldProposal () = FSharp """ +module Test type A = { Hello:string; World:string } type B = { Size:int; Height:int } type C = { Wheels:int } @@ -41,8 +43,8 @@ let r = { Size=3; Height=4; Wall=1 } |> typecheck |> shouldFail |> withDiagnostics [ - (Error 39, Line 9, Col 29, Line 9, Col 33, "The record label 'Wall' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Walls" + System.Environment.NewLine + " Wallis") - (Error 764, Line 9, Col 9, Line 9, Col 37, "No assignment given for field 'Wallis' of type 'Test.F'") + (Error 39, Line 10, Col 29, Line 10, Col 33, "The record label 'Wall' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Walls" + System.Environment.NewLine + " Wallis") + (Error 764, Line 10, Col 9, Line 10, Col 37, "No assignment given for field 'Wallis' of type 'Test.F'") ] let multipleRecdTypeChoiceWarningWith1AlternativeSource = """ diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index c6346cb30f2..6c72adb9d82 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -29,6 +29,7 @@ open TestFramework open System.Runtime.CompilerServices open System.Runtime.InteropServices open FSharp.Compiler.CodeAnalysis +open System.Threading module rec Compiler = @@ -435,19 +436,19 @@ module rec Compiler = } let FsxSourceCode source = - SourceCodeFileKind.Fsx({FileName="test.fsx"; SourceText=Some source}) + SourceCodeFileKind.Fsx({FileName=FileNames.TestFsx; SourceText=Some source}) let Source source = - SourceCodeFileKind.Create("test.fs", source) + SourceCodeFileKind.Create(FileNames.TestFs, source) let SourceFromPath path = SourceCodeFileKind.Create(path) let FsiSource source = - SourceCodeFileKind.Fsi({FileName="test.fsi"; SourceText=Some source }) + SourceCodeFileKind.Fsi({FileName= FileNames.TestFsi; SourceText=Some source }) let FsSource source = - SourceCodeFileKind.Fs({FileName="test.fs"; SourceText=Some source }) + SourceCodeFileKind.Fs({FileName= FileNames.TestFs; SourceText=Some source }) let CsSource source = SourceCodeFileKind.Cs({FileName="test.cs"; SourceText=Some source }) @@ -998,7 +999,7 @@ module rec Compiler = | None -> File.ReadAllText(fsSource.Source.GetSourceFileName) | Some text -> text let options = fsSource.Options |> Array.ofList - let (err: FSharpDiagnostic []) = CompilerAssert.TypeCheckWithOptionsAndName options (fsSource.Name |> Option.defaultValue "test.fs") source + let (err: FSharpDiagnostic []) = CompilerAssert.TypeCheckWithOptionsAndName options (fsSource.Name |> Option.defaultValue FileNames.TestFs) source err let private typecheckFSharpSource (fsSource: FSharpCompilationSource) : CompilationResult = diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 0f7baf597fb..bb67818601f 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -27,6 +27,17 @@ open Xunit open TestFramework open System.Collections.Immutable +type FileNames = + static let testFileName = AsyncLocal() + static let mutable counter = 0 + //static do testFileName.Value <- "test" + static member internal MakeTestFileNameUniqueForThisTestCase() = + testFileName.Value <- $"{Interlocked.Increment &counter}{Path.PathSeparator}test" + + static member TestFs with get() = $"{testFileName.Value}.fs" + static member TestFsx with get() = $"{testFileName.Value}.fsx" + static member TestFsi with get() = $"{testFileName.Value}.fsi" + static member Test with get() = testFileName.Value #if !NETCOREAPP module AssemblyResolver = @@ -407,9 +418,9 @@ module CompilerAssertHelpers = #endif |] { - ProjectFileName = "Z:\\test.fsproj" + ProjectFileName = "Z:\\" ++ "test.fsproj" ProjectId = None - SourceFiles = [|"test.fs"|] + SourceFiles = [| FileNames.TestFs |] OtherOptions = Array.append testDefaults assemblies ReferencedProjects = [||] IsIncompleteTypeCheckEnvironment = false @@ -742,7 +753,7 @@ Updated automatically, please check diffs in your pull request, changes must be Assert.Equal(expectedOutput, output) static member Pass (source: string) = - let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(FileNames.TestFs, 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics) @@ -752,11 +763,11 @@ Updated automatically, please check diffs in your pull request, changes must be Assert.Empty(typeCheckResults.Diagnostics) - static member PassWithOptions options (source: string) = + static member PassWithOptions options (source: string) = let defaultOptions = defaultProjectOptions TargetFramework.Current let options = { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions} - let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, options) |> Async.RunImmediate + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(FileNames.TestFs, 0, SourceText.ofString source, options) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics) @@ -872,7 +883,7 @@ Updated automatically, please check diffs in your pull request, changes must be let parseResults, fileAnswer = let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( - "test.fs", + FileNames.TestFs, 0, SourceText.ofString source, { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) @@ -932,7 +943,7 @@ Updated automatically, please check diffs in your pull request, changes must be Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors)) static member CompileExeWithOptions(options, (source: string)) = - compile true options (SourceCodeFileKind.Create("test.fs", source)) (fun (errors, _, _) -> + compile true options (SourceCodeFileKind.Create(FileNames.TestFs, source)) (fun (errors, _, _) -> if errors.Length > 0 then Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors)) @@ -940,40 +951,40 @@ Updated automatically, please check diffs in your pull request, changes must be CompilerAssert.CompileExeWithOptions([||], source) static member CompileExe (source: string) = - CompilerAssert.CompileExeWithOptions([||], (SourceCodeFileKind.Create("test.fs", source))) + CompilerAssert.CompileExeWithOptions([||], (SourceCodeFileKind.Create(FileNames.TestFs, source))) static member CompileExeAndRunWithOptions(options, (source: SourceCodeFileKind)) = compileExeAndRunWithOptions options source static member CompileExeAndRunWithOptions(options, (source: string)) = - compileExeAndRunWithOptions options (SourceCodeFileKind.Create("test.fs", source)) + compileExeAndRunWithOptions options (SourceCodeFileKind.Create(FileNames.TestFs, source)) static member CompileExeAndRun (source: SourceCodeFileKind) = compileExeAndRunWithOptions [||] source static member CompileExeAndRun (source: string) = - compileExeAndRunWithOptions [||] (SourceCodeFileKind.Create("test.fs", source)) + compileExeAndRunWithOptions [||] (SourceCodeFileKind.Create(FileNames.TestFs, source)) static member CompileLibraryAndVerifyILWithOptions(options, (source: SourceCodeFileKind), (f: ILVerifier -> unit)) = compileLibraryAndVerifyILWithOptions options source f static member CompileLibraryAndVerifyILWithOptions(options, (source: string), (f: ILVerifier -> unit)) = - compileLibraryAndVerifyILWithOptions options (SourceCodeFileKind.Create("test.fs", source)) f + compileLibraryAndVerifyILWithOptions options (SourceCodeFileKind.Create(FileNames.TestFs, source)) f static member CompileLibraryAndVerifyDebugInfoWithOptions(options, (expectedFile: string), (source: SourceCodeFileKind)) = compileLibraryAndVerifyDebugInfoWithOptions options expectedFile source static member CompileLibraryAndVerifyDebugInfoWithOptions(options, (expectedFile: string), (source: string)) = - compileLibraryAndVerifyDebugInfoWithOptions options expectedFile (SourceCodeFileKind.Create("test.fs", source)) + compileLibraryAndVerifyDebugInfoWithOptions options expectedFile (SourceCodeFileKind.Create(FileNames.TestFs, source)) static member CompileLibraryAndVerifyIL((source: SourceCodeFileKind), (f: ILVerifier -> unit)) = compileLibraryAndVerifyILWithOptions [||] source f static member CompileLibraryAndVerifyIL((source: string), (f: ILVerifier -> unit)) = - compileLibraryAndVerifyILWithOptions [||] (SourceCodeFileKind.Create("test.fs", source)) f + compileLibraryAndVerifyILWithOptions [||] (SourceCodeFileKind.Create(FileNames.TestFs, source)) f static member CompileLibraryAndVerifyILRealSig((source: string), (f: ILVerifier -> unit)) = - compileLibraryAndVerifyILWithOptions [|"--realsig+"|] (SourceCodeFileKind.Create("test.fs", source)) f + compileLibraryAndVerifyILWithOptions [|"--realsig+"|] (SourceCodeFileKind.Create(FileNames.TestFs, source)) f static member RunScriptWithOptionsAndReturnResult options (source: string) = // Initialize output and input streams @@ -1020,7 +1031,7 @@ Updated automatically, please check diffs in your pull request, changes must be static member Parse (source: string, ?langVersion: string, ?fileName: string) = let langVersion = defaultArg langVersion "default" - let sourceFileName = defaultArg fileName "test.fsx" + let sourceFileName = defaultArg fileName (FileNames.TestFsx) let parsingOptions = { FSharpParsingOptions.Default with SourceFiles = [| sourceFileName |] diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 92256c2b09b..7f2d238394c 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -856,7 +856,7 @@ module Helpers = let internal singleFileChecker source = - let fileName = "test.fs" + let fileName = FileNames.TestFs let getSource _ fileName = FSharpFileSnapshot( diff --git a/tests/FSharp.Test.Utilities/XunitHelpers.fs b/tests/FSharp.Test.Utilities/XunitHelpers.fs index 2747bdc5a63..f9571aa6b1f 100644 --- a/tests/FSharp.Test.Utilities/XunitHelpers.fs +++ b/tests/FSharp.Test.Utilities/XunitHelpers.fs @@ -57,6 +57,7 @@ type ConsoleCapturingTestRunner(test, messageBus, testClass, constructorArgument task { use capture = new TestConsole.ExecutionCapture() use _ = Activity.start test.DisplayName [ ] + FileNames.MakeTestFileNameUniqueForThisTestCase() let! executionTime = this.BaseInvokeTestMethodAsync aggregator let output = seq { diff --git a/tests/fsharp/Compiler/Service/MultiProjectTests.fs b/tests/fsharp/Compiler/Service/MultiProjectTests.fs index 9e89927220d..92913f0c98c 100644 --- a/tests/fsharp/Compiler/Service/MultiProjectTests.fs +++ b/tests/fsharp/Compiler/Service/MultiProjectTests.fs @@ -63,7 +63,7 @@ let test() = """ |> SourceText.ofString let _, checkAnswer = - CompilerAssert.Checker.ParseAndCheckFileInProject("test.fs", 0, fsText, fsOptions) + CompilerAssert.Checker.ParseAndCheckFileInProject(FileNames.TestFs, 0, fsText, fsOptions) |> Async.RunImmediate