@@ -15,7 +15,6 @@ open System.IO
15
15
16
16
open Microsoft.FSharp .Compiler
17
17
open Microsoft.FSharp .Compiler .SourceCodeServices
18
- open Microsoft.FSharp .Compiler .SimpleSourceCodeServices
19
18
open FSharp.Compiler .Service .Tests
20
19
open FSharp.Compiler .Service .Tests .Common
21
20
@@ -111,7 +110,6 @@ type DebugMode =
111
110
| Full
112
111
113
112
let checker = FSharpChecker.Create()
114
- let compiler = new SimpleSourceCodeServices()
115
113
116
114
/// Ensures the default FSharp.Core referenced by the F# compiler service (if none is
117
115
/// provided explicitly) is available in the output directory.
@@ -127,10 +125,10 @@ let ensureDefaultFSharpCoreAvailable tmpDir =
127
125
File.Copy( fsCoreDefaultReference(), Path.Combine( tmpDir, Path.GetFileName( fsCoreDefaultReference())), overwrite = true )
128
126
#endif
129
127
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 ) =
131
129
let tmp = Path.Combine( Path.GetTempPath(), " test" + string( hash ( isDll, debugMode, assemblyName, code, dependencies)))
132
130
try Directory.CreateDirectory( tmp) |> ignore with _ -> ()
133
- let sourceFile = Path.Combine( tmp, assemblyName + " .fs " )
131
+ let sourceFile = Path.Combine( tmp, assemblyName + " ." + ext )
134
132
let outFile = Path.Combine( tmp, assemblyName + if isDll then " .dll" else " .exe" )
135
133
let pdbFile = Path.Combine( tmp, assemblyName + pdbExtension isDll)
136
134
do File.WriteAllText( sourceFile, code)
@@ -164,17 +162,17 @@ let compile isDll debugMode (assemblyName : string) (code : string) (dependencie
164
162
ensureDefaultFSharpCoreAvailable tmp
165
163
166
164
printfn " args: %A " args
167
- let errorInfo , id = compiler .Compile args
165
+ let errorInfo , id = checker .Compile args
168
166
for err in errorInfo do
169
167
printfn " error: %A " err
170
168
if id <> 0 then raise <| CompilationError( assemblyName, id, errorInfo)
171
169
Assert.AreEqual ( errorInfo.Length, 0 )
172
170
outFile
173
171
174
172
//sizeof<nativeint>
175
- let compileAndVerify isDll debugMode assemblyName code dependencies =
173
+ let compileAndVerify isDll debugMode assemblyName ext code dependencies =
176
174
let verifier = new PEVerifier ()
177
- let outFile = compile isDll debugMode assemblyName code dependencies
175
+ let outFile = compile isDll debugMode assemblyName ext code dependencies
178
176
verifier.Verify outFile
179
177
outFile
180
178
@@ -186,7 +184,7 @@ let compileAndVerifyAst (name : string, ast : Ast.ParsedInput list, references :
186
184
187
185
ensureDefaultFSharpCoreAvailable outDir
188
186
189
- let errors , id = compiler .Compile( ast, name, outFile, references, executable = false )
187
+ let errors , id = checker .Compile( ast, name, outFile, references, executable = false )
190
188
for err in errors do printfn " error: %A " err
191
189
Assert.AreEqual ( errors.Length, 0 )
192
190
if id <> 0 then raise <| CompilationError( name, id, errors)
@@ -225,7 +223,7 @@ module Foo
225
223
printfn "done!" // make the code have some initialization effect
226
224
"""
227
225
228
- compileAndVerify true PdbOnly " Foo" code [] |> ignore
226
+ compileAndVerify true PdbOnly " Foo" " fs " code [] |> ignore
229
227
230
228
[<Test>]
231
229
let ``3. Simple FSC executable test`` () =
@@ -236,7 +234,7 @@ module Bar
236
234
let main _ = printfn "Hello, World!" ; 42
237
235
238
236
"""
239
- let outFile = compileAndVerify false PdbOnly " Bar" code []
237
+ let outFile = compileAndVerify false PdbOnly " Bar" " fs " code []
240
238
241
239
use proc = Process.Start( outFile, " " )
242
240
proc.WaitForExit()
@@ -295,7 +293,7 @@ module Bar
295
293
296
294
"""
297
295
try
298
- compile false PdbOnly " Bar" code [] |> ignore
296
+ compile false PdbOnly " Bar" " fs " code [] |> ignore
299
297
with
300
298
| :? CompilationError as exn ->
301
299
Assert.AreEqual( 6 , exn.Data2.[ 0 ]. StartLineAlternate)
@@ -307,19 +305,34 @@ let ``Check cols are indexed by 1`` () =
307
305
let code = " let x = 1 + a"
308
306
309
307
try
310
- compile false PdbOnly " Foo" code [] |> ignore
308
+ compile false PdbOnly " Foo" " fs " code [] |> ignore
311
309
with
312
310
| :? CompilationError as exn ->
313
311
Assert.True( exn.Data2.[ 0 ]. ToString() .Contains( " Foo.fs (1,13)-(1,14)" ))
314
312
| _ -> failwith " No compilation error"
315
313
316
314
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
+
317
331
318
332
#if STRESS
319
333
// For this stress test the aim is to check if we have a memory leak
320
334
321
335
module StressTest1 =
322
- open Microsoft.FSharp .Compiler .SimpleSourceCodeServices
323
336
open System.IO
324
337
325
338
[<Test>]
0 commit comments