fix line endings related errors in dotnet-add-p2p tests

This commit is contained in:
Krzysztof Wicher 2016-12-27 13:18:54 -08:00
parent 4d45444266
commit 5095981ec3
3 changed files with 40 additions and 12 deletions

View file

@ -91,7 +91,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorAddItemHeader, nameof(ItemTransformApplicator), outputItem.ItemType, outputItem.Condition, outputItem.Include, outputItem.Exclude, outputItem.Update)); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorAddItemHeader, nameof(ItemTransformApplicator), outputItem.ItemType, outputItem.Condition, outputItem.Include, outputItem.Exclude, outputItem.Update));
itemGroup.AppendChild(outputItem); itemGroup.AppendChild(outputItem);
outputItem.AddMetadata(item.Metadata); outputItem.AddMetadata(item.Metadata, MigrationTrace.Instance);
} }
private ProjectItemElement MergeWithExistingItemsWithACondition(ProjectItemElement item, ProjectItemGroupElement destinationItemGroup) private ProjectItemElement MergeWithExistingItemsWithACondition(ProjectItemElement item, ProjectItemGroupElement destinationItemGroup)
@ -110,7 +110,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
foreach (var existingItem in existingItemsWithACondition) foreach (var existingItem in existingItemsWithACondition)
{ {
// If this item is encompassing items in a condition, remove the encompassed includes from the existing item // If this item is encompassing items in a condition, remove the encompassed includes from the existing item
var encompassedIncludes = item.GetEncompassedIncludes(existingItem); var encompassedIncludes = item.GetEncompassedIncludes(existingItem, MigrationTrace.Instance);
if (encompassedIncludes.Any()) if (encompassedIncludes.Any())
{ {
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes))); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes)));
@ -179,7 +179,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
// conditionless item // conditionless item
foreach (var existingItem in existingItemsWithNoCondition) foreach (var existingItem in existingItemsWithNoCondition)
{ {
var encompassedIncludes = existingItem.GetEncompassedIncludes(item); var encompassedIncludes = existingItem.GetEncompassedIncludes(item, MigrationTrace.Instance);
if (encompassedIncludes.Any()) if (encompassedIncludes.Any())
{ {
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes))); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes)));
@ -280,7 +280,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
mergedItem.UnionExcludes(existingItem.Excludes()); mergedItem.UnionExcludes(existingItem.Excludes());
mergedItem.UnionExcludes(item.Excludes()); mergedItem.UnionExcludes(item.Excludes());
mergedItem.AddMetadata(MergeMetadata(existingItem.Metadata, item.Metadata)); mergedItem.AddMetadata(MergeMetadata(existingItem.Metadata, item.Metadata), MigrationTrace.Instance);
item.RemoveIncludes(commonIncludes); item.RemoveIncludes(commonIncludes);
existingItem.RemoveIncludes(commonIncludes); existingItem.RemoveIncludes(commonIncludes);

View file

@ -0,0 +1,28 @@
// 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 FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public static class StringAssertionsExtensions
{
private static string NormalizeLineEndings(string s)
{
return s.Replace("\r\n", "\n");
}
public static AndConstraint<StringAssertions> BeVisuallyEquivalentTo(this StringAssertions assertions, string expected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(NormalizeLineEndings(assertions.Subject) == NormalizeLineEndings(expected))
.BecauseOf(because, becauseArgs)
.FailWith($"String \"{assertions.Subject}\" is not visually equivalent to expected string \"{expected}\".");
return new AndConstraint<StringAssertions>(assertions);
}
}
}

View file

@ -36,7 +36,7 @@ Additional Arguments:
const string ProjectNotCompatibleErrorMessageRegEx = "Project `[^`]*` cannot be added due to incompatible targeted frameworks between the two projects\\. Please review the project you are trying to add and verify that is compatible with the following targets\\:"; const string ProjectNotCompatibleErrorMessageRegEx = "Project `[^`]*` cannot be added due to incompatible targeted frameworks between the two projects\\. Please review the project you are trying to add and verify that is compatible with the following targets\\:";
const string ProjectDoesNotTargetFrameworkErrorMessageRegEx = "Project `[^`]*` does not target framework `[^`]*`."; const string ProjectDoesNotTargetFrameworkErrorMessageRegEx = "Project `[^`]*` does not target framework `[^`]*`.";
static readonly string[] DefaultFrameworks = new string[] { "netcoreapp1.0", "net451" }; static readonly string[] DefaultFrameworks = new string[] { "netcoreapp1.0", "net451" };
private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "") private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
{ {
return new TestSetup( return new TestSetup(
@ -92,7 +92,7 @@ Additional Arguments:
{ {
var cmd = new AddP2PCommand().Execute(helpArg); var cmd = new AddP2PCommand().Execute(helpArg);
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be(HelpText); cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
} }
[Theory] [Theory]
@ -130,7 +130,7 @@ Additional Arguments:
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.ExitCode.Should().NotBe(0); cmd.ExitCode.Should().NotBe(0);
cmd.StdErr.Should().Be($"Could not find project or directory `{projName}`."); cmd.StdErr.Should().Be($"Could not find project or directory `{projName}`.");
cmd.StdOut.Should().Be(HelpText); cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
} }
[Fact] [Fact]
@ -145,7 +145,7 @@ Additional Arguments:
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.ExitCode.Should().NotBe(0); cmd.ExitCode.Should().NotBe(0);
cmd.StdErr.Should().Be("Project `Broken/Broken.csproj` is invalid."); cmd.StdErr.Should().Be("Project `Broken/Broken.csproj` is invalid.");
cmd.StdOut.Should().Be(HelpText); cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
} }
[Fact] [Fact]
@ -159,7 +159,7 @@ Additional Arguments:
.Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\""); .Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");
cmd.ExitCode.Should().NotBe(0); cmd.ExitCode.Should().NotBe(0);
cmd.StdErr.Should().Be($"Found more than one project in `{workingDir + Path.DirectorySeparatorChar}`. Please specify which one to use."); cmd.StdErr.Should().Be($"Found more than one project in `{workingDir + Path.DirectorySeparatorChar}`. Please specify which one to use.");
cmd.StdOut.Should().Be(HelpText); cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
} }
[Fact] [Fact]
@ -172,7 +172,7 @@ Additional Arguments:
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.ExitCode.Should().NotBe(0); cmd.ExitCode.Should().NotBe(0);
cmd.StdErr.Should().Be($"Could not find any project in `{setup.TestRoot + Path.DirectorySeparatorChar}`."); cmd.StdErr.Should().Be($"Could not find any project in `{setup.TestRoot + Path.DirectorySeparatorChar}`.");
cmd.StdOut.Should().Be(HelpText); cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
} }
[Fact] [Fact]
@ -489,7 +489,7 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"\"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be(OutputText); cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
@ -511,7 +511,7 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\""); .Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be(OutputText); cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(noCondBefore + 1); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(noCondBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);