Skip to content

Commit

Permalink
Fix ILLink analyzer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbomer committed Dec 29, 2023
1 parent c3032e0 commit cc45846
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<RuntimeHostConfigurationOption Include="ILLink.RoslynAnalyzer.Tests.LinkerTestDir">
<Value>$(LinkerTestDir)</Value>
</RuntimeHostConfigurationOption>
<RuntimeHostConfigurationOption Include="ILLink.RoslynAnalyzer.Tests.TargetFramework">
<Value>$(TargetFramework)</Value>
</RuntimeHostConfigurationOption>
<RuntimeHostConfigurationOption Include="ILLink.RoslynAnalyzer.Tests.ArtifactsBinDir">
<Value>$(ArtifactsBinDir)</Value>
</RuntimeHostConfigurationOption>
Expand Down
22 changes: 12 additions & 10 deletions src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -24,11 +25,15 @@ public abstract class TestCaseUtils
{
private static readonly string MonoLinkerTestsCases = "Mono.Linker.Tests.Cases";

private static string targetFramework = (string)AppContext.GetData("ILLink.RoslynAnalyzer.Tests.TargetFramework")!;

private static string frameworkVersion = typeof(object).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion.Split('+')[0];

public static readonly ReferenceAssemblies NetCoreAppReferencessemblies =
new ReferenceAssemblies (
"net8.0",
new PackageIdentity ("Microsoft.NETCore.App.Ref", "8.0.0"),
Path.Combine ("ref", "net8.0"))
targetFramework,
new PackageIdentity ("Microsoft.NETCore.App.Ref", frameworkVersion),
Path.Combine ("ref", targetFramework))
.WithNuGetConfigFilePath (Path.Combine (TestCaseUtils.GetRepoRoot (), "NuGet.config"));

private static ImmutableArray<MetadataReference> s_netcoreappRefs;
Expand Down Expand Up @@ -58,7 +63,7 @@ public static string FindTestSuiteDir (string rootDir, string suiteName)

public static async Task RunTestFile (string suiteName, string testName, bool allowMissingWarnings, params (string, string)[] msbuildProperties)
{
GetDirectoryPaths (out string rootSourceDir, out string testAssemblyPath);
GetDirectoryPaths (out string rootSourceDir);
Debug.Assert (Path.GetFileName (rootSourceDir) == MonoLinkerTestsCases);
var testSuiteDir = FindTestSuiteDir (rootSourceDir, suiteName);
Assert.True (Directory.Exists (testSuiteDir));
Expand Down Expand Up @@ -162,16 +167,13 @@ private static IEnumerable<AdditionalText> GetAdditionalFiles (string rootSource
}
}

public static void GetDirectoryPaths (out string rootSourceDirectory, out string testAssemblyPath)
public static void GetDirectoryPaths (out string rootSourceDirectory)
{
var artifactsBinDirectory = (string)AppContext.GetData("ILLink.RoslynAnalyzer.Tests.ArtifactsBinDir")!;
var LinkerTestDirectory = (string)AppContext.GetData("ILLink.RoslynAnalyzer.Tests.LinkerTestDir")!;
var linkerTestDirectory = (string)AppContext.GetData("ILLink.RoslynAnalyzer.Tests.LinkerTestDir")!;
var configuration = (string)AppContext.GetData("ILLink.RoslynAnalyzer.Tests.Configuration")!;

const string tfm = "net8.0";

rootSourceDirectory = Path.GetFullPath(Path.Combine(LinkerTestDirectory, MonoLinkerTestsCases));
testAssemblyPath = Path.GetFullPath(Path.Combine(artifactsBinDirectory, "ILLink.RoslynAnalyzer.Tests", configuration, tfm));
rootSourceDirectory = Path.GetFullPath(Path.Combine(linkerTestDirectory, MonoLinkerTestsCases));
}

// Accepts typeof expressions, with a format specifier
Expand Down

0 comments on commit cc45846

Please sign in to comment.