Skip to content

Commit 07e4344

Browse files
dsymedsyme
authored andcommitted
more testing
1 parent 75ab724 commit 07e4344

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

tests/service/FscTests.fs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let ensureDefaultFSharpCoreAvailable tmpDir =
125125
File.Copy(fsCoreDefaultReference(), Path.Combine(tmpDir, Path.GetFileName(fsCoreDefaultReference())), overwrite = true)
126126
#endif
127127

128-
let compile isDll debugMode (assemblyName : string) (ext: string) (code : string) (dependencies : string list) =
128+
let compile isDll debugMode (assemblyName : string) (ext: string) (code : string) (dependencies : string list) (extraArgs: string list) =
129129
let tmp = Path.Combine(Path.GetTempPath(),"test"+string(hash (isDll,debugMode,assemblyName,code,dependencies)))
130130
try Directory.CreateDirectory(tmp) |> ignore with _ -> ()
131131
let sourceFile = Path.Combine(tmp, assemblyName + "." + ext)
@@ -156,7 +156,10 @@ let compile isDll debugMode (assemblyName : string) (ext: string) (code : string
156156

157157
yield sprintf "--out:%s" outFile
158158

159+
yield! extraArgs
160+
159161
yield sourceFile
162+
160163
|]
161164

162165
ensureDefaultFSharpCoreAvailable tmp
@@ -172,7 +175,7 @@ let compile isDll debugMode (assemblyName : string) (ext: string) (code : string
172175
//sizeof<nativeint>
173176
let compileAndVerify isDll debugMode assemblyName ext code dependencies =
174177
let verifier = new PEVerifier ()
175-
let outFile = compile isDll debugMode assemblyName ext code dependencies
178+
let outFile = compile isDll debugMode assemblyName ext code dependencies []
176179
verifier.Verify outFile
177180
outFile
178181

@@ -293,7 +296,8 @@ module Bar
293296
294297
"""
295298
try
296-
compile false PdbOnly "Bar" "fs" code [] |> ignore
299+
let outFile : string = compile false PdbOnly "Bar" "fs" code [] []
300+
()
297301
with
298302
| :? CompilationError as exn ->
299303
Assert.AreEqual(6,exn.Data2.[0].StartLineAlternate)
@@ -305,7 +309,8 @@ let ``Check cols are indexed by 1`` () =
305309
let code = "let x = 1 + a"
306310

307311
try
308-
compile false PdbOnly "Foo" "fs" code [] |> ignore
312+
let outFile : string = compile false PdbOnly "Foo" "fs" code [] []
313+
()
309314
with
310315
| :? CompilationError as exn ->
311316
Assert.True(exn.Data2.[0].ToString().Contains("Foo.fs (1,13)-(1,14)"))
@@ -320,7 +325,8 @@ let ``Check compile of bad fsx`` () =
320325
"""
321326

322327
try
323-
compile false PdbOnly "Foo" "fsx" code [] |> ignore
328+
let outFile : string = compile false PdbOnly "Foo" "fsx" code [] []
329+
()
324330
with
325331
| :? CompilationError as exn ->
326332
Assert.True(exn.Data2.[0].ToString().Contains("Could not load file '"))
@@ -329,6 +335,21 @@ let ``Check compile of bad fsx`` () =
329335
| _ -> failwith "No compilation error"
330336

331337

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+
352+
332353
#if STRESS
333354
// For this stress test the aim is to check if we have a memory leak
334355

@@ -348,7 +369,8 @@ type C() =
348369
let x = 3 + 4
349370
"""
350371

351-
compile true PdbOnly "Foo" code [] |> ignore
372+
let outFile : string = compile true PdbOnly "Foo" "fs" code [] []
373+
()
352374

353375
#endif
354376

tests/service/ProjectOptionsTests.fs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,40 @@ let ``Project file parsing -- report files``() =
439439
for f in Directory.EnumerateFiles(dir41,"*",SearchOption.AllDirectories) do
440440
printfn "File: %s" f
441441

442+
[<Test>]
443+
let ``Test OtherOptions order for GetProjectOptionsFromScript`` () =
444+
let test scriptName expected2 =
445+
let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/" + scriptName + ".fsx"
446+
let scriptSource = File.ReadAllText scriptPath
447+
let projOpts = checker.GetProjectOptionsFromScript(scriptPath, scriptSource) |> Async.RunSynchronously
448+
449+
projOpts.OtherOptions
450+
|> Array.map Path.GetFileNameWithoutExtension
451+
|> shouldEqual expected2
452+
let otherArgs = [|"--noframework"; "3"; "System.Numerics"; "mscorlib"; "System"; "System.Xml"; "System.Runtime.Remoting"; "System.Runtime.Serialization.Formatters.Soap"; "System.Data"; "System.Drawing"; "System.Core"; "System.Runtime"; "System.Linq"; "System.Reflection"; "System.Linq.Expressions"; "System.Threading.Tasks"; "System.IO"; "System.Net.Requests"; "System.Collections"; "System.Runtime.Numerics"; "System.Threading"; "System.Web"; "System.Web.Services"; "System.Windows.Forms"; "FSharp.Compiler.Interactive.Settings"|]
453+
test "Main1" otherArgs
454+
test "Main2" otherArgs
455+
test "Main3" otherArgs
456+
test "Main4" otherArgs
457+
test "MainBad" otherArgs
458+
459+
442460
#endif
443461

444462
[<Test>]
445463
let ``Test ProjectFileNames order for GetProjectOptionsFromScript`` () = // See #594
446464
let test scriptName expected =
447465
let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/" + scriptName + ".fsx"
448466
let scriptSource = File.ReadAllText scriptPath
449-
let projOpts =
450-
checker.GetProjectOptionsFromScript(scriptPath, scriptSource)
451-
|> Async.RunSynchronously
467+
let projOpts = checker.GetProjectOptionsFromScript(scriptPath, scriptSource) |> Async.RunSynchronously
452468
projOpts.ProjectFileNames
453469
|> Array.map Path.GetFileNameWithoutExtension
454-
|> (=) expected
455-
|> shouldEqual true
456-
test "Main1" [|"BaseLib1"; "Lib1"; "Lib2"; "Main1"|]
457-
test "Main2" [|"BaseLib1"; "Lib1"; "Lib2"; "Lib3"; "Main2"|]
458-
test "Main3" [|"Lib3"; "Lib4"; "Main3"|]
459-
test "Main4" [|"BaseLib2"; "Lib5"; "BaseLib1"; "Lib1"; "Lib2"; "Main4"|]
470+
|> shouldEqual expected
471+
test "Main1" [|"BaseLib1"; "Lib1"; "Lib2"; "Main1"|]
472+
test "Main2" [|"BaseLib1"; "Lib1"; "Lib2"; "Lib3"; "Main2"|]
473+
test "Main3" [|"Lib3"; "Lib4"; "Main3"|]
474+
test "Main4" [|"BaseLib2"; "Lib5"; "BaseLib1"; "Lib1"; "Lib2"; "Main4"|]
475+
test "MainBad" [|"MainBad"|]
460476

461477
#endif
462478

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#load "NotExist1.fsx"
2+
#r "NotExist.dll"

0 commit comments

Comments
 (0)