From e945361a76f4b00b3291a134c93a7560f9b0c8e4 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Wed, 10 Feb 2016 17:23:53 -0800 Subject: [PATCH] Replacing the fixed rid in the dotnet compile unit test by one that respects the platform where the tests are running. Removing trailing slashes for the paths passed to the scripts to avoid the double quotes escaped issue. --- .../DotNetCommandFactory.cs | 3 +- .../ICommandFactory.cs | 3 +- .../OutputPaths.cs | 35 +++---------------- .../dotnet-compile/ManagedCompiler.cs | 7 ++-- ...boutScriptVariablesFromAManagedCompiler.cs | 32 ++++++++++------- test/dotnet-compile.UnitTests/project.json | 2 +- 6 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/DotNetCommandFactory.cs b/src/Microsoft.DotNet.Cli.Utils/DotNetCommandFactory.cs index 1de259450..ba48a29d9 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DotNetCommandFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/DotNetCommandFactory.cs @@ -2,10 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; -using Microsoft.DotNet.Cli.Utils; using NuGet.Frameworks; -namespace Microsoft.DotNet.Tools.Compiler +namespace Microsoft.DotNet.Cli.Utils { public class DotNetCommandFactory : ICommandFactory { diff --git a/src/Microsoft.DotNet.Cli.Utils/ICommandFactory.cs b/src/Microsoft.DotNet.Cli.Utils/ICommandFactory.cs index beef29393..ae6beddee 100644 --- a/src/Microsoft.DotNet.Cli.Utils/ICommandFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ICommandFactory.cs @@ -2,10 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; -using Microsoft.DotNet.Cli.Utils; using NuGet.Frameworks; -namespace Microsoft.DotNet.Tools.Compiler +namespace Microsoft.DotNet.Cli.Utils { public interface ICommandFactory { diff --git a/src/Microsoft.DotNet.ProjectModel/OutputPaths.cs b/src/Microsoft.DotNet.ProjectModel/OutputPaths.cs index ee37b05c0..2628032d3 100644 --- a/src/Microsoft.DotNet.ProjectModel/OutputPaths.cs +++ b/src/Microsoft.DotNet.ProjectModel/OutputPaths.cs @@ -7,9 +7,7 @@ namespace Microsoft.DotNet.ProjectModel { public class OutputPaths { - private string _compilationPath; - private string _intermediatePath; - private string _runtimePath; + private readonly string _runtimePath; private readonly RuntimeOutputFiles _runtimeFiles; public OutputPaths(string intermediateOutputDirectoryPath, @@ -18,36 +16,16 @@ namespace Microsoft.DotNet.ProjectModel CompilationOutputFiles compilationFiles, RuntimeOutputFiles runtimeFiles) { - RuntimeOutputPath = runtimePath; + _runtimePath = runtimePath; _runtimeFiles = runtimeFiles; CompilationOutputPath = compilationOutputPath; IntermediateOutputDirectoryPath = intermediateOutputDirectoryPath; CompilationFiles = compilationFiles; } - public string CompilationOutputPath - { - get - { - return _compilationPath; - } - private set - { - _compilationPath = value?.TrimEnd('\\'); - } - } + public string CompilationOutputPath { get; } - public string IntermediateOutputDirectoryPath - { - get - { - return _intermediatePath; - } - private set - { - _intermediatePath = value?.TrimEnd('\\'); - } - } + public string IntermediateOutputDirectoryPath { get; } public string RuntimeOutputPath { @@ -58,13 +36,8 @@ namespace Microsoft.DotNet.ProjectModel throw new InvalidOperationException( $"Cannot get runtime output path for {nameof(OutputPaths)} with no runtime set"); } - return _runtimePath; } - private set - { - _runtimePath = value?.TrimEnd('\\'); - } } public CompilationOutputFiles CompilationFiles { get; } diff --git a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs index 3ff360eed..40280dd62 100644 --- a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs +++ b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs @@ -8,6 +8,7 @@ using System.Linq; using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.Extensions.DependencyModel; namespace Microsoft.DotNet.Tools.Compiler @@ -137,13 +138,15 @@ namespace Microsoft.DotNet.Tools.Compiler { "compile:TargetFramework", context.TargetFramework.DotNetFrameworkName }, { "compile:Configuration", args.ConfigValue }, { "compile:OutputFile", outputName }, - { "compile:OutputDir", outputPath }, + { "compile:OutputDir", outputPath.TrimEnd('\\', '/') }, { "compile:ResponseFile", rsp } }; if (!string.IsNullOrEmpty(context.RuntimeIdentifier)) { - contextVariables.Add("compile:RuntimeOutputDir", outputPaths.RuntimeOutputPath); + contextVariables.Add( + "compile:RuntimeOutputDir", + outputPaths.RuntimeOutputPath.TrimEnd('\\', '/')); } _scriptRunner.RunScripts(context, ScriptNames.PreCompile, contextVariables); diff --git a/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs b/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs index 28c79d595..88ef37190 100644 --- a/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs +++ b/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs @@ -11,6 +11,7 @@ using Xunit; using Microsoft.DotNet.Cli.Utils; using FluentAssertions; using System.Linq; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Compiler.Tests { @@ -68,10 +69,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests [Fact] public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext() { - var fixture = ScriptVariablesFixture.GetFixtureWithRids(new[] { "win7-x64" }); + var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid); fixture.PreCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); - fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be( - ScriptVariablesFixture.RuntimeOutputDir); + fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); } [Fact] @@ -126,10 +127,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests [Fact] public void It_passes_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_set_in_the_ProjectContext() { - var fixture = ScriptVariablesFixture.GetFixtureWithRids(new [] { "win7-x64" }); + var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid); fixture.PostCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); - fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be( - ScriptVariablesFixture.RuntimeOutputDir); + fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); } } @@ -149,7 +150,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests ConfigValue, "dnxcore50"); - public static string RuntimeOutputDir = Path.Combine(OutputPath, "win7-x64"); + public string RuntimeOutputDir { get; private set; } public static string OutputFile = Path.Combine(OutputPath, "TestApp.dll"); @@ -163,12 +164,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests public Dictionary PreCompileScriptVariables { get; private set; } public Dictionary PostCompileScriptVariables { get; private set; } - public ScriptVariablesFixture() : this(Enumerable.Empty()) + public ScriptVariablesFixture() : this(string.Empty) { - } - private ScriptVariablesFixture(IEnumerable rids) + private ScriptVariablesFixture(string rid) { var projectJson = Path.Combine(TestAssetPath, "project.json"); var command = new Mock(); @@ -209,13 +209,21 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests var managedCompiler = new ManagedCompiler(_scriptRunner.Object, commandFactory.Object); + var rids = new List(); + if (!string.IsNullOrEmpty(rid)) + { + rids.Add(rid); + } + var context = ProjectContext.Create(projectJson, new NuGetFramework("dnxcore", new Version(5, 0)), rids); managedCompiler.Compile(context, _args); + + RuntimeOutputDir = Path.Combine(OutputPath, rid); } - public static ScriptVariablesFixture GetFixtureWithRids(IEnumerable rids) + public static ScriptVariablesFixture GetFixtureWithRids(string rid) { - return new ScriptVariablesFixture(rids); + return new ScriptVariablesFixture(rid); } } } diff --git a/test/dotnet-compile.UnitTests/project.json b/test/dotnet-compile.UnitTests/project.json index 9e10a2a79..3ecadbe2d 100644 --- a/test/dotnet-compile.UnitTests/project.json +++ b/test/dotnet-compile.UnitTests/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { - "NETStandard.Library": "1.0.0-rc2-23805", + "NETStandard.Library": "1.0.0-rc2-23811", "Microsoft.DotNet.Cli.Utils": { "target": "project",