@@ -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 ) ( extraArgs : 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)
@@ -158,23 +156,26 @@ let compile isDll debugMode (assemblyName : string) (code : string) (dependencie
158156
159157 yield sprintf " --out:%s " outFile
160158
159+ yield ! extraArgs
160+
161161 yield sourceFile
162+
162163 |]
163164
164165 ensureDefaultFSharpCoreAvailable tmp
165166
166167 printfn " args: %A " args
167- let errorInfo , id = compiler .Compile args
168+ let errorInfo , id = checker .Compile args
168169 for err in errorInfo do
169170 printfn " error: %A " err
170171 if id <> 0 then raise <| CompilationError( assemblyName, id, errorInfo)
171172 Assert.AreEqual ( errorInfo.Length, 0 )
172173 outFile
173174
174175//sizeof<nativeint>
175- let compileAndVerify isDll debugMode assemblyName code dependencies =
176+ let compileAndVerify isDll debugMode assemblyName ext code dependencies =
176177 let verifier = new PEVerifier ()
177- let outFile = compile isDll debugMode assemblyName code dependencies
178+ let outFile = compile isDll debugMode assemblyName ext code dependencies []
178179 verifier.Verify outFile
179180 outFile
180181
@@ -186,7 +187,7 @@ let compileAndVerifyAst (name : string, ast : Ast.ParsedInput list, references :
186187
187188 ensureDefaultFSharpCoreAvailable outDir
188189
189- let errors , id = compiler .Compile( ast, name, outFile, references, executable = false )
190+ let errors , id = checker .Compile( ast, name, outFile, references, executable = false )
190191 for err in errors do printfn " error: %A " err
191192 Assert.AreEqual ( errors.Length, 0 )
192193 if id <> 0 then raise <| CompilationError( name, id, errors)
@@ -225,7 +226,7 @@ module Foo
225226 printfn "done!" // make the code have some initialization effect
226227"""
227228
228- compileAndVerify true PdbOnly " Foo" code [] |> ignore
229+ compileAndVerify true PdbOnly " Foo" " fs " code [] |> ignore
229230
230231[<Test>]
231232let ``3. Simple FSC executable test`` () =
@@ -236,7 +237,7 @@ module Bar
236237 let main _ = printfn "Hello, World!" ; 42
237238
238239"""
239- let outFile = compileAndVerify false PdbOnly " Bar" code []
240+ let outFile = compileAndVerify false PdbOnly " Bar" " fs " code []
240241
241242 use proc = Process.Start( outFile, " " )
242243 proc.WaitForExit()
@@ -295,7 +296,8 @@ module Bar
295296
296297"""
297298 try
298- compile false PdbOnly " Bar" code [] |> ignore
299+ let outFile : string = compile false PdbOnly " Bar" " fs" code [] []
300+ ()
299301 with
300302 | :? CompilationError as exn ->
301303 Assert.AreEqual( 6 , exn.Data2.[ 0 ]. StartLineAlternate)
@@ -307,19 +309,51 @@ let ``Check cols are indexed by 1`` () =
307309 let code = " let x = 1 + a"
308310
309311 try
310- compile false PdbOnly " Foo" code [] |> ignore
312+ let outFile : string = compile false PdbOnly " Foo" " fs" code [] []
313+ ()
311314 with
312315 | :? CompilationError as exn ->
313316 Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " Foo.fs (1,13)-(1,14)" ))
314317 | _ -> failwith " No compilation error"
315318
316319
320+ [<Test>]
321+ let ``Check compile of bad fsx`` () =
322+ let code = """
323+ #load "missing.fsx"
324+ #r "missing.dll"
325+ """
326+
327+ try
328+ let outFile : string = compile false PdbOnly " Foo" " fsx" code [] []
329+ ()
330+ with
331+ | :? CompilationError as exn ->
332+ Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " Could not load file '" ))
333+ Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " missing.fsx" ))
334+ Assert.True( exn.Data2.[ 1 ]. ToString() .Contains( " Could not locate the assembly \" missing.dll\" " ))
335+ | _ -> failwith " No compilation error"
336+
337+
338+ [<Test>]
339+ let ``Check compile of good fsx with bad option`` () =
340+ let code = """
341+ let x = 1
342+ """
343+
344+ try
345+ let outFile : string = compile false PdbOnly " Foo" " fsx" code [] [ " -r:missing.dll" ]
346+ ()
347+ with
348+ | :? CompilationError as exn ->
349+ Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " startup (1,1)-(1,81) parameter error Could not resolve this reference" ))
350+ | _ -> failwith " No compilation error"
351+
317352
318353#if STRESS
319354// For this stress test the aim is to check if we have a memory leak
320355
321356module StressTest1 =
322- open Microsoft.FSharp .Compiler .SimpleSourceCodeServices
323357 open System.IO
324358
325359 [<Test>]
@@ -335,7 +369,8 @@ type C() =
335369let x = 3 + 4
336370"""
337371
338- compile true PdbOnly " Foo" code [] |> ignore
372+ let outFile : string = compile true PdbOnly " Foo" " fs" code [] []
373+ ()
339374
340375#endif
341376
0 commit comments