Skip to content

Commit 45abdfb

Browse files
committed
wip - see what breaks
1 parent b64ea2b commit 45abdfb

File tree

7 files changed

+47
-26
lines changed

7 files changed

+47
-26
lines changed

src/Compiler/Utilities/range.fs

+6
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ type FileIndexTable() =
193193
//
194194
// TO move forward we should eventually introduce a new type NormalizedFileName that tracks this invariant.
195195
member t.FileToIndex normalize filePath =
196+
196197
match fileToIndexTable.TryGetValue filePath with
197198
| true, idx -> idx
198199
| _ ->
@@ -203,6 +204,11 @@ type FileIndexTable() =
203204
else
204205
filePath
205206

207+
208+
//match normalizedFilePath with
209+
//| "test.fs" | "test.fsx" | "test.fsi" -> failwith "FileToIndex naked test file"
210+
//| _ -> ()
211+
206212
match fileToIndexTable.TryGetValue normalizedFilePath with
207213
| true, idx ->
208214
// Record the non-normalized entry if necessary

tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module NameResolutionTests =
1010
[<Fact>]
1111
let FieldNotInRecord () =
1212
FSharp """
13+
module Test
1314
type A = { Hello:string; World:string }
1415
type B = { Size:int; Height:int }
1516
type C = { Wheels:int }
@@ -22,13 +23,14 @@ let r:F = { Size=3; Height=4; Wall=1 }
2223
|> typecheck
2324
|> shouldFail
2425
|> withDiagnostics [
25-
(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")
26-
(Error 764, Line 9, Col 11, Line 9, Col 39, "No assignment given for field 'Wallis' of type 'Test.F'")
26+
(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")
27+
(Error 764, Line 10, Col 11, Line 10, Col 39, "No assignment given for field 'Wallis' of type 'Test.F'")
2728
]
2829

2930
[<Fact>]
3031
let RecordFieldProposal () =
3132
FSharp """
33+
module Test
3234
type A = { Hello:string; World:string }
3335
type B = { Size:int; Height:int }
3436
type C = { Wheels:int }
@@ -41,8 +43,8 @@ let r = { Size=3; Height=4; Wall=1 }
4143
|> typecheck
4244
|> shouldFail
4345
|> withDiagnostics [
44-
(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")
45-
(Error 764, Line 9, Col 9, Line 9, Col 37, "No assignment given for field 'Wallis' of type 'Test.F'")
46+
(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")
47+
(Error 764, Line 10, Col 9, Line 10, Col 37, "No assignment given for field 'Wallis' of type 'Test.F'")
4648
]
4749

4850
let multipleRecdTypeChoiceWarningWith1AlternativeSource = """

tests/FSharp.Test.Utilities/Compiler.fs

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ open TestFramework
2929
open System.Runtime.CompilerServices
3030
open System.Runtime.InteropServices
3131
open FSharp.Compiler.CodeAnalysis
32+
open System.Threading
3233

3334
module rec Compiler =
3435

@@ -435,19 +436,19 @@ module rec Compiler =
435436
}
436437

437438
let FsxSourceCode source =
438-
SourceCodeFileKind.Fsx({FileName="test.fsx"; SourceText=Some source})
439+
SourceCodeFileKind.Fsx({FileName=FileNames.TestFsx; SourceText=Some source})
439440

440441
let Source source =
441-
SourceCodeFileKind.Create("test.fs", source)
442+
SourceCodeFileKind.Create(FileNames.TestFs, source)
442443

443444
let SourceFromPath path =
444445
SourceCodeFileKind.Create(path)
445446

446447
let FsiSource source =
447-
SourceCodeFileKind.Fsi({FileName="test.fsi"; SourceText=Some source })
448+
SourceCodeFileKind.Fsi({FileName= FileNames.TestFsi; SourceText=Some source })
448449

449450
let FsSource source =
450-
SourceCodeFileKind.Fs({FileName="test.fs"; SourceText=Some source })
451+
SourceCodeFileKind.Fs({FileName= FileNames.TestFs; SourceText=Some source })
451452

452453
let CsSource source =
453454
SourceCodeFileKind.Cs({FileName="test.cs"; SourceText=Some source })
@@ -998,7 +999,7 @@ module rec Compiler =
998999
| None -> File.ReadAllText(fsSource.Source.GetSourceFileName)
9991000
| Some text -> text
10001001
let options = fsSource.Options |> Array.ofList
1001-
let (err: FSharpDiagnostic []) = CompilerAssert.TypeCheckWithOptionsAndName options (fsSource.Name |> Option.defaultValue "test.fs") source
1002+
let (err: FSharpDiagnostic []) = CompilerAssert.TypeCheckWithOptionsAndName options (fsSource.Name |> Option.defaultValue FileNames.TestFs) source
10021003
err
10031004

10041005
let private typecheckFSharpSource (fsSource: FSharpCompilationSource) : CompilationResult =

tests/FSharp.Test.Utilities/CompilerAssert.fs

+26-15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ open Xunit
2727
open TestFramework
2828
open System.Collections.Immutable
2929

30+
type FileNames =
31+
static let testFileName = AsyncLocal<string>()
32+
static let mutable counter = 0
33+
//static do testFileName.Value <- "test"
34+
static member internal MakeTestFileNameUniqueForThisTestCase() =
35+
testFileName.Value <- $"{Interlocked.Increment &counter}{Path.PathSeparator}test"
36+
37+
static member TestFs with get() = $"{testFileName.Value}.fs"
38+
static member TestFsx with get() = $"{testFileName.Value}.fsx"
39+
static member TestFsi with get() = $"{testFileName.Value}.fsi"
40+
static member Test with get() = testFileName.Value
3041

3142
#if !NETCOREAPP
3243
module AssemblyResolver =
@@ -407,9 +418,9 @@ module CompilerAssertHelpers =
407418
#endif
408419
|]
409420
{
410-
ProjectFileName = "Z:\\test.fsproj"
421+
ProjectFileName = "Z:\\" ++ "test.fsproj"
411422
ProjectId = None
412-
SourceFiles = [|"test.fs"|]
423+
SourceFiles = [| FileNames.TestFs |]
413424
OtherOptions = Array.append testDefaults assemblies
414425
ReferencedProjects = [||]
415426
IsIncompleteTypeCheckEnvironment = false
@@ -742,7 +753,7 @@ Updated automatically, please check diffs in your pull request, changes must be
742753
Assert.Equal(expectedOutput, output)
743754

744755
static member Pass (source: string) =
745-
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate
756+
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(FileNames.TestFs, 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate
746757

747758
Assert.Empty(parseResults.Diagnostics)
748759

@@ -752,11 +763,11 @@ Updated automatically, please check diffs in your pull request, changes must be
752763

753764
Assert.Empty(typeCheckResults.Diagnostics)
754765

755-
static member PassWithOptions options (source: string) =
766+
static member PassWithOptions options (source: string) =
756767
let defaultOptions = defaultProjectOptions TargetFramework.Current
757768
let options = { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}
758769

759-
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, options) |> Async.RunImmediate
770+
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject(FileNames.TestFs, 0, SourceText.ofString source, options) |> Async.RunImmediate
760771

761772
Assert.Empty(parseResults.Diagnostics)
762773

@@ -872,7 +883,7 @@ Updated automatically, please check diffs in your pull request, changes must be
872883
let parseResults, fileAnswer =
873884
let defaultOptions = defaultProjectOptions TargetFramework.Current
874885
checker.ParseAndCheckFileInProject(
875-
"test.fs",
886+
FileNames.TestFs,
876887
0,
877888
SourceText.ofString source,
878889
{ defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions})
@@ -932,48 +943,48 @@ Updated automatically, please check diffs in your pull request, changes must be
932943
Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors))
933944

934945
static member CompileExeWithOptions(options, (source: string)) =
935-
compile true options (SourceCodeFileKind.Create("test.fs", source)) (fun (errors, _, _) ->
946+
compile true options (SourceCodeFileKind.Create(FileNames.TestFs, source)) (fun (errors, _, _) ->
936947
if errors.Length > 0 then
937948
Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors))
938949

939950
static member CompileExe (source: SourceCodeFileKind) =
940951
CompilerAssert.CompileExeWithOptions([||], source)
941952

942953
static member CompileExe (source: string) =
943-
CompilerAssert.CompileExeWithOptions([||], (SourceCodeFileKind.Create("test.fs", source)))
954+
CompilerAssert.CompileExeWithOptions([||], (SourceCodeFileKind.Create(FileNames.TestFs, source)))
944955

945956
static member CompileExeAndRunWithOptions(options, (source: SourceCodeFileKind)) =
946957
compileExeAndRunWithOptions options source
947958

948959
static member CompileExeAndRunWithOptions(options, (source: string)) =
949-
compileExeAndRunWithOptions options (SourceCodeFileKind.Create("test.fs", source))
960+
compileExeAndRunWithOptions options (SourceCodeFileKind.Create(FileNames.TestFs, source))
950961

951962
static member CompileExeAndRun (source: SourceCodeFileKind) =
952963
compileExeAndRunWithOptions [||] source
953964

954965
static member CompileExeAndRun (source: string) =
955-
compileExeAndRunWithOptions [||] (SourceCodeFileKind.Create("test.fs", source))
966+
compileExeAndRunWithOptions [||] (SourceCodeFileKind.Create(FileNames.TestFs, source))
956967

957968
static member CompileLibraryAndVerifyILWithOptions(options, (source: SourceCodeFileKind), (f: ILVerifier -> unit)) =
958969
compileLibraryAndVerifyILWithOptions options source f
959970

960971
static member CompileLibraryAndVerifyILWithOptions(options, (source: string), (f: ILVerifier -> unit)) =
961-
compileLibraryAndVerifyILWithOptions options (SourceCodeFileKind.Create("test.fs", source)) f
972+
compileLibraryAndVerifyILWithOptions options (SourceCodeFileKind.Create(FileNames.TestFs, source)) f
962973

963974
static member CompileLibraryAndVerifyDebugInfoWithOptions(options, (expectedFile: string), (source: SourceCodeFileKind)) =
964975
compileLibraryAndVerifyDebugInfoWithOptions options expectedFile source
965976

966977
static member CompileLibraryAndVerifyDebugInfoWithOptions(options, (expectedFile: string), (source: string)) =
967-
compileLibraryAndVerifyDebugInfoWithOptions options expectedFile (SourceCodeFileKind.Create("test.fs", source))
978+
compileLibraryAndVerifyDebugInfoWithOptions options expectedFile (SourceCodeFileKind.Create(FileNames.TestFs, source))
968979

969980
static member CompileLibraryAndVerifyIL((source: SourceCodeFileKind), (f: ILVerifier -> unit)) =
970981
compileLibraryAndVerifyILWithOptions [||] source f
971982

972983
static member CompileLibraryAndVerifyIL((source: string), (f: ILVerifier -> unit)) =
973-
compileLibraryAndVerifyILWithOptions [||] (SourceCodeFileKind.Create("test.fs", source)) f
984+
compileLibraryAndVerifyILWithOptions [||] (SourceCodeFileKind.Create(FileNames.TestFs, source)) f
974985

975986
static member CompileLibraryAndVerifyILRealSig((source: string), (f: ILVerifier -> unit)) =
976-
compileLibraryAndVerifyILWithOptions [|"--realsig+"|] (SourceCodeFileKind.Create("test.fs", source)) f
987+
compileLibraryAndVerifyILWithOptions [|"--realsig+"|] (SourceCodeFileKind.Create(FileNames.TestFs, source)) f
977988

978989
static member RunScriptWithOptionsAndReturnResult options (source: string) =
979990
// Initialize output and input streams
@@ -1020,7 +1031,7 @@ Updated automatically, please check diffs in your pull request, changes must be
10201031

10211032
static member Parse (source: string, ?langVersion: string, ?fileName: string) =
10221033
let langVersion = defaultArg langVersion "default"
1023-
let sourceFileName = defaultArg fileName "test.fsx"
1034+
let sourceFileName = defaultArg fileName (FileNames.TestFsx)
10241035
let parsingOptions =
10251036
{ FSharpParsingOptions.Default with
10261037
SourceFiles = [| sourceFileName |]

tests/FSharp.Test.Utilities/ProjectGeneration.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ module Helpers =
856856

857857
let internal singleFileChecker source =
858858

859-
let fileName = "test.fs"
859+
let fileName = FileNames.TestFs
860860

861861
let getSource _ fileName =
862862
FSharpFileSnapshot(

tests/FSharp.Test.Utilities/XunitHelpers.fs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type ConsoleCapturingTestRunner(test, messageBus, testClass, constructorArgument
5757
task {
5858
use capture = new TestConsole.ExecutionCapture()
5959
use _ = Activity.start test.DisplayName [ ]
60+
FileNames.MakeTestFileNameUniqueForThisTestCase()
6061
let! executionTime = this.BaseInvokeTestMethodAsync aggregator
6162
let output =
6263
seq {

tests/fsharp/Compiler/Service/MultiProjectTests.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ let test() =
6363
"""
6464
|> SourceText.ofString
6565
let _, checkAnswer =
66-
CompilerAssert.Checker.ParseAndCheckFileInProject("test.fs", 0, fsText, fsOptions)
66+
CompilerAssert.Checker.ParseAndCheckFileInProject(FileNames.TestFs, 0, fsText, fsOptions)
6767
|> Async.RunImmediate
6868

6969

0 commit comments

Comments
 (0)