Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,28 @@ module FsiCliTests =
finally
try System.IO.File.Delete(scriptPath) with _ -> ()

// The FSI #r "nuget:" restore below must request a package version that is guaranteed to be in
// the offline restore cache on the internal signed build (which cannot restore online). Central
// package management + transitive pinning means only the centrally-pinned version (eng/Packages.props)
// is ever restored into that cache, and it changes whenever the pin is bumped. Rather than hardcode
// a version that would silently drift, read the exact pinned version baked into this test assembly
// at build time via AssemblyMetadata (see FSharp.Compiler.ComponentTests.fsproj). The package id
// (MessagePack) is kept in sync with that project; any centrally-pinned standalone package would do.
[<Literal>]
let private restoreTestPackageId = "MessagePack"

let private restoreTestPackageVersion =
System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof<System.Reflection.AssemblyMetadataAttribute>, false)
|> Array.tryPick (fun a ->
let m = a :?> System.Reflection.AssemblyMetadataAttribute
if m.Key = "FsiRestoreTestPackageVersion" && not (System.String.IsNullOrWhiteSpace m.Value) then Some m.Value else None)
|> Option.defaultWith (fun () ->
failwith "AssemblyMetadata 'FsiRestoreTestPackageVersion' is missing. It should be emitted by FSharp.Compiler.ComponentTests.fsproj from the central MessagePack PackageVersion.")

[<Fact>]
let ``FSI quiet mode suppresses NuGet restore output from stdout`` () =
let script = """
#r "nuget: Newtonsoft.Json, 13.0.3"
let script = $"""
#r "nuget: {restoreTestPackageId}, {restoreTestPackageVersion}"
printfn "RESULT_MARKER_18086"
"""
let result = runFsiScript ["--quiet"] script
Expand All @@ -100,8 +118,8 @@ printfn "RESULT_MARKER_18086"

[<Fact>]
let ``FSI default (non-quiet) mode still evaluates script and prints user output`` () =
let script = """
#r "nuget: Newtonsoft.Json, 13.0.3"
let script = $"""
#r "nuget: {restoreTestPackageId}, {restoreTestPackageVersion}"
printfn "RESULT_MARKER_18086_DEFAULT"
"""
let result = runFsiScript [] script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,5 +562,20 @@
<PackageReference Include="FSharp.Core" />
</ItemGroup>

<!-- FsiCliTests spawns FSI and does `#r "nuget: <pkg>, <version>"` to verify that quiet mode
suppresses NuGet restore chatter. On the internal signed build NuGet restore is offline, so the
requested version must be one that is already in the restore cache. Under central package
management with transitive pinning, that is exactly the centrally-pinned version
(eng/Packages.props). Bake that version into the test assembly so the test can request it at
runtime with no manual sync when the central pin is bumped. MessagePack is used (rather than a
general-purpose JSON package) because it is an actively-maintained, non-system standalone library
that is centrally pinned and restored transitively by the product (StreamJsonRpc); keep the
package id here in sync with the id in FsiCliTests.fs. -->
<PropertyGroup>
<FsiRestoreTestPackageVersion>@(PackageVersion->WithMetadataValue('Identity','MessagePack')->'%(Version)')</FsiRestoreTestPackageVersion>
</PropertyGroup>
<ItemGroup>
<AssemblyMetadata Include="FsiRestoreTestPackageVersion" Value="$(FsiRestoreTestPackageVersion)" />
</ItemGroup>

</Project>
Loading