|
1 | 1 | module Tests |
2 | 2 |
|
| 3 | +open DotnetProjInfo.TestAssets |
3 | 4 | open Expecto |
4 | | -open FileUtils |
5 | | -open Medallion.Shell |
6 | | -open System.IO |
7 | 5 | open Expecto.Logging |
8 | | -open DotnetProjInfo.TestAssets |
9 | | -open Ionide.ProjInfo |
10 | | -open System.Collections.Generic |
11 | | -open Ionide.ProjInfo.Types |
12 | | -open Ionide.ProjInfo |
13 | 6 | open Expecto.Logging.Message |
| 7 | +open FileUtils |
14 | 8 | open FSharp.Compiler.CodeAnalysis |
| 9 | +open Ionide.ProjInfo |
| 10 | +open Ionide.ProjInfo |
| 11 | +open Ionide.ProjInfo.Types |
| 12 | +open Medallion.Shell |
| 13 | +open System |
| 14 | +open System.Collections.Generic |
| 15 | +open System.IO |
| 16 | +open System.Threading |
15 | 17 |
|
16 | 18 | #nowarn "25" |
17 | 19 |
|
@@ -727,10 +729,22 @@ let testProjectNotFound toolsPath workspaceLoader (workspaceFactory: ToolsPath - |
727 | 729 |
|
728 | 730 | Expect.equal (watcher.Notifications |> List.item 1) (WorkspaceProjectState.Failed(wrongPath, (GetProjectOptionsErrors.ProjectNotFound(wrongPath)))) "check error type") |
729 | 731 |
|
| 732 | +let internalGetCSharpReferenceInfo = |
| 733 | + fun (r: FSharpReferencedProject) -> |
| 734 | + let rCase, fields = |
| 735 | + FSharp.Reflection.FSharpValue.GetUnionFields(r, typeof<FSharpReferencedProject>, System.Reflection.BindingFlags.Public ||| System.Reflection.BindingFlags.NonPublic ||| System.Reflection.BindingFlags.Instance) |
| 736 | + if rCase.Name = "PEReference" then |
| 737 | + let path: string = fields[0] :?> _ |
| 738 | + let getStamp: unit -> DateTime = fields[1] :?> _ |
| 739 | + let reader = fields[2] |
| 740 | + Some (path, getStamp, reader) |
| 741 | + else |
| 742 | + None |
| 743 | + |
730 | 744 | let internalGetProjectOptions = |
731 | 745 | fun (r: FSharpReferencedProject) -> |
732 | 746 | let rCase, fields = |
733 | | - FSharp.Reflection.FSharpValue.GetUnionFields(r, typeof<FSharpReferencedProject>, System.Reflection.BindingFlags.NonPublic ||| System.Reflection.BindingFlags.Instance) |
| 747 | + FSharp.Reflection.FSharpValue.GetUnionFields(r, typeof<FSharpReferencedProject>, System.Reflection.BindingFlags.Public ||| System.Reflection.BindingFlags.NonPublic ||| System.Reflection.BindingFlags.Instance) |
734 | 748 |
|
735 | 749 | if rCase.Name = "FSharpReference" then |
736 | 750 | let projOptions: FSharpProjectOptions = rCase.GetFields().[1].GetValue(box r) :?> _ |
@@ -826,7 +840,7 @@ let testFCSmapManyProj toolsPath workspaceLoader (workspaceFactory: ToolsPath -> |
826 | 840 | copyDirFromAssets fs ``sample3 Netsdk projs``.ProjDir testDir |
827 | 841 |
|
828 | 842 | let projPath = testDir / (``sample3 Netsdk projs``.ProjectFile) |
829 | | - |
| 843 | + |
830 | 844 | // Build csproj, so it should be referenced as FSharpReferencedProject.PortableExecutable |
831 | 845 | let csproj = testDir / ``sample3 Netsdk projs``.ProjectReferences.[0].ProjectFile |
832 | 846 | dotnet fs [ "build"; csproj ] |> checkExitCodeZero |
@@ -1175,6 +1189,27 @@ let expensiveTests toolsPath (workspaceFactory: ToolsPath -> IWorkspaceLoader) = |
1175 | 1189 | Expect.exists references (fun r -> r.Contains "packs" && r.Contains "Microsoft.Android.") "Should have found a reference to android dlls in the packs directory" |
1176 | 1190 | } |
1177 | 1191 |
|
| 1192 | +let csharpLibTest toolsPath (workspaceFactory: ToolsPath -> IWorkspaceLoader) = |
| 1193 | + testCase |> withLog "can load project that has a csharp project reference" (fun logger fs -> |
| 1194 | + let projPath = Path.Combine(__SOURCE_DIRECTORY__, "..", "examples", "sample-referenced-csharp-project", "fsharp-exe", "fsharp-exe.fsproj") |
| 1195 | + // need to build the projects first so that there's something to latch on to |
| 1196 | + dotnet fs ["build"; projPath] |> checkExitCodeZero |
| 1197 | + |
| 1198 | + let loader = workspaceFactory toolsPath |
| 1199 | + let parsed = loader.LoadProjects [ projPath ] |> Seq.toList |
| 1200 | + Expect.hasLength parsed 2 "Should have loaded the F# exe and the C# lib" |
| 1201 | + let fsharpProject = parsed[0] |
| 1202 | + let mapped = FCS.mapToFSharpProjectOptions fsharpProject parsed |
| 1203 | + let referencedProjects = mapped.ReferencedProjects |
| 1204 | + Expect.hasLength referencedProjects 1 "Should have a reference to the C# lib" |
| 1205 | + match internalGetCSharpReferenceInfo referencedProjects[0] with |
| 1206 | + | Some (path, getStamp, reader) -> |
| 1207 | + let fileName = System.IO.Path.GetFileName path |
| 1208 | + Expect.equal fileName "csharp-lib.dll" "Should have found the C# lib" |
| 1209 | + | None -> |
| 1210 | + failwith "Should have found a C# reference" |
| 1211 | + ) |
| 1212 | + |
1178 | 1213 | let testProjectLoadBadData = |
1179 | 1214 | testCase |> withLog "Does not crash when loading malformed cache data" (fun logger fs -> |
1180 | 1215 | let testDir = inDir fs "sample_netsdk_bad_cache" |
@@ -1285,4 +1320,5 @@ let tests toolsPath = |
1285 | 1320 | testLegacyFrameworkMultiProject toolsPath "can load legacy multi project file" false (fun (tools, props) -> WorkspaceLoader.Create(tools, globalProperties = props)) |
1286 | 1321 | testProjectLoadBadData |
1287 | 1322 | expensiveTests toolsPath WorkspaceLoader.Create |
| 1323 | + csharpLibTest toolsPath WorkspaceLoader.Create |
1288 | 1324 | ] |
0 commit comments