@@ -15,7 +15,6 @@ open System.IO
1515
1616open Microsoft.FSharp .Compiler
1717open Microsoft.FSharp .Compiler .SourceCodeServices
18- open Microsoft.FSharp .Compiler .SimpleSourceCodeServices
1918open FSharp.Compiler .Service .Tests
2019open FSharp.Compiler .Service .Tests .Common
2120
@@ -111,7 +110,6 @@ type DebugMode =
111110 | Full
112111
113112let checker = FSharpChecker.Create()
114- let compiler = new SimpleSourceCodeServices()
115113
116114/// Ensures the default FSharp.Core referenced by the F# compiler service (if none is
117115/// provided explicitly) is available in the output directory.
@@ -127,10 +125,10 @@ let ensureDefaultFSharpCoreAvailable tmpDir =
127125 File.Copy( fsCoreDefaultReference(), Path.Combine( tmpDir, Path.GetFileName( fsCoreDefaultReference())), overwrite = true )
128126#endif
129127
130- let compile isDll debugMode ( assemblyName : string ) ( code : string ) ( dependencies : string list ) =
128+ let compile isDll debugMode ( assemblyName : string ) ( ext : string ) ( code : string ) ( dependencies : string list ) =
131129 let tmp = Path.Combine( Path.GetTempPath(), " test" + string( hash ( isDll, debugMode, assemblyName, code, dependencies)))
132130 try Directory.CreateDirectory( tmp) |> ignore with _ -> ()
133- let sourceFile = Path.Combine( tmp, assemblyName + " .fs " )
131+ let sourceFile = Path.Combine( tmp, assemblyName + " ." + ext )
134132 let outFile = Path.Combine( tmp, assemblyName + if isDll then " .dll" else " .exe" )
135133 let pdbFile = Path.Combine( tmp, assemblyName + pdbExtension isDll)
136134 do File.WriteAllText( sourceFile, code)
@@ -164,17 +162,17 @@ let compile isDll debugMode (assemblyName : string) (code : string) (dependencie
164162 ensureDefaultFSharpCoreAvailable tmp
165163
166164 printfn " args: %A " args
167- let errorInfo , id = compiler .Compile args
165+ let errorInfo , id = checker .Compile args
168166 for err in errorInfo do
169167 printfn " error: %A " err
170168 if id <> 0 then raise <| CompilationError( assemblyName, id, errorInfo)
171169 Assert.AreEqual ( errorInfo.Length, 0 )
172170 outFile
173171
174172//sizeof<nativeint>
175- let compileAndVerify isDll debugMode assemblyName code dependencies =
173+ let compileAndVerify isDll debugMode assemblyName ext code dependencies =
176174 let verifier = new PEVerifier ()
177- let outFile = compile isDll debugMode assemblyName code dependencies
175+ let outFile = compile isDll debugMode assemblyName ext code dependencies
178176 verifier.Verify outFile
179177 outFile
180178
@@ -186,7 +184,7 @@ let compileAndVerifyAst (name : string, ast : Ast.ParsedInput list, references :
186184
187185 ensureDefaultFSharpCoreAvailable outDir
188186
189- let errors , id = compiler .Compile( ast, name, outFile, references, executable = false )
187+ let errors , id = checker .Compile( ast, name, outFile, references, executable = false )
190188 for err in errors do printfn " error: %A " err
191189 Assert.AreEqual ( errors.Length, 0 )
192190 if id <> 0 then raise <| CompilationError( name, id, errors)
@@ -225,7 +223,7 @@ module Foo
225223 printfn "done!" // make the code have some initialization effect
226224"""
227225
228- compileAndVerify true PdbOnly " Foo" code [] |> ignore
226+ compileAndVerify true PdbOnly " Foo" " fs " code [] |> ignore
229227
230228[<Test>]
231229let ``3. Simple FSC executable test`` () =
@@ -236,7 +234,7 @@ module Bar
236234 let main _ = printfn "Hello, World!" ; 42
237235
238236"""
239- let outFile = compileAndVerify false PdbOnly " Bar" code []
237+ let outFile = compileAndVerify false PdbOnly " Bar" " fs " code []
240238
241239 use proc = Process.Start( outFile, " " )
242240 proc.WaitForExit()
@@ -295,7 +293,7 @@ module Bar
295293
296294"""
297295 try
298- compile false PdbOnly " Bar" code [] |> ignore
296+ compile false PdbOnly " Bar" " fs " code [] |> ignore
299297 with
300298 | :? CompilationError as exn ->
301299 Assert.AreEqual( 6 , exn.Data2.[ 0 ]. StartLineAlternate)
@@ -307,19 +305,34 @@ let ``Check cols are indexed by 1`` () =
307305 let code = " let x = 1 + a"
308306
309307 try
310- compile false PdbOnly " Foo" code [] |> ignore
308+ compile false PdbOnly " Foo" " fs " code [] |> ignore
311309 with
312310 | :? CompilationError as exn ->
313311 Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " Foo.fs (1,13)-(1,14)" ))
314312 | _ -> failwith " No compilation error"
315313
316314
315+ [<Test>]
316+ let ``Check compile of bad fsx`` () =
317+ let code = """
318+ #load "missing.fsx"
319+ #r "missing.dll"
320+ """
321+
322+ try
323+ compile false PdbOnly " Foo" " fsx" code [] |> ignore
324+ with
325+ | :? CompilationError as exn ->
326+ Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " Could not load file '" ))
327+ Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " missing.fsx" ))
328+ Assert.True( exn.Data2.[ 1 ]. ToString() .Contains( " Could not locate the assembly \" missing.dll\" " ))
329+ | _ -> failwith " No compilation error"
330+
317331
318332#if STRESS
319333// For this stress test the aim is to check if we have a memory leak
320334
321335module StressTest1 =
322- open Microsoft.FSharp .Compiler .SimpleSourceCodeServices
323336 open System.IO
324337
325338 [<Test>]
0 commit comments