Skip to content
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
Expand Up @@ -57,6 +57,18 @@ public Task CopyWithLinkedWillHaveMethodDepsKept ()
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task MissingReferenceInUnusedCodePath ()
{
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task MissingReferenceInUsedCodePath ()
{
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task ReferencesAreRemovedWhenAllUsagesAreRemoved ()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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;

namespace Mono.Linker.Tests.Cases.Expectations.Metadata;

/// <summary>
/// Deletes a file before the linker is ran
/// </summary>
[AttributeUsage (AttributeTargets.Class)]
public class DeleteBeforeAttribute : BaseMetadataAttribute
{
public DeleteBeforeAttribute (string fileName)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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.

namespace Mono.Linker.Tests.Cases.References.Dependencies;

public class MissingAssembly
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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 Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.References.Dependencies;

namespace Mono.Linker.Tests.Cases.References;

[ExpectNonZeroExitCode (1)]
[NoLinkedOutput]
[SetupCompileBefore ("missing.dll", new[] { "Dependencies/MissingAssembly.cs" })]
[DeleteBefore ("missing.dll")]
public class MissingReferenceInUnusedCodePath
{
public static void Main ()
{
}

private static void UnusedPath ()
{
typeof (MissingAssembly).ToString ();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.References.Dependencies;

namespace Mono.Linker.Tests.Cases.References;

[ExpectNonZeroExitCode (1)]
[NoLinkedOutput]
[SetupCompileBefore ("missing.dll", new[] { "Dependencies/MissingAssembly.cs" })]
[DeleteBefore ("missing.dll")]
public class MissingReferenceInUsedCodePath
{
public static void Main ()
{
typeof (MissingAssembly).ToString ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ public virtual IEnumerable<SourceAndDestinationPair> GetLinkAttributesFiles ()
.Select (GetSourceAndRelativeDestinationValue);
}

public IEnumerable<string> GetDeleteBefore ()
{
return _testCaseTypeDefinition.CustomAttributes
.Where (attr => attr.AttributeType.Name == nameof (DeleteBeforeAttribute))
.Select (attr => (string)attr.ConstructorArguments[0].Value);
}

public virtual IEnumerable<NPath> GetExtraLinkerReferences ()
{
var netcoreappDir = Path.GetDirectoryName (typeof (object).Assembly.Location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public virtual void PopulateFromExpectations (TestCaseMetadataProvider metadataP
foreach (var res in metadataProvider.GetLinkAttributesFiles ()) {
res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName));
}

foreach (var delete in metadataProvider.GetDeleteBefore ())
InputDirectory.Combine (delete).FileMustExist ().Delete ();
}

private static NPath GetExpectationsAssemblyPath ()
Expand Down