-
Notifications
You must be signed in to change notification settings - Fork 839
Fix preferreduilang switch leaking into fsi.CommandLineArgs #19151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/handle-preferreduilang-option
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−1
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
315a423
Initial plan
Copilot 82501b8
Implement preferreduilang switch filtering in FSI script args
Copilot b1d1623
Add regression tests for preferreduilang switch in FSI
Copilot 47d5e89
Format code with fantomas
Copilot f40ffbb
Fix preferreduilang switch leaking into fsi.CommandLineArgs
Copilot 328b7b3
Fix invalid culture exception by validating before setting tcConfigB
Copilot 9c37001
Merge branch 'main' into copilot/handle-preferreduilang-option
abonie 86e0cff
Merge branch 'main' into copilot/handle-preferreduilang-option
T-Gro 6e92280
Add release notes for preferreduilang fix
Copilot 8c3ed3f
Update docs/release-notes/.FSharp.Compiler.Service/10.0.200.md
T-Gro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
tests/FSharp.Compiler.ComponentTests/Scripting/PreferredUiLangTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace Scripting | ||
|
|
||
| open Xunit | ||
| open System | ||
| open System.IO | ||
| open FSharp.Test | ||
| open FSharp.Test.CompilerAssertHelpers | ||
| open FSharp.Compiler.Interactive.Shell | ||
| open FSharp.Compiler.Diagnostics | ||
|
|
||
| module ``PreferredUiLang tests`` = | ||
|
|
||
| [<Fact>] | ||
| let ``preferreduilang switch before script is consumed from CommandLineArgs``() = | ||
| let scriptContent = """ | ||
| printfn "Args: %A" fsi.CommandLineArgs | ||
| if fsi.CommandLineArgs.Length <> 2 then exit 1 | ||
| if fsi.CommandLineArgs.[0] <> __SOURCE_FILE__ then exit 1 | ||
| if fsi.CommandLineArgs.[1] <> "arg1" then exit 1 | ||
| exit 0 | ||
| """ | ||
| let tmpFile = Path.GetTempFileName() + ".fsx" | ||
| try | ||
| File.WriteAllText(tmpFile, scriptContent) | ||
| let errors, _, _ = | ||
| CompilerAssert.RunScriptWithOptionsAndReturnResult | ||
| [| "--preferreduilang:es-ES"; tmpFile; "arg1" |] | ||
| "" | ||
|
|
||
| // Should succeed (exit 0) | ||
| Assert.True((errors: ResizeArray<string>).Count = 0, sprintf "Expected no errors, got: %A" errors) | ||
| finally | ||
| if File.Exists(tmpFile) then File.Delete(tmpFile) | ||
|
|
||
| [<Fact>] | ||
| let ``preferreduilang switch after script is consumed from CommandLineArgs``() = | ||
| let scriptContent = """ | ||
| printfn "Args: %A" fsi.CommandLineArgs | ||
| if fsi.CommandLineArgs.Length <> 2 then exit 1 | ||
| if fsi.CommandLineArgs.[0] <> __SOURCE_FILE__ then exit 1 | ||
| if fsi.CommandLineArgs.[1] <> "arg1" then exit 1 | ||
| exit 0 | ||
| """ | ||
| let tmpFile = Path.GetTempFileName() + ".fsx" | ||
| try | ||
| File.WriteAllText(tmpFile, scriptContent) | ||
| let errors, _, _ = | ||
| CompilerAssert.RunScriptWithOptionsAndReturnResult | ||
| [| tmpFile; "--preferreduilang:es-ES"; "arg1" |] | ||
| "" | ||
|
|
||
| // Should succeed (exit 0) | ||
| Assert.True((errors: ResizeArray<string>).Count = 0, sprintf "Expected no errors, got: %A" errors) | ||
| finally | ||
| if File.Exists(tmpFile) then File.Delete(tmpFile) | ||
|
|
||
| [<Fact>] | ||
| let ``preferreduilang with slash form is consumed from CommandLineArgs``() = | ||
| let scriptContent = """ | ||
| printfn "Args: %A" fsi.CommandLineArgs | ||
| if fsi.CommandLineArgs.Length <> 2 then exit 1 | ||
| if fsi.CommandLineArgs.[0] <> __SOURCE_FILE__ then exit 1 | ||
| if fsi.CommandLineArgs.[1] <> "arg1" then exit 1 | ||
| exit 0 | ||
| """ | ||
| let tmpFile = Path.GetTempFileName() + ".fsx" | ||
| try | ||
| File.WriteAllText(tmpFile, scriptContent) | ||
| let errors, _, _ = | ||
| CompilerAssert.RunScriptWithOptionsAndReturnResult | ||
| [| tmpFile; "/preferreduilang:de-DE"; "arg1" |] | ||
| "" | ||
|
|
||
| // Should succeed (exit 0) | ||
| Assert.True((errors: ResizeArray<string>).Count = 0, sprintf "Expected no errors, got: %A" errors) | ||
| finally | ||
| if File.Exists(tmpFile) then File.Delete(tmpFile) | ||
|
|
||
| [<Fact>] | ||
| let ``preferreduilang sets CurrentUICulture correctly``() = | ||
| let scriptContent = """ | ||
| let culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name | ||
| printfn "Culture: %s" culture | ||
| if not (culture.StartsWith("fr-FR")) then | ||
| printfn "Expected culture starting with fr-FR, got: %s" culture | ||
| exit 1 | ||
| exit 0 | ||
| """ | ||
| let tmpFile = Path.GetTempFileName() + ".fsx" | ||
| try | ||
| File.WriteAllText(tmpFile, scriptContent) | ||
| let errors, _, _ = | ||
| CompilerAssert.RunScriptWithOptionsAndReturnResult | ||
| [| "--preferreduilang:fr-FR"; tmpFile |] | ||
| "" | ||
|
|
||
| // Should succeed (exit 0) | ||
| Assert.True((errors: ResizeArray<string>).Count = 0, sprintf "Expected no errors, got: %A" errors) | ||
| finally | ||
| if File.Exists(tmpFile) then File.Delete(tmpFile) | ||
|
|
||
| [<Fact>] | ||
| let ``preferreduilang after script also sets culture``() = | ||
| let scriptContent = """ | ||
| let culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name | ||
| printfn "Culture: %s" culture | ||
| if not (culture.StartsWith("ja-JP")) then | ||
| printfn "Expected culture starting with ja-JP, got: %s" culture | ||
| exit 1 | ||
| exit 0 | ||
| """ | ||
| let tmpFile = Path.GetTempFileName() + ".fsx" | ||
| try | ||
| File.WriteAllText(tmpFile, scriptContent) | ||
| let errors, _, _ = | ||
| CompilerAssert.RunScriptWithOptionsAndReturnResult | ||
| [| tmpFile; "--preferreduilang:ja-JP" |] | ||
| "" | ||
|
|
||
| // Should succeed (exit 0) | ||
| Assert.True((errors: ResizeArray<string>).Count = 0, sprintf "Expected no errors, got: %A" errors) | ||
| finally | ||
| if File.Exists(tmpFile) then File.Delete(tmpFile) | ||
|
|
||
| [<Fact>] | ||
| let ``invalid culture in preferreduilang is ignored gracefully``() = | ||
| let scriptContent = """ | ||
| printfn "Args: %A" fsi.CommandLineArgs | ||
| if fsi.CommandLineArgs.Length <> 2 then exit 1 | ||
| if fsi.CommandLineArgs.[0] <> __SOURCE_FILE__ then exit 1 | ||
| if fsi.CommandLineArgs.[1] <> "arg1" then exit 1 | ||
| exit 0 | ||
| """ | ||
| let tmpFile = Path.GetTempFileName() + ".fsx" | ||
| try | ||
| File.WriteAllText(tmpFile, scriptContent) | ||
| let errors, _, _ = | ||
| CompilerAssert.RunScriptWithOptionsAndReturnResult | ||
| [| tmpFile; "--preferreduilang:invalid-culture-xyz"; "arg1" |] | ||
| "" | ||
|
|
||
| // Should succeed - invalid culture is ignored, but switch is still consumed | ||
| Assert.True((errors: ResizeArray<string>).Count = 0, sprintf "Expected no errors, got: %A" errors) | ||
| finally | ||
| if File.Exists(tmpFile) then File.Delete(tmpFile) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.