Skip to content

Commit

Permalink
wip - see what breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
majocha committed Feb 10, 2025
1 parent b64ea2b commit 45abdfb
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/Compiler/Utilities/range.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
| _ ->
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module NameResolutionTests =
[<Fact>]
let FieldNotInRecord () =
FSharp """
module Test
type A = { Hello:string; World:string }
type B = { Size:int; Height:int }
type C = { Wheels:int }
Expand All @@ -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'")
]

[<Fact>]
let RecordFieldProposal () =
FSharp """
module Test
type A = { Hello:string; World:string }
type B = { Size:int; Height:int }
type C = { Wheels:int }
Expand All @@ -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 = """
Expand Down
11 changes: 6 additions & 5 deletions tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open TestFramework
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
open FSharp.Compiler.CodeAnalysis
open System.Threading

module rec Compiler =

Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 =
Expand Down
41 changes: 26 additions & 15 deletions tests/FSharp.Test.Utilities/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ open Xunit
open TestFramework
open System.Collections.Immutable

type FileNames =
static let testFileName = AsyncLocal<string>()
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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -932,48 +943,48 @@ 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))

static member CompileExe (source: SourceCodeFileKind) =
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
Expand Down Expand Up @@ -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 |]
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.Test.Utilities/ProjectGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ module Helpers =

let internal singleFileChecker source =

let fileName = "test.fs"
let fileName = FileNames.TestFs

let getSource _ fileName =
FSharpFileSnapshot(
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Test.Utilities/XunitHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/Compiler/Service/MultiProjectTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 45abdfb

Please sign in to comment.