Fix Binding Redirect Test and other fixes

This commit is contained in:
Bryan 2016-01-29 17:37:08 -08:00
parent 07fbb3d967
commit b8d54e5a0f
13 changed files with 85 additions and 107 deletions

View file

@ -21,11 +21,18 @@ namespace Microsoft.DotNet.Tests.EndToEnd
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; }
private string TestDirectory { get; set; }
private string TestProject { get; set; }
private string OutputDirectory { get; set; }
static EndToEndTest()
{
EndToEndTest.SetupStaticTestProject();
}
public static void Main()
{
Console.WriteLine("Dummy Entrypoint.");
@ -33,9 +40,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
public EndToEndTest()
{
TestSetup();
Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
TestInstanceSetup();
}
[Fact]
@ -169,21 +174,34 @@ namespace Microsoft.DotNet.Tests.EndToEnd
TestExecutable(OutputDirectory, publishCommand.GetOutputExecutable(), s_expectedOutput);
}
private void TestSetup()
private void TestInstanceSetup()
{
var root = Temp.CreateDirectory();
TestDirectory = root.CreateDirectory(s_testdirName).Path;
var testInstanceDir = root.CopyDirectory(RestoredTestProjectDirectory);
TestDirectory = testInstanceDir.Path;
TestProject = Path.Combine(TestDirectory, "project.json");
OutputDirectory = Path.Combine(TestDirectory, s_outputdirName);
InitializeTestDirectory();
Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
}
private void InitializeTestDirectory()
private static void SetupStaticTestProject()
{
RestoredTestProjectDirectory = Path.Combine(AppContext.BaseDirectory, "bin", s_testdirName);
// Ignore Delete Failure
try
{
Directory.Delete(RestoredTestProjectDirectory, true);
}
catch(Exception e) {}
Directory.CreateDirectory(RestoredTestProjectDirectory);
var currentDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(TestDirectory);
Directory.SetCurrentDirectory(RestoredTestProjectDirectory);
new NewCommand().Execute().Should().Pass();
new RestoreCommand().Execute("--quiet").Should().Pass();

View file

@ -0,0 +1,4 @@
public class P{
public static void Main() { var t = typeof(Newtonsoft.Json.JsonConvert); }
}

View file

@ -0,0 +1,17 @@
{
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"Newtonsoft.Json": "7.0.1"
},
"frameworks": {
"net451": { },
"dnxcore50": {
"imports" : "portable-net45+wp80+win8",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23704"
}
}
}
}

View file

@ -0,0 +1,4 @@
public class P{
public static void Main() { var t = typeof(Newtonsoft.Json.JsonConvert); }
}

View file

@ -2,8 +2,8 @@
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"Microsoft.Extensions.DependencyModel": "1.0.0-*",
"Newtonsoft.Json": "6.0.0"
"Newtonsoft.Json": "6.0.0",
"TestLibraryGreater": {"target":"project"}
},
"frameworks": {

View file

@ -0,0 +1,3 @@
{
"projects": [ "."]
}

View file

@ -1,19 +0,0 @@
<?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>b76591d6-d105-441d-ab40-ac7e78eaf84d</ProjectGuid>
<RootNamespace>TestLibraryWithRunner</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

@ -25,12 +25,9 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
_mainProject = mainProject;
_expectedOutput = expectedOutput;
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
// recursively copy projects to the temp dir and restore them
_tempProjectRoot = root.CopyDirectory(testProjectsRoot);
RunRestore(_tempProjectRoot.Path);
}
protected void TouchSourcesOfProject()
@ -115,11 +112,5 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
return executablePath;
}
private void RunRestore(string args)
{
var restoreCommand = new RestoreCommand();
restoreCommand.Execute($"--quiet {args}").Should().Pass();
}
}
}

View file

@ -21,9 +21,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
var testLibDir = root.CreateDirectory("TestLibrary");
// copy projects to the temp dir and restore them
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
RunRestore(testLibDir.Path);
// run compile
var outputDir = Path.Combine(testLibDir.Path, "bin");
@ -46,7 +44,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer"), testLibDir);
RunRestore(testLibDir.Path);
// run compile
var outputDir = Path.Combine(testLibDir.Path, "bin");
@ -62,12 +59,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
// copy all the files to temp dir
foreach (var file in Directory.EnumerateFiles(projectDir))
{
// never copy project.lock.json. All the tests are expected to call 'dotnet restore'
if (file.ToLower().EndsWith("project.lock.json"))
{
continue;
}
tempDir.CopyFile(file);
}
}
@ -76,11 +67,5 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
return Path.Combine(projectDir.Path, "project.json");
}
private void RunRestore(string args)
{
var restoreCommand = new RestoreCommand();
restoreCommand.Execute($"--quiet {args}").Should().Pass();
}
}
}

View file

@ -7,6 +7,8 @@ using System.Text.RegularExpressions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
using System;
using System.Text;
namespace Microsoft.DotNet.Tools.Publish.Tests
{
@ -37,7 +39,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testAppDir = root.CreateDirectory("TestApp");
var testLibDir = root.CreateDirectory("TestLibrary");
@ -45,9 +47,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
RunRestore(testAppDir.Path);
RunRestore(testLibDir.Path);
// run publish
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir);
var testProject = GetProjectPath(testAppDir);
@ -74,14 +73,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
// create unique directories in the 'temp' folder
var testDir = Temp.CreateDirectory();
testDir.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testAppDir = Path.Combine(_testProjectsRoot, "TestAppWithContents");
// copy projects to the temp dir
CopyProjectToTempDir(testAppDir, testDir);
RunRestore(testDir.Path);
// run publish
var testProject = GetProjectPath(testDir);
var publishCommand = new PublishCommand(testProject);
@ -92,11 +89,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
}
[Fact]
public void BeforeRestoreTest()
public void FailWhenNoRestoreTest()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testAppDir = root.CreateDirectory("TestApp");
var testLibDir = root.CreateDirectory("TestLibrary");
@ -104,6 +101,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
File.Delete(Path.Combine(testAppDir.Path, "project.lock.json"));
File.Delete(Path.Combine(testLibDir.Path, "project.lock.json"));
var testProject = GetProjectPath(testAppDir);
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Fail();
@ -114,14 +114,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testLibDir = root.CreateDirectory("TestLibrary");
//copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
RunRestore(testLibDir.Path);
var testProject = GetProjectPath(testLibDir);
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass();
@ -134,37 +132,34 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
}
[WindowsOnlyFact]
public void TestLibraryPublishTest()
public void TestLibraryBindingRedirectGeneration()
{
// create unique directories in the 'temp' folder
// Set up Test Staging in Temporary Directory
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testLibDir = root.CreateDirectory("TestLibraryWithRunner");
root.CopyDirectory(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration"));
//copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithRunner"), testLibDir);
var testProjectsRootDir = Path.Combine(root.Path, "TestBindingRedirectGeneration");
var greaterTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryGreater");
var lesserTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryLesser");
RunRestore(testLibDir.Path);
var testProject = GetProjectPath(testLibDir);
var publishCommand = new PublishCommand(testProject, "net451");
var lesserTestProject = Path.Combine(lesserTestLibDir, "project.json");
var publishCommand = new PublishCommand(lesserTestProject, "net451");
publishCommand.Execute().Should().Pass();
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.pdb");
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryWithRunner.deps");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll.config");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll.config");
// dependencies should also be copied
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
publishCommand.GetOutputDirectory().Delete(true);
publishCommand = new PublishCommand(testProject, "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier());
publishCommand = new PublishCommand(lesserTestProject, "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier());
publishCommand.Execute().Should().Pass();
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.pdb");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.deps");
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryWithRunner.dll.config");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.dll.config");
// dependencies should also be copied
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
}
@ -174,7 +169,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testAppDir = root.CreateDirectory("TestAppCompilationContext");
var testLibDir = root.CreateDirectory("TestLibrary");
@ -182,9 +177,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
RunRestore(testAppDir.Path);
RunRestore(testLibDir.Path);
var testProject = GetProjectPath(testAppDir);
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass();
@ -204,13 +196,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
public void CompilationFailedTest()
{
var testDir = Temp.CreateDirectory();
testDir.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var compileFailDir = Path.Combine(_testProjectsRoot, "CompileFail");
CopyProjectToTempDir(compileFailDir, testDir);
RunRestore(testDir.Path);
var testProject = GetProjectPath(testDir);
var publishCommand = new PublishCommand(testProject);
@ -223,7 +213,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testAppDir = root.CreateDirectory("TestApp");
var testLibDir = root.CreateDirectory("TestLibrary");
@ -231,9 +221,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
RunRestore(testAppDir.Path);
RunRestore(testLibDir.Path);
// run publish
var testProject = GetProjectPath(testAppDir);
var publishCommand = new PublishCommand(testProject);
@ -249,12 +236,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
// copy all the files to temp dir
foreach (var file in Directory.EnumerateFiles(projectDir))
{
// never copy project.lock.json. All the tests are expected to call 'dotnet restore'
if (file.ToLower().EndsWith("project.lock.json"))
{
continue;
}
tempDir.CopyFile(file);
}
}
@ -263,11 +244,5 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
return Path.Combine(projectDir.Path, "project.json");
}
private void RunRestore(string args)
{
var restoreCommand = new RestoreCommand();
restoreCommand.Execute($"--quiet {args}").Should().Pass();
}
}
}