diff --git a/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj b/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj index 23edeb171224f..ee40ffc68c229 100644 --- a/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj +++ b/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj @@ -86,6 +86,7 @@ + diff --git a/src/Interactive/HostTest/InteractiveHostTests.cs b/src/Interactive/HostTest/InteractiveHostTests.cs index 2a232f70e3ff7..843883b281d76 100644 --- a/src/Interactive/HostTest/InteractiveHostTests.cs +++ b/src/Interactive/HostTest/InteractiveHostTests.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Microsoft.CodeAnalysis.Editor.CSharp; using Microsoft.CodeAnalysis.Editor.CSharp.Interactive; using Microsoft.CodeAnalysis.Interactive; using Microsoft.CodeAnalysis.Test.Utilities; @@ -57,7 +58,7 @@ public InteractiveHostTests() Assert.Equal("", errorOutput); Assert.Equal(2, output.Length); - Assert.Equal("Microsoft (R) Roslyn C# Compiler version " + FileVersionInfo.GetVersionInfo(_host.GetType().Assembly.Location).FileVersion, output[0]); + Assert.Equal(string.Format(CSharpInteractiveEditorResources.Microsoft_R_Roslyn_CSharp_Compiler_version_0, FileVersionInfo.GetVersionInfo(_host.GetType().Assembly.Location).FileVersion), output[0]); // "Type "#help" for more information." Assert.Equal(FeaturesResources.Type_Sharphelp_for_more_information, output[1]); @@ -853,7 +854,7 @@ public void ReferencePaths() var output = SplitLines(ReadOutputToEnd()); Assert.Equal(2, output.Length); - Assert.Equal("Loading context from '" + Path.GetFileName(rspFile.Path) + "'.", output[0]); + Assert.Equal($"{ string.Format(FeaturesResources.Loading_context_from_0, Path.GetFileName(rspFile.Path)) }", output[0]); Assert.Equal($"[{assemblyName}, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]", output[1]); } @@ -906,7 +907,7 @@ public void DefaultUsings() AssertEx.AssertEqualToleratingWhitespaceDifferences("", ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Loading context from '{Path.GetFileName(rspFile.Path)}'. +$@"{ string.Format(FeaturesResources.Loading_context_from_0, Path.GetFileName(rspFile.Path)) } OK ", ReadOutputToEnd()); } @@ -929,11 +930,11 @@ public void InitialScript_Error() Execute("new Process()"); AssertEx.AssertEqualToleratingWhitespaceDifferences($@" -{initFile.Path}(1,3): error CS1002: ; expected +{initFile.Path}(1,3): error CS1002: { CSharpResources.ERR_SemicolonExpected } ", ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences($@" -Loading context from '{Path.GetFileName(rspFile.Path)}'. +{ string.Format(FeaturesResources.Loading_context_from_0, Path.GetFileName(rspFile.Path)) } [System.Diagnostics.Process] ", ReadOutputToEnd()); } @@ -955,7 +956,7 @@ public void ScriptAndArguments() Assert.Equal("", ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Loading context from '{Path.GetFileName(rspFile.Path)}'. +$@"{ string.Format(FeaturesResources.Loading_context_from_0, Path.GetFileName(rspFile.Path)) } ""a"" ""b"" ""c"" @@ -986,8 +987,8 @@ public void Script_NoHostNamespaces() { Execute("nameof(Microsoft.CodeAnalysis)"); - AssertEx.AssertEqualToleratingWhitespaceDifferences(@" -(1,8): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)", + AssertEx.AssertEqualToleratingWhitespaceDifferences($@" +(1,8): error CS0234: { string.Format(CSharpResources.ERR_DottedTypeNameNotFoundInNS, "CodeAnalysis", "Microsoft") }", ReadErrorOutputToEnd()); Assert.Equal("", ReadOutputToEnd()); diff --git a/src/Scripting/CSharpTest.Desktop/CsiTests.cs b/src/Scripting/CSharpTest.Desktop/CsiTests.cs index 4f364b7fdc827..aa371934ae23b 100644 --- a/src/Scripting/CSharpTest.Desktop/CsiTests.cs +++ b/src/Scripting/CSharpTest.Desktop/CsiTests.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Reflection; +using Microsoft.CodeAnalysis.Scripting; using Roslyn.Test.Utilities; using Roslyn.Utilities; using Xunit; @@ -50,19 +51,24 @@ public void CurrentWorkingDirectory_Change() Environment.Exit(0) "); - AssertEx.AssertEqualToleratingWhitespaceDifferences($@" -Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. + var expected = $@" +{ string.Format(CSharpScriptingResources.LogoLine1, s_compilerVersion) } +{CSharpScriptingResources.LogoLine2} -Type ""#help"" for more information. +{ScriptingResources.HelpPrompt} > > > > > > 1 > C {{ }} > -", result.Output); +"; + // The German translation (and possibly others) contains an en dash (0x2013), + // but csi.exe outputs it as a hyphen-minus (0x002d). We need to fix up the + // expected string before we can compare it to the actual output. + expected = expected.Replace((char)0x2013, (char)0x002d); // EN DASH -> HYPHEN-MINUS + AssertEx.AssertEqualToleratingWhitespaceDifferences(expected, result.Output); AssertEx.AssertEqualToleratingWhitespaceDifferences($@" -(1,7): error CS1504: Source file 'a.csx' could not be opened -- Could not find file. -(1,1): error CS0006: Metadata file 'C.dll' could not be found +(1,7): error CS1504: { string.Format(CSharpResources.ERR_NoSourceFile, "a.csx", CSharpResources.CouldNotFindFile) } +(1,1): error CS0006: { string.Format(CSharpResources.ERR_NoMetadataFile,"C.dll") } ", result.Errors); Assert.Equal(0, result.ExitCode); @@ -143,7 +149,7 @@ public void LineNumber_Information_On_Exception() AssertEx.AssertEqualToleratingWhitespaceDifferences("OK", result.Output); AssertEx.AssertEqualToleratingWhitespaceDifferences($@" Error! - + .MoveNext() at {cwd}{Path.DirectorySeparatorChar}a.csx : 2 + + .MoveNext(){string.Format(ScriptingResources.AtFileLine, $"{cwd}{Path.DirectorySeparatorChar}a.csx", "2")} ", result.Errors); } } diff --git a/src/Scripting/CSharpTest/CommandLineRunnerTests.cs b/src/Scripting/CSharpTest/CommandLineRunnerTests.cs index 8b9c5f4a6551e..6f7deb10a1fb6 100644 --- a/src/Scripting/CSharpTest/CommandLineRunnerTests.cs +++ b/src/Scripting/CSharpTest/CommandLineRunnerTests.cs @@ -23,6 +23,10 @@ public class CommandLineRunnerTests : TestBase { private static readonly string s_compilerVersion = typeof(CSharpInteractiveCompiler).GetTypeInfo().Assembly.GetCustomAttribute().Version; + private static readonly string s_logoAndHelpPrompt = $@"{ string.Format(CSharpScriptingResources.LogoLine1, s_compilerVersion) } +{CSharpScriptingResources.LogoLine2} + +{ScriptingResources.HelpPrompt}"; // default csi.rsp private static readonly string[] s_defaultArgs = new[] @@ -115,16 +119,13 @@ select x * x runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > async Task GetStuffAsync() . {{ . return new int[] {{ 1, 2, 3, 4, 5 }}; . }} «Yellow» -(1,19): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. +(1,19): warning CS1998: { CSharpResources.WRN_AsyncLacksAwaits } «Gray» > from x in await GetStuffAsync() . where x > 2 @@ -133,14 +134,19 @@ . select x * x > ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( - @"(1,19): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.", + $@"(1,19): warning CS1998: { CSharpResources.WRN_AsyncLacksAwaits }", runner.Console.Error.ToString()); } - [Fact(Skip="https://github.com/dotnet/roslyn/issues/17043")] + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/17043")] [WorkItem(7133, "http://github.com/dotnet/roslyn/issues/7133")] - public void TestDisplayResultsWithCurrentUICulture() + public void TestDisplayResultsWithCurrentUICulture1() { + // logoOutput needs to be retrieved before the runner is started, because the runner changes the culture to de-DE. + var logoOutput = $@"{ string.Format(CSharpScriptingResources.LogoLine1, s_compilerVersion) } +{ CSharpScriptingResources.LogoLine2} + +{ ScriptingResources.HelpPrompt}"; var runner = CreateRunner(input: @"using System.Globalization; CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(""en-GB"", useUserOverride: false) @@ -151,10 +157,7 @@ public void TestDisplayResultsWithCurrentUICulture() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{ logoOutput } > using System.Globalization; > CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(""en-GB"", useUserOverride: false) [en-GB] @@ -165,9 +168,19 @@ public void TestDisplayResultsWithCurrentUICulture() > Math.PI 3,1415926535897931 >", runner.Console.Out.ToString()); + } + + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/17043")] + [WorkItem(7133, "http://github.com/dotnet/roslyn/issues/7133")] + public void TestDisplayResultsWithCurrentUICulture2() + { + // logoOutput needs to be retrieved before the runner is started, because the runner changes the culture to de-DE. + var logoOutput = $@"{ string.Format(CSharpScriptingResources.LogoLine1, s_compilerVersion) } +{ CSharpScriptingResources.LogoLine2} +{ ScriptingResources.HelpPrompt}"; // Tests that DefaultThreadCurrentUICulture is respected and not DefaultThreadCurrentCulture. - runner = CreateRunner(input: + var runner = CreateRunner(input: @"using System.Globalization; CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(""en-GB"", useUserOverride: false) CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(""en-GB"", useUserOverride: false) @@ -178,10 +191,7 @@ public void TestDisplayResultsWithCurrentUICulture() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{ logoOutput } > using System.Globalization; > CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(""en-GB"", useUserOverride: false) [en-GB] @@ -206,10 +216,7 @@ public void Void() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > Print(1); 1 > Print(2) @@ -225,10 +232,7 @@ public void Tuples() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > (1,2) [(1, 2)] > ", runner.Console.Out.ToString()); @@ -245,10 +249,7 @@ public void Exception() Assert.Equal(0, runner.RunInteractive()); Assert.Equal( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > int div(int a, int b) => a/b; > div(10, 2) 5 @@ -276,10 +277,7 @@ public void ExceptionInGeneric() Assert.Equal(0, runner.RunInteractive()); Assert.Equal( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > static class C {{ public static int div(int a, int b) => a/b; }} > C.div(10, 2) 5 @@ -306,10 +304,7 @@ public void Args_Interactive1() runner.RunInteractive(); Assert.Equal( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > 1+1 2 > ", runner.Console.Out.ToString()); @@ -324,7 +319,7 @@ public void Args_Interactive2() runner.RunInteractive(); - var error = $@"error CS2001: Source file '{Path.Combine(AppContext.BaseDirectory, "@arg1")}' could not be found."; + var error = $@"error CS2001: { string.Format(CSharpResources.ERR_FileNotFound, Path.Combine(AppContext.BaseDirectory, "@arg1"))}"; AssertEx.AssertEqualToleratingWhitespaceDifferences(error, runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences(error, runner.Console.Error.ToString()); } @@ -472,7 +467,7 @@ public void Script_NonExistingFile() Assert.Equal(1, runner.RunInteractive()); - var error = $@"error CS2001: Source file '{Path.Combine(AppContext.BaseDirectory, "a + b")}' could not be found."; + var error = $@"error CS2001: { string.Format(CSharpResources.ERR_FileNotFound, Path.Combine(AppContext.BaseDirectory, "a + b")) }"; AssertEx.AssertEqualToleratingWhitespaceDifferences(error, runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences(error, runner.Console.Error.ToString()); } @@ -485,24 +480,10 @@ public void Help() Assert.Equal(0, runner.RunInteractive()); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Usage: csi [option] ... [script-file.csx] [script-argument] ... - -Executes script-file.csx if specified, otherwise launches an interactive REPL (Read Eval Print Loop). - -Options: - /help Display this usage message (alternative form: /?) - /version Display the version and exit - /i Drop to REPL after executing the specified script. - /r: Reference metadata from the specified assembly file (alternative form: /reference) - /r: Reference metadata from the specified assembly files (alternative form: /reference) - /lib: List of directories where to look for libraries specified by #r directive. - (alternative forms: /libPath /libPaths) - /u: Define global namespace using (alternative forms: /using, /usings, /import, /imports) - @ Read response file for more options - -- Indicates that the remaining arguments should not be treated as options. +$@"{ string.Format(CSharpScriptingResources.LogoLine1, s_compilerVersion) } +{CSharpScriptingResources.LogoLine2} + +{CSharpScriptingResources.InteractiveHelp} ", runner.Console.Out.ToString()); } @@ -540,7 +521,7 @@ public void Script_BadUsings() Assert.Equal(1, runner.RunInteractive()); - const string error = @"error CS0246: The type or namespace name 'Alpha' could not be found (are you missing a using directive or an assembly reference?)"; + var error = $@"error CS0246: { string.Format(CSharpResources.ERR_SingleTypeNameNotFound, "Alpha") }"; AssertEx.AssertEqualToleratingWhitespaceDifferences(error, runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences(error, runner.Console.Error.ToString()); } @@ -553,18 +534,15 @@ public void Script_NoHostNamespaces() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > nameof(Microsoft.CodeAnalysis) «Red» -(1,8): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) +(1,8): error CS0234: { string.Format(CSharpResources.ERR_DottedTypeNameNotFoundInNS, "CodeAnalysis", "Microsoft") } «Gray» > ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( - "(1,8): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)", + $"(1,8): error CS0234: { string.Format(CSharpResources.ERR_DottedTypeNameNotFoundInNS, "CodeAnalysis", "Microsoft") }", runner.Console.Error.ToString()); } @@ -671,15 +649,12 @@ public void SourceSearchPaths_Change1() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences($@" -Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +{s_logoAndHelpPrompt} > SourcePaths SearchPaths {{ }} > #load ""a.csx"" «Red» -(1,7): error CS1504: Source file 'a.csx' could not be opened -- Could not find file. +(1,7): error CS1504: { string.Format(CSharpResources.ERR_NoSourceFile, "a.csx", CSharpResources.CouldNotFindFile) } «Gray» > SourcePaths.Add(@""{dir.Path}"") > #load ""a.csx"" @@ -689,7 +664,7 @@ public void SourceSearchPaths_Change1() ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( - @"(1,7): error CS1504: Source file 'a.csx' could not be opened -- Could not find file.", + $@"(1,7): error CS1504: { string.Format(CSharpResources.ERR_NoSourceFile, "a.csx", CSharpResources.CouldNotFindFile) }", runner.Console.Error.ToString()); } @@ -710,15 +685,12 @@ public void ReferenceSearchPaths_Change1() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences($@" -Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +{s_logoAndHelpPrompt} > ReferencePaths SearchPaths {{ }} > #r ""C.dll"" «Red» -(1,1): error CS0006: Metadata file 'C.dll' could not be found +(1,1): error CS0006: { string.Format(CSharpResources.ERR_NoMetadataFile, "C.dll") } «Gray» > ReferencePaths.Add(@""{dir.Path}"") > #r ""C.dll"" @@ -728,7 +700,7 @@ public void ReferenceSearchPaths_Change1() ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( - @"(1,1): error CS0006: Metadata file 'C.dll' could not be found", + $@"(1,1): error CS0006: { string.Format(CSharpResources.ERR_NoMetadataFile, "C.dll") }", runner.Console.Error.ToString()); } @@ -804,7 +776,7 @@ 1 1 AssertEx.AssertEqualToleratingWhitespaceDifferences($@" «Red» -{init.Path}(2,3): error CS1002: ; expected +{init.Path}(2,3): error CS1002: { CSharpResources.ERR_SemicolonExpected } «Gray» > new C() C {{ }} @@ -812,7 +784,7 @@ 1 1 ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( - $@"{init.Path}(2,3): error CS1002: ; expected", + $@"{init.Path}(2,3): error CS1002: { CSharpResources.ERR_SemicolonExpected }", runner.Console.Error.ToString()); } @@ -825,22 +797,9 @@ public void HelpCommand() runner.RunInteractive(); Assert.Equal( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > #help -Keyboard shortcuts: - Enter If the current submission appears to be complete, evaluate it. Otherwise, insert a new line. - Escape Clear the current submission. - UpArrow Replace the current submission with a previous submission. - DownArrow Replace the current submission with a subsequent submission (after having previously navigated backwards). - Ctrl-C Exit the REPL. -REPL commands: - #help Display help on available commands and key bindings. -Script directives: - #r Add a metadata reference to specified assembly and all its dependencies, e.g. #r ""myLib.dll"". - #load Load specified script file and execute it, e.g. #load ""myScript.csx"". +{ ScriptingResources.HelpText } > ", runner.Console.Out.ToString()); } @@ -902,16 +861,13 @@ public class Lib2 runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > #r ""{file1.Path}"" > var l1 = new Lib1(); > #r ""{file2.Path}"" > var l2 = new Lib2(); «Red» -Assembly '{libBaseName}, Version=0.0.0.0' has already been loaded from '{fileBase1.Path}'. A different assembly with the same name and version can't be loaded: '{fileBase2.Path}'. +{ string.Format(ScriptingResources.AssemblyAlreadyLoaded, libBaseName, "0.0.0.0", fileBase1.Path, fileBase2.Path) } «Gray» > ", runner.Console.Out.ToString()); } @@ -928,14 +884,11 @@ public void PreservingDeclarationsOnException() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > int i = 100; > int j = 20; throw new System.Exception(""Bang!""); int k = 3; «Yellow» -(1,58): warning CS0162: Unreachable code detected +(1,58): warning CS0162: { CSharpResources.WRN_UnreachableCode } «Red» Bang! «Gray» @@ -944,7 +897,7 @@ public void PreservingDeclarationsOnException() > ", runner.Console.Out.ToString()); AssertEx.AssertEqualToleratingWhitespaceDifferences( -@"(1,58): warning CS0162: Unreachable code detected +$@"(1,58): warning CS0162: { CSharpResources.WRN_UnreachableCode } Bang!", runner.Console.Error.ToString()); } @@ -960,10 +913,7 @@ public void DefaultLiteral() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. +$@"{s_logoAndHelpPrompt} > int i = default; > Print(i); 0 @@ -982,9 +932,9 @@ public void InferredTupleNames() runner.RunInteractive(); AssertEx.AssertEqualToleratingWhitespaceDifferences( -$@"Microsoft (R) Visual C# Interactive Compiler version {s_compilerVersion} -Copyright (C) Microsoft Corporation. All rights reserved. -Type ""#help"" for more information. +$@"{ string.Format(CSharpScriptingResources.LogoLine1, s_compilerVersion) } +{CSharpScriptingResources.LogoLine2} +{ScriptingResources.HelpPrompt} > var a = 1; > var t = (a, 2); > Print(t.a); diff --git a/src/Scripting/CSharpTest/ObjectFormatterTests.cs b/src/Scripting/CSharpTest/ObjectFormatterTests.cs index 89401c5130f15..07df563da2b96 100644 --- a/src/Scripting/CSharpTest/ObjectFormatterTests.cs +++ b/src/Scripting/CSharpTest/ObjectFormatterTests.cs @@ -272,7 +272,7 @@ public void DebuggerProxy_Recursive() str = s_formatter.FormatObject(obj, SeparateLinesOptions); // TODO: better overflow handling - Assert.Equal("!", str); + Assert.Equal(ScriptingResources.StackOverflowWhileEvaluating, str); } [Fact] diff --git a/src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb b/src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb index 6e3248711e3e4..b1948b8d63638 100644 --- a/src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb +++ b/src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb @@ -1,14 +1,14 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -Imports System.Reflection +Imports System.Globalization Imports System.IO +Imports System.Reflection Imports Microsoft.CodeAnalysis.Scripting Imports Microsoft.CodeAnalysis.Scripting.Hosting Imports Microsoft.CodeAnalysis.Scripting.Test Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.VisualBasic.Scripting.Hosting Imports Roslyn.Test.Utilities -Imports Roslyn.Utilities Imports Xunit Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting.UnitTests @@ -18,6 +18,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting.UnitTests Private Shared ReadOnly s_compilerVersion As String = GetType(VisualBasicInteractiveCompiler).GetTypeInfo().Assembly.GetCustomAttribute(Of AssemblyFileVersionAttribute)().Version + Private Shared ReadOnly s_logoAndHelpPrompt As String = + String.Format(VBScriptingResources.LogoLine1, s_compilerVersion) + vbNewLine + VBScriptingResources.LogoLine2 + " + +" + ScriptingResources.HelpPrompt Private Shared ReadOnly s_defaultArgs As String() = {"/R:System"} @@ -54,11 +58,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting.UnitTests runner.RunInteractive() - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic Interactive Compiler version " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. + AssertEx.AssertEqualToleratingWhitespaceDifferences(s_logoAndHelpPrompt + " > ? 10 10 >", runner.Console.Out.ToString()) @@ -70,11 +70,7 @@ Type ""#help"" for more information. runner.RunInteractive() - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic Interactive Compiler version " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. + AssertEx.AssertEqualToleratingWhitespaceDifferences(s_logoAndHelpPrompt + " >", runner.Console.Out.ToString()) End Sub @@ -91,11 +87,7 @@ End Class", "1").EmitToArray()) runner.RunInteractive() - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic Interactive Compiler version " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. + AssertEx.AssertEqualToleratingWhitespaceDifferences(s_logoAndHelpPrompt + " > #r """ & file1.Path & """ > ? New C1().Goo() ""Bar"" @@ -105,14 +97,10 @@ Type ""#help"" for more information. runner.RunInteractive() - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic Interactive Compiler version " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. + AssertEx.AssertEqualToleratingWhitespaceDifferences(s_logoAndHelpPrompt + " > ? New C1().Goo() «Red» -(1) : error BC30002: Type 'C1' is not defined. +(1) : error BC30002: " + String.Format(VBResources.ERR_UndefinedType1, "C1") + " «Gray» >", runner.Console.Out.ToString()) End Sub @@ -123,34 +111,33 @@ Type ""#help"" for more information. runner.RunInteractive() - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic Interactive Compiler version " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. All rights reserved. - -Type ""#help"" for more information. + AssertEx.AssertEqualToleratingWhitespaceDifferences(s_logoAndHelpPrompt + " > #r ""://invalidfilepath"" «Red» -(1) : error BC2017: could not find library '://invalidfilepath' +(1) : error BC2017: " + String.Format(ERR_LibNotFound, "://invalidfilepath") + " «Gray» >", runner.Console.Out.ToString()) End Sub - Public Sub TestDisplayResultsWithCurrentUICulture() - Dim runner = CreateRunner(args:={}, input:="Imports System.Globalization + Public Sub TestDisplayResultsWithCurrentUICulture1() + ' Save the current thread culture as it is changed in the test. + ' If the culture is not restored after the test all following tests + ' would run in the en-GB culture. + Dim currentCulture = CultureInfo.DefaultThreadCurrentCulture + Dim currentUICulture = CultureInfo.DefaultThreadCurrentUICulture + Try + Dim runner = CreateRunner(args:={}, input:="Imports System.Globalization System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(""en-GB"") ? System.Math.PI System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(""de-DE"") ? System.Math.PI") - runner.RunInteractive() - - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic Interactive Compiler version " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. All rights reserved. + runner.RunInteractive() -Type ""#help"" for more information. + AssertEx.AssertEqualToleratingWhitespaceDifferences( + s_logoAndHelpPrompt + " > Imports System.Globalization > System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(""en-GB"") > ? System.Math.PI @@ -159,22 +146,33 @@ Type ""#help"" for more information. > ? System.Math.PI 3,1415926535897931 >", runner.Console.Out.ToString()) + Finally + CultureInfo.DefaultThreadCurrentCulture = currentCulture + CultureInfo.DefaultThreadCurrentUICulture = currentUICulture + End Try + End Sub - ' Tests that DefaultThreadCurrentUICulture is respected and not DefaultThreadCurrentCulture. - runner = CreateRunner(args:={}, input:="Imports System.Globalization + + + Public Sub TestDisplayResultsWithCurrentUICulture2() + ' Save the current thread culture as it is changed in the test. + ' If the culture is not restored after the test all following tests + ' would run in the en-GB culture. + Dim currentCulture = CultureInfo.DefaultThreadCurrentCulture + Dim currentUICulture = CultureInfo.DefaultThreadCurrentUICulture + Try + ' Tests that DefaultThreadCurrentUICulture is respected and not DefaultThreadCurrentCulture. + Dim runner = CreateRunner(args:={}, input:="Imports System.Globalization System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(""en-GB"") System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(""en-GB"") ? System.Math.PI System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(""de-DE"") ? System.Math.PI") - runner.RunInteractive() - - AssertEx.AssertEqualToleratingWhitespaceDifferences( -"Microsoft (R) Visual Basic – interaktive Compilerversion " + s_compilerVersion + " -Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. + runner.RunInteractive() -Weitere Informationen erhalten Sie nach der Eingabe von ""#help"". + AssertEx.AssertEqualToleratingWhitespaceDifferences( +s_logoAndHelpPrompt + " > Imports System.Globalization > System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(""en-GB"") > System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(""en-GB"") @@ -184,6 +182,10 @@ Weitere Informationen erhalten Sie nach der Eingabe von ""#help"". > ? System.Math.PI 3.1415926535897931 >", runner.Console.Out.ToString()) + Finally + CultureInfo.DefaultThreadCurrentCulture = currentCulture + CultureInfo.DefaultThreadCurrentUICulture = currentUICulture + End Try End Sub