From d459c986737c8d679dad950d490c968f29691864 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 5 Feb 2024 21:50:42 -0600 Subject: [PATCH] add test to verify reference assembly support --- test/Ionide.ProjInfo.Tests/TestAssets.fs | 24 +++++++++ test/Ionide.ProjInfo.Tests/Tests.fs | 53 +++++++++++++++++++ test/examples/sample-netsdk-prodref/README.md | 1 + .../sample-netsdk-prodref/l1/Library.fs | 5 ++ .../sample-netsdk-prodref/l1/l1.fsproj | 12 +++++ .../sample-netsdk-prodref/l2/Library.fs | 5 ++ .../sample-netsdk-prodref/l2/l2.fsproj | 12 +++++ 7 files changed, 112 insertions(+) create mode 100644 test/examples/sample-netsdk-prodref/README.md create mode 100644 test/examples/sample-netsdk-prodref/l1/Library.fs create mode 100644 test/examples/sample-netsdk-prodref/l1/l1.fsproj create mode 100644 test/examples/sample-netsdk-prodref/l2/Library.fs create mode 100644 test/examples/sample-netsdk-prodref/l2/l2.fsproj diff --git a/test/Ionide.ProjInfo.Tests/TestAssets.fs b/test/Ionide.ProjInfo.Tests/TestAssets.fs index df33e182..c80e531e 100644 --- a/test/Ionide.ProjInfo.Tests/TestAssets.fs +++ b/test/Ionide.ProjInfo.Tests/TestAssets.fs @@ -280,3 +280,27 @@ let ``sample9 NetSdk library`` = { TargetFrameworks = Map.ofList [ "netstandard2.0", sourceFiles [ "Library.fs" ] ] ProjectReferences = [] } + +/// dotnet sdk library with ProduceReferenceAssembly=true +let ``NetSDK library with ProduceReferenceAssembly`` = { + ProjDir = "sample-netsdk-prodref" + AssemblyName = "l1" + ProjectFile = + "l1" + / "l1.fsproj" + TargetFrameworks = Map.ofList [ "netstandard2.0", sourceFiles [ "Library.fs" ] ] + ProjectReferences = [] +} + + +let ``NetSDK library referencing ProduceReferenceAssembly library`` = { + ProjDir = "sample-netsdk-prodref" + AssemblyName = "l2" + ProjectFile = + "l2" + / "l2.fsproj" + TargetFrameworks = Map.ofList [ "netstandard2.0", sourceFiles [ "Library.fs" ] ] + ProjectReferences = [ + ``NetSDK library with ProduceReferenceAssembly`` + ] +} diff --git a/test/Ionide.ProjInfo.Tests/Tests.fs b/test/Ionide.ProjInfo.Tests/Tests.fs index d3cd3d92..0a1f1237 100644 --- a/test/Ionide.ProjInfo.Tests/Tests.fs +++ b/test/Ionide.ProjInfo.Tests/Tests.fs @@ -30,6 +30,20 @@ let ExamplesDir = / "test" / "examples" +let pathForTestAssets (test: TestAssetProjInfo) = + ExamplesDir + / test.ProjDir + +let pathForProject (test: TestAssetProjInfo) = + pathForTestAssets test + / test.ProjectFile + +let implAssemblyForProject (test: TestAssetProjInfo) = + $"{test.AssemblyName}.dll" + +let refAssemblyForProject (test: TestAssetProjInfo) = + Path.Combine("ref", implAssemblyForProject test) + let TestRunDir = RepoDir / "test" @@ -2119,6 +2133,41 @@ let csharpLibTest toolsPath (workspaceFactory: ToolsPath -> IWorkspaceLoader) = | _ -> failwith "Should have found a C# reference" ) +let referenceAssemblySupportTest toolsPath prefix (workspaceFactory: ToolsPath -> IWorkspaceLoader) = + testCase + |> withLog + $"{prefix} can reference projects that support reference assemblies" + (fun logger fs -> + let parentProj: TestAssetProjInfo = ``NetSDK library with ProduceReferenceAssembly`` + let childProj = ``NetSDK library referencing ProduceReferenceAssembly library`` + + let projPath = pathForProject childProj + + // need to build the projects first so that there's something to latch on to + dotnet fs [ + "build" + projPath + ] + |> checkExitCodeZero + + let loader = workspaceFactory toolsPath + + let parsed = + loader.LoadProjects [ projPath ] + |> Seq.toList + + Expect.hasLength parsed 2 "Should have loaded the F# lib and the referenced F# lib" + let fsharpProject = parsed |> Seq.find (fun p -> Path.GetFileName(p.ProjectFileName) = Path.GetFileName(childProj.ProjectFile)) + let mapped = FCS.mapToFSharpProjectOptions fsharpProject parsed + let referencedProjects = mapped.ReferencedProjects + Expect.hasLength referencedProjects 1 "Should have a reference to the F# ProjectReference lib" + + match referencedProjects[0] with + | FSharpReferencedProject.FSharpReference(targetPath, _) -> + Expect.stringContains targetPath (refAssemblyForProject parentProj) "Should have found the ref assembly for the F# lib" + | _ -> failwith "Should have found a F# reference" + ) + let testProjectLoadBadData = testCase |> withLog @@ -2247,4 +2296,8 @@ let tests toolsPath = testProjectLoadBadData expensiveTests toolsPath WorkspaceLoader.Create csharpLibTest toolsPath WorkspaceLoader.Create + + referenceAssemblySupportTest toolsPath (nameof(WorkspaceLoader)) WorkspaceLoader.Create + referenceAssemblySupportTest toolsPath (nameof(WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create + ] diff --git a/test/examples/sample-netsdk-prodref/README.md b/test/examples/sample-netsdk-prodref/README.md new file mode 100644 index 00000000..d84e3731 --- /dev/null +++ b/test/examples/sample-netsdk-prodref/README.md @@ -0,0 +1 @@ +a library (l1) with ProduceReferenceAssembly set to true, and another library (l2) that references l1 diff --git a/test/examples/sample-netsdk-prodref/l1/Library.fs b/test/examples/sample-netsdk-prodref/l1/Library.fs new file mode 100644 index 00000000..7f8edfa6 --- /dev/null +++ b/test/examples/sample-netsdk-prodref/l1/Library.fs @@ -0,0 +1,5 @@ +namespace n1 + +module Say = + let hello name = + printfn "Hello %s" name diff --git a/test/examples/sample-netsdk-prodref/l1/l1.fsproj b/test/examples/sample-netsdk-prodref/l1/l1.fsproj new file mode 100644 index 00000000..cfb01100 --- /dev/null +++ b/test/examples/sample-netsdk-prodref/l1/l1.fsproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + true + + + + + + + diff --git a/test/examples/sample-netsdk-prodref/l2/Library.fs b/test/examples/sample-netsdk-prodref/l2/Library.fs new file mode 100644 index 00000000..7f8edfa6 --- /dev/null +++ b/test/examples/sample-netsdk-prodref/l2/Library.fs @@ -0,0 +1,5 @@ +namespace n1 + +module Say = + let hello name = + printfn "Hello %s" name diff --git a/test/examples/sample-netsdk-prodref/l2/l2.fsproj b/test/examples/sample-netsdk-prodref/l2/l2.fsproj new file mode 100644 index 00000000..b96931a5 --- /dev/null +++ b/test/examples/sample-netsdk-prodref/l2/l2.fsproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + +