33open Xunit
44open FsUnit
55open System
6- open System.IO
76open System.Text
87open System.Collections .Generic
9- open System.Diagnostics
10- open System.Threading
118open FSharp.Compiler .CodeAnalysis
129open FSharp.Compiler .Diagnostics
1310open FSharp.Compiler .IO
1411open FSharp.Compiler .Service .Tests .Common
1512open FSharp.Compiler .Symbols
1613open FSharp.Compiler .Symbols .FSharpExprPatterns
17- open TestFramework
1814
1915type FSharpCore =
2016 | FC45
@@ -29,52 +25,11 @@ type FSharpCore =
2925 | FC47 -> " FSharp.Core 4.7"
3026 | FC50 -> " FSharp.Core 5.0"
3127
28+ [<Literal>]
29+ let dirName = " ExprTests"
3230
3331[<AutoOpen>]
3432module internal Utils =
35- let getTempPath() =
36- Path.Combine(Path.GetTempPath(), "ExprTests")
37-
38- /// If it doesn't exists, create a folder 'ExprTests' in local user's %TEMP% folder
39- let createTempDir() =
40- let tempPath = getTempPath()
41- do
42- if Directory.Exists tempPath then ()
43- else Directory.CreateDirectory tempPath |> ignore
44-
45- /// Returns the file name part of a temp file name created with tryCreateTemporaryFileName ()
46- /// and an added process id and thread id to ensure uniqueness between threads.
47- let getTempFileName() =
48- let tempFileName = tryCreateTemporaryFileName ()
49- try
50- let tempFile, tempExt = Path.GetFileNameWithoutExtension tempFileName, Path.GetExtension tempFileName
51- let procId, threadId = Process.GetCurrentProcess().Id, Thread.CurrentThread.ManagedThreadId
52- String.concat "" [tempFile; "_"; string procId; "_"; string threadId; tempExt] // ext includes dot
53- finally
54- try
55- FileSystem.FileDeleteShim tempFileName
56- with _ -> ()
57-
58- /// Clean up after a test is run. If you need to inspect the create *.fs files, change this function to do nothing, or just break here.
59- let cleanupTempFiles files =
60- { new IDisposable with
61- member _.Dispose() =
62- for fileName in files do
63- try
64- // cleanup: only the source file is written to the temp dir.
65- FileSystem.FileDeleteShim fileName
66- with _ -> ()
67-
68- try
69- // remove the dir when empty
70- let tempPath = getTempPath()
71- if Directory.GetFiles tempPath |> Array.isEmpty then
72- Directory.Delete tempPath
73- with _ -> () }
74-
75- /// Given just a file name, returns it with changed extension located in %TEMP%\ExprTests
76- let getTempFilePathChangeExt tmp ext =
77- Path.Combine(getTempPath(), Path.ChangeExtension(tmp, ext))
7833
7934 // This behaves slightly differently on Mono versions, 'null' is printed sometimes, 'None' other times
8035 // Presumably this is very small differences in Mono reflection causing F# printing to change behaviour
@@ -345,22 +300,6 @@ module internal Utils =
345300 yield ! collectMembers e |> Seq.map printMemberSignature
346301 }
347302
348-
349- let createOptionsAux fileSources extraArgs =
350- let fileNames = fileSources |> List.map (fun _ -> Utils.getTempFileName())
351- let temp2 = Utils.getTempFileName()
352- let fileNames = fileNames |> List.map (fun temp1 -> Utils.getTempFilePathChangeExt temp1 ".fs")
353- let dllName = Utils.getTempFilePathChangeExt temp2 ".dll"
354- let projFileName = Utils.getTempFilePathChangeExt temp2 ".fsproj"
355-
356- Utils.createTempDir()
357- for fileSource: string, fileName in List.zip fileSources fileNames do
358- FileSystem.OpenFileForWriteShim(fileName).Write(fileSource)
359- let args = [| yield! extraArgs; yield! mkProjectCommandLineArgs (dllName, []) |]
360- let options = { checker.GetProjectOptionsFromCommandLineArgs (projFileName, args) with SourceFiles = fileNames |> List.toArray }
361-
362- Utils.cleanupTempFiles (fileNames @ [dllName; projFileName]), options
363-
364303//---------------------------------------------------------------------------------------------------------
365304// This project is a smoke test for a whole range of standard and obscure expressions
366305
@@ -653,7 +592,7 @@ let testMutableVar = mutableVar 1
653592let testMutableConst = mutableConst ()
654593 """
655594
656- let createOptionsWithArgs args = createOptionsAux [ fileSource1; fileSource2 ] args
595+ let createOptionsWithArgs args = createProjectOptions dirName [ fileSource1; fileSource2 ] args
657596
658597 let createOptions () = createOptionsWithArgs []
659598
@@ -1002,15 +941,15 @@ let ``Test Optimized Declarations Project1`` useTransparentCompiler =
1002941
1003942let testOperators dnName fsName excludedTests expectedUnoptimized expectedOptimized =
1004943
1005- let tempFileName = Utils. getTempFileName()
1006- let filePath = Utils. getTempFilePathChangeExt tempFileName ".fs"
1007- let dllPath =Utils. getTempFilePathChangeExt tempFileName ".dll"
1008- let projFilePath = Utils. getTempFilePathChangeExt tempFileName ".fsproj"
944+ let tempFileName = getTempFileName()
945+ let filePath = getTempFilePathChangeExt dirName tempFileName " .fs"
946+ let dllPath = getTempFilePathChangeExt dirName tempFileName " .dll"
947+ let projFilePath = getTempFilePathChangeExt dirName tempFileName " .fsproj"
1009948 let exprChecker = FSharpChecker.Create( keepAssemblyContents= true , useTransparentCompiler= true )
1010949
1011950 begin
1012- use _cleanup = Utils. cleanupTempFiles [filePath; dllPath; projFilePath]
1013- createTempDir()
951+ use _cleanup = cleanupTempFiles dirName [ filePath; dllPath; projFilePath]
952+ createTempDir dirName
1014953 let source = String.Format( Project1.operatorTests, dnName, fsName)
1015954 let replace ( s : string ) r = s.Replace( " let " + r, " // let " + r)
1016955 let fileSource = excludedTests |> List.fold replace source
@@ -3192,7 +3131,7 @@ let BigSequenceExpression(outFileOpt,docFileOpt,baseAddressOpt) =
31923131 """
31933132
31943133
3195- let createOptions() = createOptionsAux [fileSource1] []
3134+ let createOptions () = createProjectOptions dirName [ fileSource1] []
31963135
31973136#if ! NETFRAMEWORK && DEBUG
31983137[<Fact( Skip = " Test is known to fail in DEBUG when not using NetFramework. Use RELEASE configuration or NetFramework to run it." ) >]
@@ -3279,7 +3218,7 @@ let f7() = callXY (C()) (D())
32793218let f8() = callXY (D()) (C())
32803219 """
32813220
3282- let createOptions() = createOptionsAux [fileSource1] ["--langversion:7.0"]
3221+ let createOptions () = createProjectOptions dirName [ fileSource1] [ " --langversion:7.0" ]
32833222
32843223[<Theory>]
32853224[<InlineData( false ) >]
@@ -3407,7 +3346,7 @@ type MyNumberWrapper =
34073346 { MyNumber: MyNumber }
34083347 """
34093348
3410- let createOptions() = createOptionsAux [fileSource1] ["--langversion:7.0"]
3349+ let createOptions () = createProjectOptions dirName [ fileSource1] [ " --langversion:7.0" ]
34113350
34123351[<Theory>]
34133352[<InlineData( false ) >]
@@ -3465,13 +3404,13 @@ let s2 = sign p1
34653404
34663405 """
34673406
3468- let createOptions() = createOptionsAux [fileSource1] ["--langversion:7.0"]
3407+ let createOptions () = createProjectOptions dirName [ fileSource1] [ " --langversion:7.0" ]
34693408
34703409[<Theory>]
34713410[<InlineData( false ) >]
34723411[<InlineData( true ) >]
34733412let ``Test ProjectForWitnesses3`` useTransparentCompiler =
3474- let cleanup, options = createOptionsAux [ ProjectForWitnesses3.fileSource1 ] ["--langversion:7.0"]
3413+ let cleanup , options = createProjectOptions dirName [ ProjectForWitnesses3.fileSource1 ] [ " --langversion:7.0" ]
34753414 use _holder = cleanup
34763415 let exprChecker = FSharpChecker.Create( keepAssemblyContents= true , useTransparentCompiler= useTransparentCompiler)
34773416 let wholeProjectResults = exprChecker.ParseAndCheckProject( options) |> Async.RunImmediate
@@ -3563,7 +3502,7 @@ let isNullQuoted (ts : 't[]) =
35633502
35643503"""
35653504
3566- let createOptions() = createOptionsAux [fileSource1] ["--langversion:7.0"]
3505+ let createOptions () = createProjectOptions dirName [ fileSource1] [ " --langversion:7.0" ]
35673506
35683507[<Theory>]
35693508[<InlineData( false ) >]
@@ -3603,7 +3542,7 @@ module N.M
36033542let rec f = new System.EventHandler(fun _ _ -> f.Invoke(null,null))
36043543"""
36053544
3606- let createOptions() = createOptionsAux [fileSource1] []
3545+ let createOptions () = createProjectOptions dirName [ fileSource1] []
36073546
36083547[<Theory>]
36093548[<InlineData( false ) >]
0 commit comments