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.
This commit is contained in:
Livar Cunha 2016-02-10 17:23:53 -08:00
parent 4e1ec4c159
commit e945361a76
6 changed files with 32 additions and 50 deletions

View file

@ -2,10 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.DotNet.Cli.Utils;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Compiler namespace Microsoft.DotNet.Cli.Utils
{ {
public class DotNetCommandFactory : ICommandFactory public class DotNetCommandFactory : ICommandFactory
{ {

View file

@ -2,10 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.DotNet.Cli.Utils;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Compiler namespace Microsoft.DotNet.Cli.Utils
{ {
public interface ICommandFactory public interface ICommandFactory
{ {

View file

@ -7,9 +7,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
public class OutputPaths public class OutputPaths
{ {
private string _compilationPath; private readonly string _runtimePath;
private string _intermediatePath;
private string _runtimePath;
private readonly RuntimeOutputFiles _runtimeFiles; private readonly RuntimeOutputFiles _runtimeFiles;
public OutputPaths(string intermediateOutputDirectoryPath, public OutputPaths(string intermediateOutputDirectoryPath,
@ -18,36 +16,16 @@ namespace Microsoft.DotNet.ProjectModel
CompilationOutputFiles compilationFiles, CompilationOutputFiles compilationFiles,
RuntimeOutputFiles runtimeFiles) RuntimeOutputFiles runtimeFiles)
{ {
RuntimeOutputPath = runtimePath; _runtimePath = runtimePath;
_runtimeFiles = runtimeFiles; _runtimeFiles = runtimeFiles;
CompilationOutputPath = compilationOutputPath; CompilationOutputPath = compilationOutputPath;
IntermediateOutputDirectoryPath = intermediateOutputDirectoryPath; IntermediateOutputDirectoryPath = intermediateOutputDirectoryPath;
CompilationFiles = compilationFiles; CompilationFiles = compilationFiles;
} }
public string CompilationOutputPath public string CompilationOutputPath { get; }
{
get
{
return _compilationPath;
}
private set
{
_compilationPath = value?.TrimEnd('\\');
}
}
public string IntermediateOutputDirectoryPath public string IntermediateOutputDirectoryPath { get; }
{
get
{
return _intermediatePath;
}
private set
{
_intermediatePath = value?.TrimEnd('\\');
}
}
public string RuntimeOutputPath public string RuntimeOutputPath
{ {
@ -58,13 +36,8 @@ namespace Microsoft.DotNet.ProjectModel
throw new InvalidOperationException( throw new InvalidOperationException(
$"Cannot get runtime output path for {nameof(OutputPaths)} with no runtime set"); $"Cannot get runtime output path for {nameof(OutputPaths)} with no runtime set");
} }
return _runtimePath; return _runtimePath;
} }
private set
{
_runtimePath = value?.TrimEnd('\\');
}
} }
public CompilationOutputFiles CompilationFiles { get; } public CompilationOutputFiles CompilationFiles { get; }

View file

@ -8,6 +8,7 @@ using System.Linq;
using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
namespace Microsoft.DotNet.Tools.Compiler namespace Microsoft.DotNet.Tools.Compiler
@ -137,13 +138,15 @@ namespace Microsoft.DotNet.Tools.Compiler
{ "compile:TargetFramework", context.TargetFramework.DotNetFrameworkName }, { "compile:TargetFramework", context.TargetFramework.DotNetFrameworkName },
{ "compile:Configuration", args.ConfigValue }, { "compile:Configuration", args.ConfigValue },
{ "compile:OutputFile", outputName }, { "compile:OutputFile", outputName },
{ "compile:OutputDir", outputPath }, { "compile:OutputDir", outputPath.TrimEnd('\\', '/') },
{ "compile:ResponseFile", rsp } { "compile:ResponseFile", rsp }
}; };
if (!string.IsNullOrEmpty(context.RuntimeIdentifier)) if (!string.IsNullOrEmpty(context.RuntimeIdentifier))
{ {
contextVariables.Add("compile:RuntimeOutputDir", outputPaths.RuntimeOutputPath); contextVariables.Add(
"compile:RuntimeOutputDir",
outputPaths.RuntimeOutputPath.TrimEnd('\\', '/'));
} }
_scriptRunner.RunScripts(context, ScriptNames.PreCompile, contextVariables); _scriptRunner.RunScripts(context, ScriptNames.PreCompile, contextVariables);

View file

@ -11,6 +11,7 @@ using Xunit;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using FluentAssertions; using FluentAssertions;
using System.Linq; using System.Linq;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Compiler.Tests namespace Microsoft.DotNet.Tools.Compiler.Tests
{ {
@ -68,10 +69,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact] [Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext() 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.Should().ContainKey("compile:RuntimeOutputDir");
fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be( fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir);
ScriptVariablesFixture.RuntimeOutputDir);
} }
[Fact] [Fact]
@ -126,10 +127,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact] [Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_set_in_the_ProjectContext() 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.Should().ContainKey("compile:RuntimeOutputDir");
fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be( fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir);
ScriptVariablesFixture.RuntimeOutputDir);
} }
} }
@ -149,7 +150,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
ConfigValue, ConfigValue,
"dnxcore50"); "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"); public static string OutputFile = Path.Combine(OutputPath, "TestApp.dll");
@ -163,12 +164,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
public Dictionary<string, string> PreCompileScriptVariables { get; private set; } public Dictionary<string, string> PreCompileScriptVariables { get; private set; }
public Dictionary<string, string> PostCompileScriptVariables { get; private set; } public Dictionary<string, string> PostCompileScriptVariables { get; private set; }
public ScriptVariablesFixture() : this(Enumerable.Empty<string>()) public ScriptVariablesFixture() : this(string.Empty)
{ {
} }
private ScriptVariablesFixture(IEnumerable<string> rids) private ScriptVariablesFixture(string rid)
{ {
var projectJson = Path.Combine(TestAssetPath, "project.json"); var projectJson = Path.Combine(TestAssetPath, "project.json");
var command = new Mock<ICommand>(); var command = new Mock<ICommand>();
@ -209,13 +209,21 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
var managedCompiler = new ManagedCompiler(_scriptRunner.Object, commandFactory.Object); var managedCompiler = new ManagedCompiler(_scriptRunner.Object, commandFactory.Object);
var context = ProjectContext.Create(projectJson, new NuGetFramework("dnxcore", new Version(5, 0)), rids); var rids = new List<string>();
managedCompiler.Compile(context, _args); if (!string.IsNullOrEmpty(rid))
{
rids.Add(rid);
} }
public static ScriptVariablesFixture GetFixtureWithRids(IEnumerable<string> rids) 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(string rid)
{ {
return new ScriptVariablesFixture(rids); return new ScriptVariablesFixture(rid);
} }
} }
} }

View file

@ -2,7 +2,7 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"NETStandard.Library": "1.0.0-rc2-23805", "NETStandard.Library": "1.0.0-rc2-23811",
"Microsoft.DotNet.Cli.Utils": { "Microsoft.DotNet.Cli.Utils": {
"target": "project", "target": "project",