Merge pull request #4185 from brthor/brthor/migrate-x-targetting

Migration X-Targeting
This commit is contained in:
Bryan Thornbury 2016-09-19 16:01:04 -07:00 committed by GitHub
commit 3a567e5957
14 changed files with 141 additions and 193 deletions

View file

@ -79,10 +79,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}",
testDirectory: testDirectory);
Console.WriteLine(string.Join(";", mockProj.Items.Select(i => " ;; " + i.ItemType)));
Console.WriteLine(string.Join(";", mockProj.Items.Select(i => " ;; " + i.Include)));
Console.WriteLine(string.Join(";", mockProj.Items.Select(i => " ;; " + i.Exclude)));
mockProj.Items.Count(i => i.ItemType.Equals("Content", StringComparison.Ordinal)).Should().Be(3);
// From ProjectReader #L725 (Both are empty)

View file

@ -41,7 +41,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);
File.Exists(migratedRuntimeOptionsPath).Should().BeTrue();
Console.WriteLine(migratedRuntimeOptionsPath);
var migratedRuntimeOptionsContent = JObject.Parse(File.ReadAllText(migratedRuntimeOptionsPath));
JToken.DeepEquals(rawRuntimeOptions, migratedRuntimeOptionsContent).Should().BeTrue();

View file

@ -16,6 +16,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public class GivenThatIWantToMigrateScripts : TestBase
{
[Theory]
[InlineData("compile:TargetFramework", "$(TargetFramework)")]
[InlineData("publish:TargetFramework", "$(TargetFramework)")]
[InlineData("compile:FullTargetFramework", "$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)")]
[InlineData("compile:Configuration", "$(Configuration)")]
[InlineData("compile:OutputFile", "$(TargetPath)")]
@ -37,12 +39,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
[Theory]
[InlineData("compile:TargetFramework")]
[InlineData("compile:ResponseFile")]
[InlineData("compile:CompilerExitCode")]
[InlineData("compile:RuntimeOutputDir")]
[InlineData("compile:RuntimeIdentifier")]
[InlineData("publish:TargetFramework")]
public void Formatting_script_commands_throws_when_variable_is_unsupported(string unsupportedVariable)
{
var scriptMigrationRule = new MigrateScriptsRule();
@ -122,7 +122,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"};
var commands = new[] { "%compile:FullTargetFramework%", "%compile:Configuration%"};
var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, scriptName);
target.Tasks.Count().Should().Be(commands.Length);
@ -136,76 +136,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
}
[Theory]
[InlineData("precompile")]
[InlineData("postcompile")]
[InlineData("prepublish")]
[InlineData("postpublish")]
public void Migrated_ScriptSet_has_two_MigratedScriptExtensionProperties_for_each_script(string scriptName)
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
var commands = new string[] {"compile:FullTargetFramework", "compile:Configuration"};
var propertyGroup = mockProj.AddPropertyGroup();
var target = scriptMigrationRule.MigrateScriptSet(mockProj, propertyGroup, commands,
scriptName);
Console.WriteLine(string.Join(";", propertyGroup.Properties.Select(n => n.Name)));
propertyGroup.Properties.Count().Should().Be(commands.Length * 2);
var count = 0;
foreach (var command in commands)
{
count += 1;
var scriptExtensionProperties =
propertyGroup.Properties.Where(p => p.Name.Contains($"MigratedScriptExtension_{scriptName}_{count}")).ToArray();
scriptExtensionProperties.All(p => p.Value == ".sh" || p.Value == ".cmd").Should().BeTrue();
scriptExtensionProperties.Count().Should().Be(2);
}
}
[Theory]
[InlineData("echo", ".\\echo$(MigratedScriptExtension_1)")]
[InlineData("echo hello world", ".\\echo$(MigratedScriptExtension_1) hello world")]
[InlineData("\"echo\"", ".\\\"echo$(MigratedScriptExtension_1)\"")]
[InlineData("\"echo space\"", ".\\\"echo space$(MigratedScriptExtension_1)\"")]
[InlineData("\"echo space\" other args", ".\\\"echo space$(MigratedScriptExtension_1)\" other args")]
[InlineData("\"echo space\" \"other space\"", ".\\\"echo space$(MigratedScriptExtension_1)\" \"other space\"")]
public void Migrated_ScriptSet_has_ScriptExtension_added_to_script_command(string scriptCommandline, string expectedOutputCommand)
{
var scriptMigrationRule = new MigrateScriptsRule();
var formattedCommand = scriptMigrationRule.AddScriptExtensionPropertyToCommandLine(scriptCommandline,
"MigratedScriptExtension_1");
formattedCommand.Should().Be(expectedOutputCommand);
}
[Theory]
[InlineData("echo", @".\echo")]
[InlineData("/usr/echo", "/usr/echo")]
[InlineData(@"C:\usr\echo", @"C:\usr\echo")]
[InlineData("\"echo\"", @".\""echo")]
[InlineData("\"/usr/echo\"", @"""/usr/echo")]
[InlineData(@"""C:\usr\echo", @"""C:\usr\echo")]
public void Migrated_ScriptSet_has_dotSlash_prepended_when_command_is_not_rooted(string scriptCommandline,
string expectedOutputCommandPrefix)
{
var scriptMigrationRule = new MigrateScriptsRule();
var formattedCommand = scriptMigrationRule.FormatScriptCommand(scriptCommandline,
"MigratedScriptExtension_1");
formattedCommand.Should().StartWith(expectedOutputCommandPrefix);
}
[Fact]
public void Formatting_script_commands_replaces_unknown_variables_with_MSBuild_Property_for_environment_variable_support()
{
var scriptMigrationRule = new MigrateScriptsRule();
scriptMigrationRule.ReplaceScriptVariables($"%UnknownVariable%").Should().Be("$(UnknownVariable)");
}
[Fact]
public void Migrating_scripts_creates_target_with_IsCrossTargettingBuild_not_equal_true_Condition()
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"};
var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "prepublish");
target.Condition.Should().Be(" '$(IsCrossTargetingBuild)' != 'true' ");
}
}
}

View file

@ -15,8 +15,59 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
public class GivenThatIWantToMigrateProjectFramework : TestBase
{
[Fact]
public void Migrating_netcoreapp_project_Populates_TargetFrameworkIdentifier_and_TargetFrameworkVersion()
[Fact(Skip="Emitting this until x-targetting full support is in")]
public void Migrating_netcoreapp_project_Does_not_populate_TargetFrameworkIdentifier_and_TargetFrameworkVersion()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestAppWithRuntimeOptions")
.WithCustomProperty("buildOptions", new Dictionary<string, string>
{
{ "emitEntryPoint", "false" }
})
.SaveToDisk(testDirectory);
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create();
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
mockProj.Properties.Count(p => p.Name == "TargetFrameworkIdentifier").Should().Be(0);
mockProj.Properties.Count(p => p.Name == "TargetFrameworkVersion").Should().Be(0);
}
public void Migrating_MultiTFM_project_Populates_TargetFrameworks_with_short_tfms()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromTestAssetBase("TestLibraryWithMultipleFrameworks")
.SaveToDisk(testDirectory);
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create();
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
mockProj.Properties.First(p => p.Name == "TargetFrameworks")
.Value.Should().Be("net20;net35;net40;net461;netstandard1.5");
}
public void Migrating_Single_TFM_project_Populates_TargetFrameworks_with_short_tfm()
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
@ -31,14 +82,17 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var mockProj = ProjectRootElement.Create();
// Run BuildOptionsRule
var testSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var testInputs = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(testSettings, testInputs);
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
mockProj.Properties.Count(p => p.Name == "TargetFrameworkIdentifier").Should().Be(1);
mockProj.Properties.Count(p => p.Name == "TargetFrameworkVersion").Should().Be(1);
mockProj.Properties.First(p => p.Name == "TargetFrameworkIdentifier").Value.Should().Be(".NETCoreApp");
mockProj.Properties.First(p => p.Name == "TargetFrameworkVersion").Value.Should().Be("v1.0");
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
mockProj.Properties.First(p => p.Name == "TargetFrameworks").Value.Should().Be("netcoreapp1.0");
}
}
}

View file

@ -2,7 +2,7 @@
"version": "1.0.0-*",
"buildOptions": {
"copyToOutput": ["MSBuild.exe", "MSBuild.exe.config"],
"keyFile": "../../tools/test_key.snk",
"keyFile": "../../tools/test_key.snk"
},
"dependencies": {
"Microsoft.NETCore.App": {
@ -21,9 +21,6 @@
},
"Microsoft.DotNet.Cli.Utils": {
"target": "project"
},
"dotnet": {
"target":"project"
}
},

View file

@ -15,6 +15,7 @@ using Microsoft.DotNet.Tools.Common;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Tools.Migrate;
using Build3Command = Microsoft.DotNet.Tools.Test.Utilities.Build3Command;
using BuildCommand = Microsoft.DotNet.Tools.Test.Utilities.BuildCommand;
namespace Microsoft.DotNet.Migration.Tests
{
@ -70,6 +71,26 @@ namespace Microsoft.DotNet.Migration.Tests
outputsIdentical.Should().BeTrue();
}
[Theory]
// TODO: Enable this when X-Targeting is in
// [InlineData("TestLibraryWithMultipleFrameworks")]
public void It_migrates_projects_with_multiple_TFMs(string projectName)
{
var projectDirectory =
TestAssetsManager.CreateTestInstance(projectName, callingMethod: "i").WithLockFiles().Path;
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory);
var outputsIdentical =
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
if (!outputsIdentical)
{
OutputDiagnostics(outputComparisonData);
}
outputsIdentical.Should().BeTrue();
}
[Theory]
[InlineData("TestAppWithLibrary/TestLibrary")]
[InlineData("TestLibraryWithAnalyzer")]
@ -91,33 +112,6 @@ namespace Microsoft.DotNet.Migration.Tests
outputsIdentical.Should().BeTrue();
}
[Fact]
public void It_migrates_an_app_with_scripts_and_the_scripts_run()
{
var projectDirectory =
TestAssetsManager.CreateTestInstance("TestAppWithMigrateableScripts", callingMethod: "i").WithLockFiles().Path;
BuildProjectJson(projectDirectory);
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
CleanBinObj(projectDirectory);
MigrateProject(projectDirectory);
Restore(projectDirectory);
var msBuildStdOut = BuildMSBuild(projectDirectory);
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
var outputsIdentical = projectJsonBuildOutputs.SetEquals(msbuildBuildOutputs);
outputsIdentical.Should().BeTrue();
VerifyAllMSBuildOutputsRunnable(projectDirectory);
var outputDir =
PathUtility.EnsureTrailingSlash(Path.Combine(projectDirectory, "bin", "Debug", "netcoreapp1.0"));
msBuildStdOut.Should().Contain($"precompile_output ?Debug? ?{outputDir}? ?.NETCoreApp,Version=v1.0?");
msBuildStdOut.Should().Contain($"postcompile_output ?Debug? ?{outputDir}? ?.NETCoreApp,Version=v1.0?");
}
private MigratedBuildComparisonData GetDotnetNewComparisonData(string projectDirectory, string dotnetNewType)
{
DotnetNew(projectDirectory, dotnetNewType);