From 5c8ef5758555b8501aacb110bdf350b575938a1f Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 22 Apr 2016 14:20:50 -0500 Subject: [PATCH 1/3] Adding all code pages for dotnet CLI. Since we write to the console and create new processes and read from their stdout and stderr, we need to ensure we have all the code pages in our process. This way we can encode/decode strings correctly when writing to our Console, and when reading from spawned process's output. Fix #2486 --- src/dotnet/Program.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 2ecbed88b..1ab628b14 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel.Server; using Microsoft.DotNet.Tools.Build; @@ -41,6 +42,8 @@ namespace Microsoft.DotNet.Cli { DebugHelper.HandleDebugSwitch(ref args); + InitializeProcess(); + try { return Program.ProcessArgs(args, new Telemetry()); @@ -138,6 +141,13 @@ namespace Microsoft.DotNet.Cli } + private static void InitializeProcess() + { + // by default, .NET Core doesn't have all code pages needed for Console apps. + // see the .NET Core Notes in https://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + } + internal static bool TryGetBuiltInCommand(string commandName, out Func builtInCommand) { return s_builtIns.TryGetValue(commandName, out builtInCommand); From 7a7b524b34f2bf342789936ab04026ecd687fbb0 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Wed, 20 Apr 2016 12:43:34 -0700 Subject: [PATCH 2/3] add tests for a test app with unicode characters in the path --- .../TestAppWithUnicodéPath/Program.cs | 12 +++++ .../TestAppWithUnicodéPath/project.json | 22 +++++++++ .../ArgumentForwardingTests.cs | 1 + .../GivenDotnetBuildBuildsProjects.cs | 46 +++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs create mode 100644 TestAssets/TestProjects/TestAppWithUnicodéPath/project.json create mode 100644 test/dotnet-build.Tests/GivenDotnetBuildBuildsProjects.cs diff --git a/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs b/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs new file mode 100644 index 000000000..51233cffa --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnicodéPath/project.json b/TestAssets/TestProjects/TestAppWithUnicodéPath/project.json new file mode 100644 index 000000000..0c076f5f1 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnicodéPath/project.json @@ -0,0 +1,22 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + "dependencies": { + "Microsoft.NETCore.App": "1.0.0-rc2-*" + }, + "frameworks": { + "netcoreapp1.0": { } + }, + "runtimes": { + "win7-x64": {}, + "win7-x86": {}, + "osx.10.10-x64": {}, + "osx.10.11-x64": {}, + "ubuntu.14.04-x64": {}, + "centos.7-x64": {}, + "rhel.7.2-x64": {}, + "debian.8-x64": {} + } +} diff --git a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs index 95be0edaa..ed08e45bf 100644 --- a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs +++ b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs @@ -51,6 +51,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding /// [Theory] [InlineData(@"""abc"" d e")] + [InlineData(@"""ábc"" d é")] [InlineData(@"""abc"" d e")] [InlineData("\"abc\"\t\td\te")] [InlineData(@"a\\b d""e f""g h")] diff --git a/test/dotnet-build.Tests/GivenDotnetBuildBuildsProjects.cs b/test/dotnet-build.Tests/GivenDotnetBuildBuildsProjects.cs new file mode 100644 index 000000000..d05471455 --- /dev/null +++ b/test/dotnet-build.Tests/GivenDotnetBuildBuildsProjects.cs @@ -0,0 +1,46 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace Microsoft.DotNet.Tools.Builder.Tests +{ + public class GivenDotnetBuildBuildsProjects : TestBase + { + [Fact] + public void It_builds_projects_with_Unicode_in_path() + { + var testInstance = TestAssetsManager + .CreateTestInstance("TestAppWithUnicodéPath") + .WithLockFiles(); + + var testProjectDirectory = testInstance.TestRoot; + + var buildCommand = new BuildCommand(""); + buildCommand.WorkingDirectory = testProjectDirectory; + + buildCommand.ExecuteWithCapturedOutput() + .Should() + .Pass(); + } + + [Fact] + public void It_builds_projects_with_Unicode_in_path_project_path_passed() + { + var testInstance = TestAssetsManager + .CreateTestInstance("TestAppWithUnicodéPath") + .WithLockFiles(); + + var testProject = Path.Combine(testInstance.TestRoot, "project.json"); + + new BuildCommand(testProject) + .ExecuteWithCapturedOutput() + .Should() + .Pass(); + } + } +} From c60abb0d0ad2be238bb14db5ae5405e7023c5dd0 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 25 Apr 2016 11:04:23 -0500 Subject: [PATCH 3/3] Adding a dotnet run test that outputs unicode characters. --- .../TestProjects/TestAppWithUnicodéPath/Program.cs | 2 +- test/dotnet-run.Tests/RunTests.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs b/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs index 51233cffa..dcdd3eaa1 100644 --- a/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs +++ b/TestAssets/TestProjects/TestAppWithUnicodéPath/Program.cs @@ -6,7 +6,7 @@ namespace ConsoleApplication { public static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Console.WriteLine("Hélló Wórld!"); } } } diff --git a/test/dotnet-run.Tests/RunTests.cs b/test/dotnet-run.Tests/RunTests.cs index b41ecce8b..41de0dd2e 100644 --- a/test/dotnet-run.Tests/RunTests.cs +++ b/test/dotnet-run.Tests/RunTests.cs @@ -68,6 +68,19 @@ namespace Microsoft.DotNet.Tools.Run.Tests new RunCommand(instance.TestRoot).Execute().Should().Pass(); } + [Fact] + public void ItRunsAppsThatOutputUnicodeCharacters() + { + TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithUnicodéPath") + .WithLockFiles() + .WithBuildArtifacts(); + new RunCommand(instance.TestRoot) + .ExecuteWithCapturedOutput() + .Should() + .Pass() + .And + .HaveStdOutContaining("Hélló Wórld!"); + } private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir) {