Merge branch 'rel/1.0.0' of https://github.com/dotnet/cli into test-fx

Conflicts:
	Microsoft.DotNet.Cli.sln
	scripts/dockerbuild.sh
	scripts/test/setup/build-test-prerequisites.ps1
	test/dotnet-build.Tests/IncrementalTestBase.cs
	test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs
	test/dotnet-publish.Tests/project.json
This commit is contained in:
Sridhar Periyasamy 2016-02-12 17:26:58 -08:00
commit 2a94a1e384
184 changed files with 5025 additions and 3052 deletions

View file

@ -18,7 +18,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
{
public class ArgumentForwardingTests : TestBase
{
private static readonly string s_reflectorExeName = "Reflector" + Constants.ExeSuffix;
private static readonly string s_reflectorExeName = "ArgumentsReflector" + Constants.ExeSuffix;
private static readonly string s_reflectorCmdName = "reflector_cmd";
private string ReflectorPath { get; set; }
@ -28,7 +28,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
{
Console.WriteLine("Dummy Entrypoint.");
}
public ArgumentForwardingTests()
{
// This test has a dependency on an argument reflector
@ -94,16 +94,12 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
[InlineData("\"abc\"\t\td\te")]
[InlineData(@"a\\b d""e f""g h")]
[InlineData(@"\ \\ \\\")]
[InlineData(@"a\""b c d")]
[InlineData(@"a\\""b c d")]
[InlineData(@"a\\\""b c d")]
[InlineData(@"a\\\\""b c d")]
[InlineData(@"a\\\\""b c d")]
[InlineData(@"a\\\\""b c"" d e")]
[InlineData(@"a""b c""d e""f g""h i""j k""l")]
[InlineData(@"a b c""def")]
[InlineData(@"""\a\"" \\""\\\ b c")]
[InlineData(@"a\""b \\ cd ""\e f\"" \\""\\\")]
public void TestArgumentForwardingCmd(string testUserArgument)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@ -139,7 +135,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
{
var rawArg = rawEvaluatedArgument[i];
var escapedArg = escapedEvaluatedRawArgument[i];
try
{
rawArg.Should().Be(escapedArg);
@ -153,10 +149,33 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
}
}
[Theory]
[InlineData(@"a\""b c d")]
[InlineData(@"a\\\""b c d")]
[InlineData(@"""\a\"" \\""\\\ b c")]
[InlineData(@"a\""b \\ cd ""\e f\"" \\""\\\")]
public void TestArgumentForwardingCmdFailsWithUnbalancedQuote(string testArgString)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}
// Get Baseline Argument Evaluation via Reflector
// This does not need to be different for cmd because
// it only establishes what the string[] args should be
var rawEvaluatedArgument = RawEvaluateArgumentString(testArgString);
// Escape and Re-Evaluate the rawEvaluatedArgument
var escapedEvaluatedRawArgument = EscapeAndEvaluateArgumentStringCmd(rawEvaluatedArgument);
rawEvaluatedArgument.Length.Should().NotBe(escapedEvaluatedRawArgument.Length);
}
/// <summary>
/// EscapeAndEvaluateArgumentString returns a representation of string[] args
/// when rawEvaluatedArgument is passed as an argument to a process using
/// Command.Create(). Ideally this should escape the argument such that
/// Command.Create(). Ideally this should escape the argument such that
/// the output is == rawEvaluatedArgument.
/// </summary>
/// <param name="rawEvaluatedArgument">A string[] representing string[] args as already evaluated by a process</param>
@ -176,7 +195,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
/// <summary>
/// EscapeAndEvaluateArgumentString returns a representation of string[] args
/// when rawEvaluatedArgument is passed as an argument to a process using
/// Command.Create(). Ideally this should escape the argument such that
/// Command.Create(). Ideally this should escape the argument such that
/// the output is == rawEvaluatedArgument.
/// </summary>
/// <param name="rawEvaluatedArgument">A string[] representing string[] args as already evaluated by a process</param>
@ -199,7 +218,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
/// <summary>
/// Parse the output of the reflector into a string array.
/// Reflector output is simply string[] args written to
/// Reflector output is simply string[] args written to
/// one string separated by commas.
/// </summary>
/// <param name="reflectorOutput"></param>
@ -211,7 +230,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
/// <summary>
/// Parse the output of the reflector into a string array.
/// Reflector output is simply string[] args written to
/// Reflector output is simply string[] args written to
/// one string separated by commas.
/// </summary>
/// <param name="reflectorOutput"></param>
@ -243,7 +262,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding
{
StartInfo = new ProcessStartInfo
{
FileName = s_reflectorExeName,
FileName = ReflectorPath,
Arguments = testUserArgument,
UseShellExecute = false,
RedirectStandardOutput = true,

View file

@ -1,26 +0,0 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library" : "1.0.0-rc2-23811",
"Microsoft.NETCore.TestHost": "1.0.0-rc2-23811",
"xunit": "2.1.0",
"xunit.console.netcore": "1.0.2-prerelease-00101",
"xunit.netcore.extensions": "1.0.0-prerelease-00153",
"xunit.runner.utility": "2.1.0",
"Microsoft.DotNet.ProjectModel": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": { "target": "project" },
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" }
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
}
}

View file

@ -6,21 +6,22 @@
"dependencies": {
"NETStandard.Library" : "1.0.0-rc2-23811",
"Microsoft.NETCore.TestHost": "1.0.0-rc2-23811",
"xunit": "2.1.0",
"xunit.console.netcore": "1.0.2-prerelease-00101",
"xunit.netcore.extensions": "1.0.0-prerelease-00153",
"xunit.runner.utility": "2.1.0",
"Microsoft.DotNet.ProjectModel": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": { "target": "project" },
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" }
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-dev-48273-16"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
}
},
"testRunner": "xunit",
"scripts": { "precompile": "dotnet build ../ArgumentsReflector/project.json --framework dnxcore50 --output %compile:RuntimeOutputDir%" }
}

View file

@ -2,17 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Diagnostics;
using FluentAssertions;
namespace Microsoft.DotNet.Tests.ArgumentForwarding
{

View file

@ -0,0 +1,18 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library" : "1.0.0-rc2-23811"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
},
"content": ["reflector_cmd.cmd"]
}

View file

@ -16,7 +16,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
private static readonly string s_expectedOutput = "Hello World!" + Environment.NewLine;
private static readonly string s_testdirName = "e2etestroot";
private static readonly string s_outputdirName = "test space/bin";
private static string RestoredTestProjectDirectory { get; set; }
private string Rid { get; set; }
@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
{
Console.WriteLine("Dummy Entrypoint.");
}
public EndToEndTest()
{
TestInstanceSetup();
@ -192,7 +192,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
{
Directory.Delete(RestoredTestProjectDirectory, true);
}
catch(Exception e) {}
catch(Exception) {}
Directory.CreateDirectory(RestoredTestProjectDirectory);
@ -231,4 +231,4 @@ namespace Microsoft.DotNet.Tests.EndToEnd
File.SetLastWriteTimeUtc(csFile, DateTime.UtcNow);
}
}
}
}

View file

@ -26,6 +26,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string _cppCompilerFlags;
private bool _buildProfile;
private bool _noIncremental;
private bool _noDependencies;
private string OutputOption
{
@ -166,6 +167,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
}
}
private string NoDependencies
{
get
{
return _noDependencies ?
"--no-dependencies" :
"";
}
}
public BuildCommand(
string projectPath,
string output="",
@ -181,11 +192,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
bool nativeCppMode=false,
string cppCompilerFlags="",
bool buildProfile=true,
bool noIncremental=false
bool noIncremental=false,
bool noDependencies=false
)
: base("dotnet")
{
_projectPath = projectPath;
_project = ProjectReader.GetProject(projectPath);
@ -203,6 +214,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
_cppCompilerFlags = cppCompilerFlags;
_buildProfile = buildProfile;
_noIncremental = noIncremental;
_noDependencies = noDependencies;
}
public override CommandResult Execute(string args = "")
@ -226,7 +238,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string BuildArgs()
{
return $"{BuildProfile} {NoIncremental} \"{_projectPath}\" {OutputOption} {BuildBasePathOption} {ConfigurationOption} {FrameworkOption} {NoHostOption} {NativeOption} {ArchitectureOption} {IlcArgsOption} {IlcPathOption} {AppDepSDKPathOption} {NativeCppModeOption} {CppCompilerFlagsOption}";
return $"{BuildProfile} {NoDependencies} {NoIncremental} \"{_projectPath}\" {OutputOption} {BuildBasePathOption} {ConfigurationOption} {FrameworkOption} {NoHostOption} {NativeOption} {ArchitectureOption} {IlcArgsOption} {IlcPathOption} {AppDepSDKPathOption} {NativeCppModeOption} {CppCompilerFlagsOption}";
}
}
}

View file

@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
if (!Path.IsPathRooted(_command))
{
_command = Env.GetCommandPath(_command) ??
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command);
Env.GetCommandPathFromRootPath(AppContext.BaseDirectory, _command);
}
Console.WriteLine($"Executing - {_command} {args}");
@ -43,7 +43,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
Console.WriteLine($"Executing (Captured Output) - {_command} {args}");
var commandPath = Env.GetCommandPath(_command, ".exe", ".cmd", "") ??
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");
Env.GetCommandPathFromRootPath(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");
var stdOut = new StreamForwarder();
var stdErr = new StreamForwarder();

View file

@ -0,0 +1,155 @@
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using System.Runtime.InteropServices;
using Xunit;
using FluentAssertions;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
{
public class ScriptExecutorTests : TestBase
{
private static readonly string s_testProjectRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects");
private TempDirectory _root;
private string binTestProjectPath;
private Project project;
public ScriptExecutorTests()
{
_root = Temp.CreateDirectory();
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
}
[Fact]
public void Test_Project_Local_Script_is_Resolved()
{
CreateTestFile("some.script", binTestProjectPath);
var scriptCommandLine = "some.script";
var command = ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
command.Should().NotBeNull();
command.ResolutionStrategy.Should().Be(CommandResolutionStrategy.ProjectLocal);
}
[Fact]
public void Test_Nonexistent_Project_Local_Script_throws_CommandUnknownException()
{
var scriptCommandLine = "nonexistent.script";
Action action = () => ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
action.ShouldThrow<CommandUnknownException>();
}
[Fact]
public void Test_Extension_sh_is_Inferred_over_cmd_in_Project_Local_Scripts_on_Unix()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}
var extensionList = new string[] { ".cmd", ".sh" };
var expectedExtension = ".sh";
foreach (var extension in extensionList)
{
CreateTestFile("uniquescriptname" + extension, binTestProjectPath);
}
// Don't include extension
var scriptCommandLine = "uniquescriptname";
var command = ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
command.Should().NotBeNull();
command.ResolutionStrategy.Should().Be(CommandResolutionStrategy.ProjectLocal);
command.CommandArgs.Should().Contain(scriptCommandLine + expectedExtension);
}
[Fact]
public void Test_Extension_cmd_is_Inferred_over_sh_in_Project_Local_Scripts_on_Windows()
{
if (! RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}
var extensionList = new string[] { ".cmd", ".sh" };
var expectedExtension = ".cmd";
foreach (var extension in extensionList)
{
CreateTestFile("uniquescriptname" + extension, binTestProjectPath);
}
// Don't include extension
var scriptCommandLine = "uniquescriptname";
var command = ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
command.Should().NotBeNull();
command.ResolutionStrategy.Should().Be(CommandResolutionStrategy.ProjectLocal);
command.CommandArgs.Should().Contain(scriptCommandLine + expectedExtension);
}
[Fact]
public void Test_Script_Exe_Files_Dont_Use_Cmd_or_Sh()
{
CreateTestFile("some.exe", binTestProjectPath);
var scriptCommandLine = "some.exe";
var command = ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
command.Should().NotBeNull();
command.ResolutionStrategy.Should().Be(CommandResolutionStrategy.ProjectLocal);
Path.GetFileName(command.CommandName).Should().NotBe("cmd.exe");
Path.GetFileName(command.CommandName).Should().NotBe("sh");
}
[Fact]
public void Test_Script_Cmd_Files_Use_CmdExe()
{
if (! RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}
CreateTestFile("some.cmd", binTestProjectPath);
var scriptCommandLine = "some.cmd";
var command = ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
command.Should().NotBeNull();
command.ResolutionStrategy.Should().Be(CommandResolutionStrategy.ProjectLocal);
Path.GetFileName(command.CommandName).Should().Be("cmd.exe");
}
[Fact]
public void Test_Script_Builtins_throws_CommandUnknownException()
{
var scriptCommandLine = "echo";
Action action = () => ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
action.ShouldThrow<CommandUnknownException>();
}
private void CreateTestFile(string filename, string directory)
{
string path = Path.Combine(directory, filename);
File.WriteAllText(path, "echo hello");
}
}
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>833ffee1-7eed-4f51-8dfd-946d48833333</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Cli.Utils.ScriptExecutorTests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,26 @@
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23805",
"Microsoft.DotNet.ProjectModel": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": { "target": "project" },
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-dev-48273-16"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
},
"content": [
"../../TestAssets/TestProjects/TestApp/**/*"
],
"testRunner": "xunit"
}

View file

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
@ -14,7 +15,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class ProjectToProjectDependenciesIncrementalTest : IncrementalTestBase
{
private string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
private readonly string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
private string MainProjectExe
{
@ -58,6 +59,38 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
AssertRebuilt(result3, expectedRebuiltProjects);
}
[Fact]
public void TestNoDependencyFlag()
{
var dependencies = new[] { "L11", "L12", "L21", "L22" };
// first clean build; all projects required compilation
var result1 = BuildProject();
AssertRebuilt(result1, _projects);
// modify the source code of a leaf dependency
TouchSourcesOfProject("L22");
// second build with no dependencies and no incremental; only the root rebuilds
var result2 = BuildProject(noDependencies: true, noIncremental: true);
result2.Should().StdOutMatchPattern("Compiling.*L0.*");
AssertResultDoesNotContainStrings(result2, dependencies);
// third build with no dependencies but incremental; nothing rebuilds
var result3 = BuildProject(noDependencies: true);
result3.Should().HaveSkippedProjectCompilation("L0");
AssertResultDoesNotContainStrings(result3, dependencies);
}
private static void AssertResultDoesNotContainStrings(CommandResult commandResult, string[] strings)
{
foreach (var s in strings)
{
commandResult.StdOut.Should().NotContain(s);
}
}
// compute A - B
private T[] SetDifference<T>(T[] A, T[] B)
{

View file

@ -58,15 +58,15 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
File.SetLastWriteTimeUtc(file, DateTime.UtcNow);
}
protected CommandResult BuildProject(bool noIncremental = false, bool expectBuildFailure = false)
protected CommandResult BuildProject(bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
{
var mainProjectFile = GetProjectFile(MainProject);
return BuildProject(mainProjectFile, noIncremental, expectBuildFailure);
}
protected CommandResult BuildProject(string projectFile, bool noIncremental = false, bool expectBuildFailure = false)
protected CommandResult BuildProject(string projectFile, bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
{
var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "dnxcore50", noIncremental: noIncremental);
var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "dnxcore50", noIncremental: noIncremental, noDependencies : noDependencies);
var result = buildCommand.ExecuteWithCapturedOutput();
if (!expectBuildFailure)

View file

@ -0,0 +1,83 @@
// 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.Collections.Generic;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Compiler;
using Moq;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Tools.Compiler.Tests
{
public class GivenACompilationDriverController
{
private string _projectJson;
private Mock<ICompiler> _managedCompilerMock;
private Mock<ICompiler> _nativeCompilerMock;
private List<ProjectContext> _contexts;
private CompilerCommandApp _args;
public GivenACompilationDriverController()
{
_projectJson =
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestApp", "project.json");
_managedCompilerMock = new Mock<ICompiler>();
_managedCompilerMock.Setup(c => c
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
.Returns(true);
_nativeCompilerMock = new Mock<ICompiler>();
_nativeCompilerMock.Setup(c => c
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
.Returns(true);
_contexts = new List<ProjectContext>
{
ProjectContext.Create(_projectJson, new NuGetFramework(string.Empty))
};
_args = new CompilerCommandApp("dotnet compile", ".NET Compiler", "Compiler for the .NET Platform");
}
[Fact]
public void It_compiles_all_project_contexts()
{
var compiledProjectContexts = new List<ProjectContext>();
_managedCompilerMock.Setup(c => c
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
.Callback<ProjectContext, CompilerCommandApp>((p, c) => compiledProjectContexts.Add(p))
.Returns(true);
var compilerController = new CompilationDriver(_managedCompilerMock.Object, _nativeCompilerMock.Object);
compilerController.Compile(_contexts, _args);
compiledProjectContexts.Should().BeEquivalentTo(_contexts);
}
[Fact]
public void It_does_not_compile_native_when_the_native_parameter_is_not_passed()
{
var compilerController = new CompilationDriver(_managedCompilerMock.Object, _nativeCompilerMock.Object);
compilerController.Compile(_contexts, _args);
_nativeCompilerMock.Verify(c => c.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()), Times.Never);
}
[Fact]
public void It_does_compile_native_when_the_native_parameter_is_passed()
{
var compilerController = new CompilationDriver(_managedCompilerMock.Object, _nativeCompilerMock.Object);
_args.IsNativeValue = true;
compilerController.Compile(_contexts, _args);
_nativeCompilerMock.Verify(c => c.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()), Times.Once);
}
}
}

View file

@ -0,0 +1,242 @@
// 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.Collections.Generic;
using System.IO;
using Microsoft.DotNet.ProjectModel;
using Moq;
using NuGet.Frameworks;
using Xunit;
using Microsoft.DotNet.Cli.Utils;
using FluentAssertions;
using System.Linq;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Compiler.Tests
{
public class GivenThatICareAboutScriptVariablesFromAManagedCompiler : IClassFixture<ScriptVariablesFixture>
{
private readonly ScriptVariablesFixture _fixture;
public GivenThatICareAboutScriptVariablesFromAManagedCompiler(ScriptVariablesFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void It_passes_a_FullTargetFramework_variable_to_the_pre_compile_scripts()
{
_fixture.PreCompileScriptVariables.Should().ContainKey("compile:FullTargetFramework");
_fixture.PreCompileScriptVariables["compile:FullTargetFramework"].Should().Be("dnxcore,Version=v5.0");
}
[Fact]
public void It_passes_a_TargetFramework_variable_to_the_pre_compile_scripts()
{
_fixture.PreCompileScriptVariables.Should().ContainKey("compile:TargetFramework");
_fixture.PreCompileScriptVariables["compile:TargetFramework"].Should().Be("dnxcore50");
}
[Fact]
public void It_passes_a_Configuration_variable_to_the_pre_compile_scripts()
{
_fixture.PreCompileScriptVariables.Should().ContainKey("compile:Configuration");
_fixture.PreCompileScriptVariables["compile:Configuration"].Should().Be(
ScriptVariablesFixture.ConfigValue);
}
[Fact]
public void It_passes_a_OutputFile_variable_to_the_pre_compile_scripts()
{
_fixture.PreCompileScriptVariables.Should().ContainKey("compile:OutputFile");
_fixture.PreCompileScriptVariables["compile:OutputFile"].Should().Be(ScriptVariablesFixture.OutputFile);
}
[Fact]
public void It_passes_a_OutputDir_variable_to_the_pre_compile_scripts()
{
_fixture.PreCompileScriptVariables.Should().ContainKey("compile:OutputDir");
_fixture.PreCompileScriptVariables["compile:OutputDir"].Should().Be(ScriptVariablesFixture.OutputPath);
}
[Fact]
public void It_passes_a_ResponseFile_variable_to_the_pre_compile_scripts()
{
_fixture.PreCompileScriptVariables.Should().ContainKey("compile:ResponseFile");
_fixture.PreCompileScriptVariables["compile:ResponseFile"].Should().Be(ScriptVariablesFixture.ResponseFile);
}
[Fact]
public void It_does_not_pass_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_not_set_in()
{
_fixture.PreCompileScriptVariables.Should().NotContainKey("compile:RuntimeOutputDir");
}
[Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext()
{
var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid);
fixture.PreCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir");
fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir);
}
[Fact]
public void It_passes_a_FullTargetFramework_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:FullTargetFramework");
_fixture.PostCompileScriptVariables["compile:FullTargetFramework"].Should().Be("dnxcore,Version=v5.0");
}
[Fact]
public void It_passes_a_TargetFramework_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:TargetFramework");
_fixture.PostCompileScriptVariables["compile:TargetFramework"].Should().Be("dnxcore50");
}
[Fact]
public void It_passes_a_Configuration_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:Configuration");
_fixture.PostCompileScriptVariables["compile:Configuration"].Should().Be(
ScriptVariablesFixture.ConfigValue);
}
[Fact]
public void It_passes_a_OutputFile_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:OutputFile");
_fixture.PostCompileScriptVariables["compile:OutputFile"].Should().Be(ScriptVariablesFixture.OutputFile);
}
[Fact]
public void It_passes_a_OutputDir_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:OutputDir");
_fixture.PostCompileScriptVariables["compile:OutputDir"].Should().Be(ScriptVariablesFixture.OutputPath);
}
[Fact]
public void It_passes_a_ResponseFile_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:ResponseFile");
_fixture.PostCompileScriptVariables["compile:ResponseFile"].Should().Be(ScriptVariablesFixture.ResponseFile);
}
[Fact]
public void It_passes_a_CompilerExitCode_variable_to_the_post_compile_scripts()
{
_fixture.PostCompileScriptVariables.Should().ContainKey("compile:CompilerExitCode");
_fixture.PostCompileScriptVariables["compile:CompilerExitCode"].Should().Be("0");
}
[Fact]
public void It_does_not_pass_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_not_set_in_the_ProjectContext()
{
_fixture.PostCompileScriptVariables.Should().NotContainKey("compile:RuntimeOutputDir");
}
[Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_set_in_the_ProjectContext()
{
var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid);
fixture.PostCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir");
fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir);
}
}
public class ScriptVariablesFixture
{
public const string ConfigValue = "Debug";
public static string TestAssetPath = Path.Combine(
AppContext.BaseDirectory,
"TestAssets",
"TestProjects",
"TestApp");
public static string OutputPath = Path.Combine(
TestAssetPath,
"bin",
ConfigValue,
"dnxcore50");
public string RuntimeOutputDir { get; private set; }
public static string OutputFile = Path.Combine(OutputPath, "TestApp.dll");
public static string ResponseFile = Path.Combine(
TestAssetPath,
"obj",
ConfigValue,
"dnxcore50",
"dotnet-compile.rsp");
public Dictionary<string, string> PreCompileScriptVariables { get; private set; }
public Dictionary<string, string> PostCompileScriptVariables { get; private set; }
public ScriptVariablesFixture() : this(string.Empty)
{
}
private ScriptVariablesFixture(string rid)
{
var projectJson = Path.Combine(TestAssetPath, "project.json");
var command = new Mock<ICommand>();
command.Setup(c => c.Execute()).Returns(new CommandResult());
command.Setup(c => c.OnErrorLine(It.IsAny<Action<string>>())).Returns(() => command.Object);
command.Setup(c => c.OnOutputLine(It.IsAny<Action<string>>())).Returns(() => command.Object);
var commandFactory = new Mock<ICommandFactory>();
commandFactory.Setup(c => c
.Create(
It.IsAny<string>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<NuGetFramework>()))
.Returns(command.Object);
var _args = new CompilerCommandApp("dotnet compile", ".NET Compiler", "Compiler for the .NET Platform");
_args.ConfigValue = ConfigValue;
PreCompileScriptVariables = new Dictionary<string, string>();
PostCompileScriptVariables = new Dictionary<string, string>();
var _scriptRunner = new Mock<IScriptRunner>();
_scriptRunner.Setup(
s =>
s.RunScripts(It.IsAny<ProjectContext>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>()))
.Callback<ProjectContext, string, Dictionary<string, string>>((p, n, v) =>
{
if (n.Equals(ScriptNames.PreCompile))
{
PreCompileScriptVariables = v;
}
if (n.Equals(ScriptNames.PostCompile))
{
PostCompileScriptVariables = v;
}
});
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(string rid)
{
return new ScriptVariablesFixture(rid);
}
}
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>920b71d8-62da-4f5e-8a26-926c113f1d97</ProjectGuid>
<RootNamespace>dotnet-compile.UnitTests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,34 @@
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"Microsoft.DotNet.Cli.Utils": {
"target": "project",
"type": "build"
},
"dotnet": { "target": "project" },
"Microsoft.DotNet.ProjectModel": { "target": "project" },
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-dev-48273-16",
"moq.netcore": "4.4.0-beta8",
"FluentAssertions": "4.2.2"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net451+win8"
}
},
"content": [
"../../TestAssets/TestProjects/TestLibrary/*",
"../../TestAssets/TestProjects/TestApp/*",
"../../TestAssets/TestProjects/global.json"
],
"testRunner": "xunit"
}

View file

@ -177,14 +177,13 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
}
[Fact]
[ActiveIssue(982)]
public void PublishScriptsRun()
{
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary")
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithScripts")
.WithLockFiles()
.WithBuildArtifacts();
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
var testProject = _getProjectJson(instance.TestRoot, "TestAppWithScripts");
var publishCommand = new PublishCommand(testProject);
var result = publishCommand.ExecuteWithCapturedOutput();