diff --git a/.executor-pid b/.executor-pid new file mode 100644 index 0000000000..8be9e5c772 --- /dev/null +++ b/.executor-pid @@ -0,0 +1 @@ +33472 \ No newline at end of file diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index 7d4162f804..a4047b7219 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -57,6 +57,7 @@ * Fix parser recovery, name resolution, and code completion for unfinished enum patterns ([PR #19708](https://github.com/dotnet/fsharp/pull/19708)) * Parser: fix unexpected diagnostics in debug builds, improve error messages ([PR #19730](https://github.com/dotnet/fsharp/pull/19730)) * Fix signature conformance: overloaded member with unit parameter `M(())` now matches sig `member M: unit -> unit`. ([Issue #19596](https://github.com/dotnet/fsharp/issues/19596), [PR #19615](https://github.com/dotnet/fsharp/pull/19615)) +* Fix `--quiet` not suppressing NuGet restore output on stdout in F# Interactive ([Issue #18086](https://github.com/dotnet/fsharp/issues/18086)) ### Added diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 1ff957e77a..a5dcac2164 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -2819,8 +2819,15 @@ type internal FsiDynamicCompiler if result.Success then + // Issue #18086: under --quiet (tcConfigB.noFeedback), NuGet/MSBuild + // restore chatter and warnings must not pollute stdout. Route what + // would have gone to stdout to stderr instead so the information is + // still discoverable for users who redirect stderr. + let stdOutSink: System.IO.TextWriter = + if tcConfigB.noFeedback then Console.Error else Console.Out + for line in result.StdOut do - Console.Out.WriteLine(line) + stdOutSink.WriteLine(line) for line in result.StdError do Console.Error.WriteLine(line) diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs index a66269e63f..0dd699ec05 100644 --- a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs @@ -67,3 +67,47 @@ module FsiCliTests = let result = runFsiProcess [option] Assert.NotEqual(0, result.ExitCode) Assert.Contains(expectedError, result.StdErr) + + // ============================================================================ + // Issue #18086: --quiet must suppress NuGet restore stdout chatter + // ============================================================================ + + let private writeTempScript (content: string) : string = + let path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"fsi_quiet_{System.Guid.NewGuid():N}.fsx") + System.IO.File.WriteAllText(path, content) + path + + let private runFsiScript (extraArgs: string list) (scriptBody: string) = + let scriptPath = writeTempScript scriptBody + try + let result = runFsiProcess (extraArgs @ [scriptPath]) + result + finally + try System.IO.File.Delete(scriptPath) with _ -> () + + [] + let ``FSI quiet mode suppresses NuGet restore output from stdout`` () = + let script = """ +#r "nuget: Newtonsoft.Json, 13.0.3" +printfn "RESULT_MARKER_18086" +""" + let result = runFsiScript ["--quiet"] script + Assert.Contains("RESULT_MARKER_18086", result.StdOut) + Assert.DoesNotContain("Determining projects to restore", result.StdOut) + Assert.DoesNotContain("Restored ", result.StdOut) + Assert.DoesNotContain("NU1", result.StdOut) + + [] + let ``FSI default (non-quiet) mode still evaluates script and prints user output`` () = + let script = """ +#r "nuget: Newtonsoft.Json, 13.0.3" +printfn "RESULT_MARKER_18086_DEFAULT" +""" + let result = runFsiScript [] script + Assert.Contains("RESULT_MARKER_18086_DEFAULT", result.StdOut) + + [] + let ``FSI quiet mode still prints user printfn output to stdout`` () = + let script = """printfn "hello from quiet script" """ + let result = runFsiScript ["--quiet"] script + Assert.Contains("hello from quiet script", result.StdOut)