Skip to content

Commit

Permalink
add test to verify reference assembly support
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Feb 6, 2024
1 parent 62a99e3 commit d459c98
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/Ionide.ProjInfo.Tests/TestAssets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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``
]
}
53 changes: 53 additions & 0 deletions test/Ionide.ProjInfo.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

]
1 change: 1 addition & 0 deletions test/examples/sample-netsdk-prodref/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a library (l1) with ProduceReferenceAssembly set to true, and another library (l2) that references l1
5 changes: 5 additions & 0 deletions test/examples/sample-netsdk-prodref/l1/Library.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace n1

module Say =
let hello name =
printfn "Hello %s" name
12 changes: 12 additions & 0 deletions test/examples/sample-netsdk-prodref/l1/l1.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>

<ItemGroup>
<Compile Include="Library.fs" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions test/examples/sample-netsdk-prodref/l2/Library.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace n1

module Say =
let hello name =
printfn "Hello %s" name
12 changes: 12 additions & 0 deletions test/examples/sample-netsdk-prodref/l2/l2.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Library.fs" />
<ProjectReference Include="../l1/l1.fsproj" />
</ItemGroup>

</Project>

0 comments on commit d459c98

Please sign in to comment.