Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding P2P test coverage for targeting common PCL profiles #1606

Merged
merged 2 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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 Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.ProjectConstruction;
using System;
Expand Down Expand Up @@ -55,4 +58,4 @@ private void DeleteNuGetArtifacts()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using FluentAssertions;
// 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 FluentAssertions;
using Microsoft.Build.Utilities;
using Microsoft.Extensions.DependencyModel;
using Microsoft.NET.TestFramework;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using FluentAssertions;
// 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 FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.DependencyModel;
using Microsoft.NET.TestFramework;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.IO;
// 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.IO;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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.Text;
using FluentAssertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.NET.TestFramework;
// 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 Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using FluentAssertions;
// 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 FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.ProjectConstruction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.NET.TestFramework;
// 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 Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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 Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xunit;
using FluentAssertions;
using System.Runtime.InteropServices;
using System.Linq;
using Xunit.Abstractions;

namespace Microsoft.NET.Build.Tests
{
public class GivenThatWeWantToVerifyPCLProjectReferenceCompat : SdkTest
{
public GivenThatWeWantToVerifyPCLProjectReferenceCompat(ITestOutputHelper log) : base(log)
{
}

[Theory]
[InlineData("netstandard1.1", "Profile7", "v4.5", true, true)]
[InlineData("netstandard1.0", "Profile31", "v4.6", true, true)]
[InlineData("netstandard1.2", "Profile32", "v4.6", true, true)]
[InlineData("netstandard1.2", "Profile44", "v4.6", true, true)]
[InlineData("netstandard1.0", "Profile49", "v4.5", true, true)]
[InlineData("netstandard1.0", "Profile78", "v4.5", true, true)]
[InlineData("netstandard1.0", "Profile84", "v4.6", true, true)]
[InlineData("netstandard1.1", "Profile111", "v4.5", true, true)]
[InlineData("netstandard1.2", "Profile151", "v4.6", true, true)]
[InlineData("netstandard1.0", "Profile157", "v4.6", true, true)]
[InlineData("netstandard1.0", "Profile259", "v4.5", true, true)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the bools are for if they are always true,true.

We should probably also add cases that we expect to fail.


public void PCL_Project_reference_compat(string referencerTarget, string profileDependencyTarget, string netDependencyTarget,
bool restoreSucceeds, bool buildSucceeds)
{
string identifier = "_TestID_" + referencerTarget + "_" + profileDependencyTarget;

TestProject referencerProject = GetTestProject("Referencer", referencerTarget, null, true);
TestProject dependencyProject = GetTestProject("Dependency", netDependencyTarget, profileDependencyTarget, false);
referencerProject.ReferencedProjects.Add(dependencyProject);

// Set the referencer project as an Exe unless it targets .NET Standard
if (!referencerProject.ShortTargetFrameworkIdentifiers.Contains("netstandard"))
{
referencerProject.IsExe = true;
}

// Skip running test if not running on Windows
// https://github.com/dotnet/sdk/issues/335
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect these tests wouldn't work on .NET Core msbuild because the deployment doesn't carry the PCL targets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now that even core msbuild can build these projects in the test environment because we force a VS Dev command prompt which sets VSINSTALLDIR and core msbuild is "crossing the streams" into VS land to pick up these targets. Since we already require a VS command prompt for building/testing SDK (there's an error from build.cmd otherwise currently), I suppose this is OK.

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (!referencerProject.BuildsOnNonWindows || !dependencyProject.BuildsOnNonWindows)
{
return;
}
}

var testAsset = _testAssetsManager.CreateTestProject(referencerProject, nameof(PCL_Project_reference_compat), identifier);

var restoreCommand = testAsset.GetRestoreCommand(Log, relativePath: "Referencer");

if (restoreSucceeds)
{
restoreCommand.Execute().Should().Pass();
}
else
{
restoreCommand.Execute().Should().Fail();
}

var appProjectDirectory = Path.Combine(testAsset.TestRoot, "Referencer");
var buildCommand = new BuildCommand(Log, appProjectDirectory);
var result = buildCommand.Execute();

if (buildSucceeds)
{
result.Should().Pass();
}
else
{
result.Should().Fail()
.And.HaveStdOutContaining("It cannot be referenced by a project that targets");
}
}

TestProject GetTestProject(string name, string target, string profile, bool isSdkProject)
{
TestProject ret = new TestProject()
{
Name = name,
IsSdkProject = isSdkProject
};

if (isSdkProject)
{
ret.TargetFrameworks = target;
}
else
{
ret.TargetFrameworkVersion = target;
if (!string.IsNullOrEmpty(profile))
{
ret.TargetFrameworkProfile = profile;
}
}

return ret;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.NET.TestFramework;
// 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 Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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 System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public class TestProject
public string RuntimeFrameworkVersion { get; set; }

public string RuntimeIdentifier { get; set; }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unecessary whitespace diff

// TargetFrameworkVersion applies to non-SDK projects
public string TargetFrameworkVersion { get; set; }

public string TargetFrameworkProfile { get; set; }

public List<TestProject> ReferencedProjects { get; } = new List<TestProject>();

public List<string> References { get; } = new List<string>();
Expand Down Expand Up @@ -161,8 +163,17 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder)
}
else
{
var targetFrameworkVersionElement = propertyGroup.Element(ns + "TargetFrameworkVersion");
targetFrameworkVersionElement.SetValue(this.TargetFrameworkVersion);
if (!string.IsNullOrEmpty(this.TargetFrameworkProfile))
{
propertyGroup.Add(new XElement(ns + "TargetFrameworkProfile", this.TargetFrameworkProfile));

// To construct an accurate PCL project file, we must modify the import of the CSharp targets;
// building/testing the SDK requires a VSDev command prompt which sets 'VSINSTALLDIR'
var importGroup = projectXml.Root.Elements(ns + "Import").Last();
importGroup.Attribute("Project").Value = "$(VSINSTALLDIR)\\MSBuild\\Microsoft\\Portable\\$(TargetFrameworkVersion)\\Microsoft.Portable.CSharp.targets";
}

propertyGroup.Element(ns + "TargetFrameworkVersion").SetValue(this.TargetFrameworkVersion);
}

foreach (var additionalProperty in AdditionalProperties)
Expand Down Expand Up @@ -290,7 +301,11 @@ public override string ToString()
{
ret.Append(TargetFrameworks);
}
if (!string.IsNullOrEmpty(TargetFrameworkVersion))
if (!string.IsNullOrEmpty(TargetFrameworkProfile))
{
ret.Append(TargetFrameworkProfile);
}
else if (!string.IsNullOrEmpty(TargetFrameworkVersion))
{
ret.Append(TargetFrameworkVersion);
}
Expand Down