update compiler unit tests

fix rebase errors

PR Feedback

more PR feedback

fix

make new script file executable

Remove scripts from TestAppCompilationContext

add hashbang to echoscript
This commit is contained in:
Bryan Thornbury 2016-02-11 16:08:46 -08:00
parent c1e28ae921
commit 50ab680688
9 changed files with 61 additions and 50 deletions

View file

@ -13,10 +13,5 @@
"frameworks": {
"dnxcore50": { }
},
"scripts": {
"prepublish" : ["echo prepublish_output ?%publish:ProjectPath%? ?%publish:Configuration%? ?%publish:OutputPath%? ?%publish:Framework%? ?%publish:Runtime%?"],
"postpublish" : ["echo postpublish_output ?%publish:ProjectPath%? ?%publish:Configuration%? ?%publish:OutputPath%? ?%publish:Framework%? ?%publish:Runtime%?"]
}
}

View file

@ -1 +1,2 @@
#!/usr/bin/env sh
echo $@

View file

@ -8,9 +8,9 @@ namespace Microsoft.DotNet.Cli.Utils
{
public class DotNetCommandFactory : ICommandFactory
{
public ICommand Create(string commandName, IEnumerable<string> args, NuGetFramework framework = null, bool useComSpec = false)
public ICommand Create(string commandName, IEnumerable<string> args, NuGetFramework framework = null)
{
return Command.CreateDotNet(commandName, args, framework, useComSpec);
return Command.CreateDotNet(commandName, args, framework);
}
}
}

View file

@ -29,5 +29,7 @@ namespace Microsoft.DotNet.Cli.Utils
CommandResolutionStrategy ResolutionStrategy { get; }
string CommandName { get; }
string CommandArgs { get; }
}
}

View file

@ -9,6 +9,6 @@ namespace Microsoft.DotNet.Cli.Utils
public interface ICommandFactory
{
ICommand Create(
string commandName, IEnumerable<string> args, NuGetFramework framework = null, bool useComSpec = false);
string commandName, IEnumerable<string> args, NuGetFramework framework = null);
}
}

View file

@ -48,7 +48,7 @@ namespace Microsoft.DotNet.Cli.Utils
private static string[] DetermineInferredScriptExtensions()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
return new string[] { "", ".cmd" };
}

View file

@ -16,20 +16,21 @@ namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
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()
{
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
var project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
CreateTestFile("some.script", binTestProjectPath);
var scriptCommandLine = "some.script";
@ -40,13 +41,8 @@ namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
}
[Fact]
public void Test_Nonexistent_Project_Local_Script_is_not_Resolved()
public void Test_Nonexistent_Project_Local_Script_throws_CommandUnknownException()
{
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
var project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
var scriptCommandLine = "nonexistent.script";
Action action = () => ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());
@ -54,24 +50,43 @@ namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
}
[Fact]
public void Test_Extension_Inference_in_Resolution_for_Project_Local_Scripts()
public void Test_Extension_sh_is_Inferred_over_cmd_in_Project_Local_Scripts_on_Unix()
{
var extensionList = new string[] {".cmd", ".sh"};
var expectedExtension = default(string);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
expectedExtension = ".cmd";
return;
}
else
var extensionList = new string[] { ".cmd", ".sh" };
var expectedExtension = ".sh";
foreach (var extension in extensionList)
{
expectedExtension = ".sh";
CreateTestFile("uniquescriptname" + extension, binTestProjectPath);
}
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
// Don't include extension
var scriptCommandLine = "uniquescriptname";
var project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
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)
{
@ -91,11 +106,6 @@ namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
[Fact]
public void Test_Script_Exe_Files_Dont_Use_Cmd_or_Sh()
{
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
var project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
CreateTestFile("some.exe", binTestProjectPath);
var scriptCommandLine = "some.exe";
@ -116,11 +126,6 @@ namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
return;
}
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
var project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
CreateTestFile("some.cmd", binTestProjectPath);
var scriptCommandLine = "some.cmd";
@ -133,13 +138,8 @@ namespace Microsoft.DotNet.Cli.Utils.ScriptExecutorTests
}
[Fact]
public void Test_Script_Builtins_Fail()
public void Test_Script_Builtins_throws_CommandUnknownException()
{
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
var project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("dnxcore50")).ProjectFile;
var scriptCommandLine = "echo";
Action action = () => ScriptExecutor.CreateCommandForScript(project, scriptCommandLine, new Dictionary<string, string>());

View file

@ -24,11 +24,18 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
_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("dnxcore,Version=v5.0");
_fixture.PreCompileScriptVariables["compile:TargetFramework"].Should().Be("dnxcore50");
}
[Fact]
@ -75,11 +82,18 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
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("dnxcore,Version=v5.0");
_fixture.PostCompileScriptVariables["compile:TargetFramework"].Should().Be("dnxcore50");
}
[Fact]
@ -180,8 +194,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
.Create(
It.IsAny<string>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<NuGetFramework>(),
It.IsAny<bool>()))
It.IsAny<NuGetFramework>()))
.Returns(command.Object);
var _args = new CompilerCommandApp("dotnet compile", ".NET Compiler", "Compiler for the .NET Platform");