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 1/4] 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 From da8f52e592d90258a7a410aa2833d2b00abd0491 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Mon, 10 Feb 2025 20:17:41 +0100 Subject: [PATCH 2/4] Revert "wip - see what breaks" This reverts commit 45abdfb07e243eed3c645667b9199e8d30e7c8c8. --- 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, 26 insertions(+), 47 deletions(-) diff --git a/src/Compiler/Utilities/range.fs b/src/Compiler/Utilities/range.fs index cc1e198deeb..5e13752df0b 100755 --- a/src/Compiler/Utilities/range.fs +++ b/src/Compiler/Utilities/range.fs @@ -193,7 +193,6 @@ 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 | _ -> @@ -204,11 +203,6 @@ 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 ce79ac956ee..d40e5e8d43c 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs @@ -10,7 +10,6 @@ module NameResolutionTests = [] let FieldNotInRecord () = FSharp """ -module Test type A = { Hello:string; World:string } type B = { Size:int; Height:int } type C = { Wheels:int } @@ -23,14 +22,13 @@ let r:F = { Size=3; Height=4; Wall=1 } |> typecheck |> shouldFail |> withDiagnostics [ - (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'") + (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'") ] [] let RecordFieldProposal () = FSharp """ -module Test type A = { Hello:string; World:string } type B = { Size:int; Height:int } type C = { Wheels:int } @@ -43,8 +41,8 @@ let r = { Size=3; Height=4; Wall=1 } |> typecheck |> shouldFail |> withDiagnostics [ - (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'") + (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'") ] let multipleRecdTypeChoiceWarningWith1AlternativeSource = """ diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 6c72adb9d82..c6346cb30f2 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -29,7 +29,6 @@ open TestFramework open System.Runtime.CompilerServices open System.Runtime.InteropServices open FSharp.Compiler.CodeAnalysis -open System.Threading module rec Compiler = @@ -436,19 +435,19 @@ module rec Compiler = } let FsxSourceCode source = - SourceCodeFileKind.Fsx({FileName=FileNames.TestFsx; SourceText=Some source}) + SourceCodeFileKind.Fsx({FileName="test.fsx"; SourceText=Some source}) let Source source = - SourceCodeFileKind.Create(FileNames.TestFs, source) + SourceCodeFileKind.Create("test.fs", source) let SourceFromPath path = SourceCodeFileKind.Create(path) let FsiSource source = - SourceCodeFileKind.Fsi({FileName= FileNames.TestFsi; SourceText=Some source }) + SourceCodeFileKind.Fsi({FileName="test.fsi"; SourceText=Some source }) let FsSource source = - SourceCodeFileKind.Fs({FileName= FileNames.TestFs; SourceText=Some source }) + SourceCodeFileKind.Fs({FileName="test.fs"; SourceText=Some source }) let CsSource source = SourceCodeFileKind.Cs({FileName="test.cs"; SourceText=Some source }) @@ -999,7 +998,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 FileNames.TestFs) source + let (err: FSharpDiagnostic []) = CompilerAssert.TypeCheckWithOptionsAndName options (fsSource.Name |> Option.defaultValue "test.fs") 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 bb67818601f..0f7baf597fb 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -27,17 +27,6 @@ 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 = @@ -418,9 +407,9 @@ module CompilerAssertHelpers = #endif |] { - ProjectFileName = "Z:\\" ++ "test.fsproj" + ProjectFileName = "Z:\\test.fsproj" ProjectId = None - SourceFiles = [| FileNames.TestFs |] + SourceFiles = [|"test.fs"|] OtherOptions = Array.append testDefaults assemblies ReferencedProjects = [||] IsIncompleteTypeCheckEnvironment = false @@ -753,7 +742,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(FileNames.TestFs, 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics) @@ -763,11 +752,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(FileNames.TestFs, 0, SourceText.ofString source, options) |> Async.RunImmediate + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, options) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics) @@ -883,7 +872,7 @@ Updated automatically, please check diffs in your pull request, changes must be let parseResults, fileAnswer = let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( - FileNames.TestFs, + "test.fs", 0, SourceText.ofString source, { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) @@ -943,7 +932,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(FileNames.TestFs, source)) (fun (errors, _, _) -> + compile true options (SourceCodeFileKind.Create("test.fs", source)) (fun (errors, _, _) -> if errors.Length > 0 then Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors)) @@ -951,40 +940,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(FileNames.TestFs, source))) + CompilerAssert.CompileExeWithOptions([||], (SourceCodeFileKind.Create("test.fs", source))) static member CompileExeAndRunWithOptions(options, (source: SourceCodeFileKind)) = compileExeAndRunWithOptions options source static member CompileExeAndRunWithOptions(options, (source: string)) = - compileExeAndRunWithOptions options (SourceCodeFileKind.Create(FileNames.TestFs, source)) + compileExeAndRunWithOptions options (SourceCodeFileKind.Create("test.fs", source)) static member CompileExeAndRun (source: SourceCodeFileKind) = compileExeAndRunWithOptions [||] source static member CompileExeAndRun (source: string) = - compileExeAndRunWithOptions [||] (SourceCodeFileKind.Create(FileNames.TestFs, source)) + compileExeAndRunWithOptions [||] (SourceCodeFileKind.Create("test.fs", 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(FileNames.TestFs, source)) f + compileLibraryAndVerifyILWithOptions options (SourceCodeFileKind.Create("test.fs", 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(FileNames.TestFs, source)) + compileLibraryAndVerifyDebugInfoWithOptions options expectedFile (SourceCodeFileKind.Create("test.fs", source)) static member CompileLibraryAndVerifyIL((source: SourceCodeFileKind), (f: ILVerifier -> unit)) = compileLibraryAndVerifyILWithOptions [||] source f static member CompileLibraryAndVerifyIL((source: string), (f: ILVerifier -> unit)) = - compileLibraryAndVerifyILWithOptions [||] (SourceCodeFileKind.Create(FileNames.TestFs, source)) f + compileLibraryAndVerifyILWithOptions [||] (SourceCodeFileKind.Create("test.fs", source)) f static member CompileLibraryAndVerifyILRealSig((source: string), (f: ILVerifier -> unit)) = - compileLibraryAndVerifyILWithOptions [|"--realsig+"|] (SourceCodeFileKind.Create(FileNames.TestFs, source)) f + compileLibraryAndVerifyILWithOptions [|"--realsig+"|] (SourceCodeFileKind.Create("test.fs", source)) f static member RunScriptWithOptionsAndReturnResult options (source: string) = // Initialize output and input streams @@ -1031,7 +1020,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 (FileNames.TestFsx) + let sourceFileName = defaultArg fileName "test.fsx" let parsingOptions = { FSharpParsingOptions.Default with SourceFiles = [| sourceFileName |] diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 7f2d238394c..92256c2b09b 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 = FileNames.TestFs + let fileName = "test.fs" let getSource _ fileName = FSharpFileSnapshot( diff --git a/tests/FSharp.Test.Utilities/XunitHelpers.fs b/tests/FSharp.Test.Utilities/XunitHelpers.fs index bac836bc03b..ce4d47b9635 100644 --- a/tests/FSharp.Test.Utilities/XunitHelpers.fs +++ b/tests/FSharp.Test.Utilities/XunitHelpers.fs @@ -57,7 +57,6 @@ 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 92913f0c98c..9e89927220d 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(FileNames.TestFs, 0, fsText, fsOptions) + CompilerAssert.Checker.ParseAndCheckFileInProject("test.fs", 0, fsText, fsOptions) |> Async.RunImmediate From 9778e1a644e059249ffe5772448c12dd5c0ee2fb Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Mon, 10 Feb 2025 20:50:21 +0100 Subject: [PATCH 3/4] redo --- tests/FSharp.Test.Utilities/CompilerAssert.fs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 0f7baf597fb..dfe1d75e428 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -309,6 +309,10 @@ and Compilation = module CompilerAssertHelpers = + let uniqueName = + let mutable counter = 0 + fun (ext: string) -> $"test%x{Interlocked.Increment &counter}{ext}" + let UseTransparentCompiler = FSharp.Compiler.CompilerConfig.FSharpExperimentalFeaturesEnabledAutomatically || not (String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEST_TRANSPARENT_COMPILER"))) @@ -407,7 +411,7 @@ module CompilerAssertHelpers = #endif |] { - ProjectFileName = "Z:\\test.fsproj" + ProjectFileName = "Z:\\" ++ uniqueName ".fsproj" ProjectId = None SourceFiles = [|"test.fs"|] OtherOptions = Array.append testDefaults assemblies @@ -742,7 +746,8 @@ 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 path = uniqueName ".fs" + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(path, 0, SourceText.ofString source, defaultProjectOptionsForFilePath path TargetFramework.Current) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics) @@ -756,7 +761,7 @@ Updated automatically, please check diffs in your pull request, changes must be 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(uniqueName ".fs", 0, SourceText.ofString source, options) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics) @@ -826,9 +831,10 @@ Updated automatically, please check diffs in your pull request, changes must be static member TypeCheckWithOptions options (source: string) = let errors = let parseResults, fileAnswer = - let defaultOptions = defaultProjectOptions TargetFramework.Current + let path = uniqueName ".fs" + let defaultOptions = defaultProjectOptionsForFilePath path TargetFramework.Current checker.ParseAndCheckFileInProject( - "test.fs", + path, 0, SourceText.ofString source, { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) @@ -869,10 +875,11 @@ Updated automatically, please check diffs in your pull request, changes must be static member TypeCheckWithErrorsAndOptionsAndAdjust options libAdjust (source: string) expectedTypeErrors = let errors = + let path = uniqueName ".fs" let parseResults, fileAnswer = - let defaultOptions = defaultProjectOptions TargetFramework.Current + let defaultOptions = defaultProjectOptionsForFilePath path TargetFramework.Current checker.ParseAndCheckFileInProject( - "test.fs", + path, 0, SourceText.ofString source, { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) @@ -1020,7 +1027,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 (uniqueName ".fsx") let parsingOptions = { FSharpParsingOptions.Default with SourceFiles = [| sourceFileName |] From e93d85f03eeb4540d188276913c47f5771e45887 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Mon, 10 Feb 2025 21:46:50 +0100 Subject: [PATCH 4/4] missed a case --- tests/FSharp.Test.Utilities/CompilerAssert.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index dfe1d75e428..7d3cec64f4f 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -758,10 +758,11 @@ Updated automatically, please check diffs in your pull request, changes must be Assert.Empty(typeCheckResults.Diagnostics) static member PassWithOptions options (source: string) = - let defaultOptions = defaultProjectOptions TargetFramework.Current + let path = uniqueName ".fs" + let defaultOptions = defaultProjectOptionsForFilePath path TargetFramework.Current let options = { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions} - let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(uniqueName ".fs", 0, SourceText.ofString source, options) |> Async.RunImmediate + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(path, 0, SourceText.ofString source, options) |> Async.RunImmediate Assert.Empty(parseResults.Diagnostics)