Skip to content

Commit

Permalink
Merge pull request #28696 from nagilson/nagilson-exe-rids-test-improv…
Browse files Browse the repository at this point in the history
…ements

Improve Tests for Implicit RIDs and Libraries
  • Loading branch information
nagilson authored Nov 4, 2022
2 parents a990f3a + 19709b3 commit 00ddda7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 57 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// 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.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -15,30 +18,43 @@ public class GivenThatWeWantToPublishASingleFileLibrary : SdkTest
{
public GivenThatWeWantToPublishASingleFileLibrary(ITestOutputHelper log) : base(log)
{

}

[WindowsOnlyFact]
// Tests regression on https://github.com/dotnet/sdk/pull/28484
public void ItPublishesSuccessfullyWithRIDAndPublishSingleFileLibrary()
{
var targetFramework = ToolsetInfo.CurrentTargetFramework;
var testAsset = _testAssetsManager
.CopyTestAsset("AppWithLibrarySDKStyleThatPublishesSingleFile")
.WithTargetFramework(targetFramework)
.WithSource();

var publishCommand = new PublishCommand(testAsset);
publishCommand.Execute()
.Should()
.Pass();

// It would be better if we could somehow check the library binlog or something for a RID instead.
var exeFolder = publishCommand.GetOutputDirectory(targetFramework: targetFramework);
// Parent: RID, then TFM, then Debug, then bin, then the test folder
var ridlessLibraryDllPath = Path.Combine(exeFolder.Parent.Parent.Parent.Parent.FullName, "lib", "bin", "Debug", targetFramework, "lib.dll");
Assert.True(File.Exists(ridlessLibraryDllPath));
}
TestProject referencedProject = new TestProject("Library")
{
TargetFrameworks = targetFramework,
IsExe = false
};

TestProject testProject = new TestProject("MainProject")
{
TargetFrameworks = targetFramework,
IsExe = true
};
testProject.ReferencedProjects.Add(referencedProject);
testProject.RecordProperties("RuntimeIdentifier");
referencedProject.RecordProperties("RuntimeIdentifier");

string rid = EnvironmentInfo.GetCompatibleRid(targetFramework);
List<string> args = new List<string>{"/p:PublishSingleFile=true", $"/p:RuntimeIdentifier={rid}"};

var testAsset = _testAssetsManager.CreateTestProject(testProject);
new PublishCommand(testAsset)
.Execute(args.ToArray())
.Should()
.Pass();

var referencedProjProperties = referencedProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework);
var mainProjProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework);
Assert.True(mainProjProperties["RuntimeIdentifier"] == rid);
Assert.True(referencedProjProperties["RuntimeIdentifier"] == "");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void PublishRuntimeIdentifierOverridesUseCurrentRuntime()
}

[Fact]
public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut()
public void ImplicitRuntimeIdentifierOptOutCorrectlyOptsOut()
{
var targetFramework = ToolsetInfo.CurrentTargetFramework;
var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);
Expand Down

0 comments on commit 00ddda7

Please sign in to comment.