Skip to content

Commit c55cd55

Browse files
Add more tests and improve fix
1 parent 5a53f24 commit c55cd55

File tree

13 files changed

+73
-47
lines changed

13 files changed

+73
-47
lines changed

src/fsharp/CompileOps.fs

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4962,38 +4962,32 @@ module private ScriptPreprocessClosure =
49624962
match closureDirective with
49634963
| ClosedSourceFile _ as csf -> [csf]
49644964
| SourceFile(filename,m,source) ->
4965-
let filename = FileSystem.GetFullPathShim(filename)
4966-
if observedSources.HaveSeen(filename) then []
4967-
else
4968-
observedSources.SetSeen(filename)
4969-
4970-
let errors = ref []
4971-
let warnings = ref []
4972-
let errorLogger =
4973-
{ new ErrorLogger("FindClosure") with
4974-
member x.ErrorSinkImpl(e) = errors := e :: !errors
4975-
member x.WarnSinkImpl(e) = warnings := e :: !warnings
4976-
member x.ErrorCount = (!errors).Length }
4977-
4978-
use unwindEL = PushErrorLoggerPhaseUntilUnwind (fun _ -> errorLogger)
4979-
let pathOfMetaCommandSource = Path.GetDirectoryName(filename)
4980-
match ParseScriptText(filename,source,!tcConfig,codeContext,lexResourceManager,errorLogger) with
4981-
| Some(input) ->
4982-
let tcConfigResult, noWarns = ApplyMetaCommandsFromInputToTcConfigAndGatherNoWarn !tcConfig (input,pathOfMetaCommandSource)
4983-
tcConfig := tcConfigResult
4965+
let errors = ref []
4966+
let warnings = ref []
4967+
let errorLogger =
4968+
{ new ErrorLogger("FindClosure") with
4969+
member x.ErrorSinkImpl(e) = errors := e :: !errors
4970+
member x.WarnSinkImpl(e) = warnings := e :: !warnings
4971+
member x.ErrorCount = (!errors).Length }
4972+
4973+
use unwindEL = PushErrorLoggerPhaseUntilUnwind (fun _ -> errorLogger)
4974+
let pathOfMetaCommandSource = Path.GetDirectoryName(filename)
4975+
match ParseScriptText(filename,source,!tcConfig,codeContext,lexResourceManager,errorLogger) with
4976+
| Some(input) ->
4977+
let tcConfigResult, noWarns = ApplyMetaCommandsFromInputToTcConfigAndGatherNoWarn !tcConfig (input,pathOfMetaCommandSource)
4978+
tcConfig := tcConfigResult
49844979

4985-
let AddFileIfNotSeen(m,filename) =
4986-
if observedSources.HaveSeen(filename) then []
4987-
else
4988-
if IsScript(filename) then SourceFileOfFilename(filename,m,tcConfigResult.inputCodePage)
4989-
else
4990-
observedSources.SetSeen(filename)
4991-
[ClosedSourceFile(filename,m,None,[],[],[])] // Don't traverse into .fs leafs.
4980+
let AddFileIfNotSeen(m,filename) =
4981+
if observedSources.HaveSeen(filename) then []
4982+
else
4983+
observedSources.SetSeen(filename)
4984+
if IsScript(filename) then SourceFileOfFilename(filename,m,tcConfigResult.inputCodePage)
4985+
else [ClosedSourceFile(filename,m,None,[],[],[])] // Don't traverse into .fs leafs.
49924986

4993-
let loadedSources = (!tcConfig).GetAvailableLoadedSources() |> List.rev |> List.map AddFileIfNotSeen |> List.concat
4994-
(loadedSources |> List.map FindClosure |> List.concat)
4995-
@ [ClosedSourceFile(filename,m,Some(input),!errors,!warnings,!noWarns)]
4996-
| None -> [ClosedSourceFile(filename,m,None,!errors,!warnings,[])]
4987+
let loadedSources = (!tcConfig).GetAvailableLoadedSources() |> List.map AddFileIfNotSeen |> List.concat
4988+
(loadedSources |> List.map FindClosure |> List.concat)
4989+
@ [ClosedSourceFile(filename,m,Some(input),!errors,!warnings,!noWarns)]
4990+
| None -> [ClosedSourceFile(filename,m,None,!errors,!warnings,[])]
49974991

49984992
closureDirectives |> List.map FindClosure |> List.concat, !tcConfig
49994993

@@ -5011,7 +5005,7 @@ module private ScriptPreprocessClosure =
50115005
let sourceFiles = ref []
50125006
let sourceInputs = ref []
50135007
let globalNoWarns = ref []
5014-
for directive in closureDirectives do
5008+
for directive in List.rev closureDirectives do
50155009
match directive with
50165010
| ClosedSourceFile(filename,m,input,_,_,noWarns) ->
50175011
let filename = FileSystem.GetFullPathShim(filename)
@@ -5054,8 +5048,8 @@ module private ScriptPreprocessClosure =
50545048
let rootWarnings = rootWarnings |> List.filter isRootRange
50555049

50565050
let result : LoadClosure =
5057-
{ SourceFiles = List.groupByFirst !sourceFiles |> List.rev
5058-
References = List.groupByFirst references |> List.rev
5051+
{ SourceFiles = List.groupByFirst !sourceFiles
5052+
References = List.groupByFirst references
50595053
UnresolvedReferences = unresolvedReferences
50605054
Inputs = !sourceInputs
50615055
NoWarns = List.groupByFirst !globalNoWarns

tests/service/ProjectOptionsTests.fs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,20 @@ let ``Project file parsing -- report files``() =
420420

421421
[<Test>]
422422
let ``Test ProjectFileNames order for GetProjectOptionsFromScript`` () = // See #594
423-
let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/Main.fsx"
424-
let scriptSource = File.ReadAllText scriptPath
425-
let projOpts =
426-
checker.GetProjectOptionsFromScript(scriptPath, scriptSource)
427-
|> Async.RunSynchronously
428-
projOpts.ProjectFileNames
429-
|> Array.map Path.GetFileNameWithoutExtension
430-
|> (=) [|"BaseLib"; "Lib1"; "Lib2"; "Main"|]
431-
|> shouldEqual true
423+
let test scriptName expected =
424+
let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/" + scriptName + ".fsx"
425+
let scriptSource = File.ReadAllText scriptPath
426+
let projOpts =
427+
checker.GetProjectOptionsFromScript(scriptPath, scriptSource)
428+
|> Async.RunSynchronously
429+
projOpts.ProjectFileNames
430+
|> Array.map Path.GetFileNameWithoutExtension
431+
|> (=) expected
432+
|> shouldEqual true
433+
test "Main1" [|"BaseLib1"; "Lib1"; "Lib2"; "Main1"|]
434+
test "Main2" [|"BaseLib1"; "Lib1"; "Lib2"; "Lib3"; "Main2"|]
435+
test "Main3" [|"Lib3"; "Lib4"; "Main3"|]
436+
test "Main4" [|"BaseLib2"; "Lib5"; "BaseLib1"; "Lib1"; "Lib2"; "Main4"|]
432437

433438
#endif
434439

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module BaseLib
1+
module BaseLib1
22

33
let add2 x = x + 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module BaseLib2
2+
3+
let add10 x = x + 10
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#load "BaseLib.fs"
2-
let add3 = BaseLib.add2 >> ((+) 1)
1+
#load "BaseLib1.fs"
2+
let add3 = BaseLib1.add2 >> ((+) 1)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#load "BaseLib.fs"
2-
let add4 = BaseLib.add2 >> ((+) 2)
1+
#load "BaseLib1.fs"
2+
let add4 = BaseLib1.add2 >> ((+) 2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Lib3
2+
3+
let add6 = ((+) 6)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Lib4
2+
3+
let add8 = ((+) 8)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#load "BaseLib2.fs"
2+
let add12 = BaseLib2.add10 >> ((+) 2)

0 commit comments

Comments
 (0)