forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemTests.fs
85 lines (71 loc) · 3.39 KB
/
FileSystemTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
module FSharp.Compiler.Service.Tests.FileSystemTests
open Xunit
open FsUnit
open FSharp.Test
open System
open System.IO
open System.Text
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.IO
open FSharp.Compiler.Service.Tests.Common
let fileName1 = @"c:\mycode\test1.fs" // note, the path doesn' exist
let fileName2 = @"c:\mycode\test2.fs" // note, the path doesn' exist
#nowarn "57"
let file1 = """
module File1
let A = 1"""
let file2 = """
module File2
let B = File1.A + File1.A"""
type internal MyFileSystem() =
inherit DefaultFileSystem()
static member FilesCache = dict [(fileName1, file1); (fileName2, file2)]
// Implement the service to open files for reading and writing
override _.OpenFileForReadShim(filePath, ?useMemoryMappedFile: bool, ?shouldShadowCopy: bool) =
let shouldShadowCopy = defaultArg shouldShadowCopy false
let useMemoryMappedFile = defaultArg useMemoryMappedFile false
match MyFileSystem.FilesCache.TryGetValue filePath with
| true, text ->
new MemoryStream(Encoding.UTF8.GetBytes(text)) :> Stream
| _ -> base.OpenFileForReadShim(filePath, useMemoryMappedFile, shouldShadowCopy)
override _.FileExistsShim(fileName) = MyFileSystem.FilesCache.ContainsKey(fileName) || base.FileExistsShim(fileName)
let UseMyFileSystem() =
let myFileSystem = MyFileSystem()
FileSystemAutoOpens.FileSystem <- myFileSystem
{ new IDisposable with member x.Dispose() = FileSystemAutoOpens.FileSystem <- myFileSystem }
// .NET Core SKIPPED: need to check if these tests can be enabled for .NET Core testing of FSharp.Compiler.Service"
[<FactForDESKTOP>]
let ``FileSystem compilation test``() =
if Environment.OSVersion.Platform = PlatformID.Win32NT then // file references only valid on Windows
use myFileSystem = UseMyFileSystem()
let programFilesx86Folder = Environment.GetEnvironmentVariable("PROGRAMFILES(X86)")
let projectOptions =
let allFlags =
[| yield "--simpleresolution";
yield "--noframework";
yield "--debug:full";
yield "--define:DEBUG";
yield "--optimize-";
yield "--doc:test.xml";
yield "--warn:3";
yield "--fullpaths";
yield "--flaterrors";
yield "--target:library";
for r in [ sysLib "mscorlib"; sysLib "System"; sysLib "System.Core"; fsCoreDefaultReference() ] do
yield "-r:" + r |]
{ ProjectFileName = @"c:\mycode\compilation.fsproj" // Make a name that is unique in this directory.
ProjectId = None
SourceFiles = [| fileName1; fileName2 |]
OtherOptions = allFlags
ReferencedProjects = [| |];
IsIncompleteTypeCheckEnvironment = false
UseScriptResolutionRules = true
LoadTime = DateTime.Now // Not 'now', we don't want to force reloading
UnresolvedReferences = None
OriginalLoadReferences = []
Stamp = None }
let results = checker.ParseAndCheckProject(projectOptions) |> Async.RunImmediate
results.Diagnostics.Length |> shouldEqual 0
results.AssemblySignature.Entities.Count |> shouldEqual 2
results.AssemblySignature.Entities[0].MembersFunctionsAndValues.Count |> shouldEqual 1
results.AssemblySignature.Entities[0].MembersFunctionsAndValues[0].DisplayName |> shouldEqual "B"