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.
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
{

View file

@ -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
{

View file

@ -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; }

View file

@ -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);

View file

@ -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<string, string> PreCompileScriptVariables { 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 command = new Mock<ICommand>();
@ -209,13 +209,21 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
var managedCompiler = new ManagedCompiler(_scriptRunner.Object, commandFactory.Object);
var rids = new List<string>();
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<string> rids)
public static ScriptVariablesFixture GetFixtureWithRids(string rid)
{
return new ScriptVariablesFixture(rids);
return new ScriptVariablesFixture(rid);
}
}
}

View file

@ -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",