diff --git a/Src/Basic.Reference.Assemblies.UnitTests/CompilationUtil.cs b/Src/Basic.Reference.Assemblies.UnitTests/CompilationUtil.cs index a2198b7..79be56c 100644 --- a/Src/Basic.Reference.Assemblies.UnitTests/CompilationUtil.cs +++ b/Src/Basic.Reference.Assemblies.UnitTests/CompilationUtil.cs @@ -1,5 +1,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Operations; using System; using System.Collections.Generic; using System.IO; @@ -11,14 +12,8 @@ namespace Basic.Reference.Assemblies.UnitTests; internal static class CompilationUtil { - public static MemoryStream CompileToLibrary(string code, string assemblyName) + public static MemoryStream CompileToLibrary(string code, string assemblyName, IEnumerable references) { - var references = -#if NET - Net80.References.All; -#else - Net461.References.All; -#endif var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); var compilation = CSharpCompilation.Create( assemblyName, @@ -48,23 +43,23 @@ static string GetMessage(IEnumerable diagnostics) } } - public static Assembly CompileToLibraryAndLoad(string code, string assemblyName) + public static Assembly CompileToLibraryAndLoad(string code, string assemblyName, IEnumerable references) { - var stream = CompileToLibrary(code, assemblyName); + var stream = CompileToLibrary(code, assemblyName, references); return Load(stream, assemblyName); } /// /// Compile and run the code expecting to find a static Lib.Go method /// - public static string? CompileAndRun(string code, string assemblyName) + public static string? CompileAndRun(string code, string assemblyName, IEnumerable references) { - var assembly = CompileToLibraryAndLoad(code, assemblyName); + var assembly = CompileToLibraryAndLoad(code, assemblyName, references); var libType = assembly .GetTypes() .Where(x => x.Name == "Lib") .Single(); - var method = libType.GetMethod("Go", BindingFlags.Static | BindingFlags.NonPublic); + var method = libType.GetMethod("Go", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); var obj = method!.Invoke(null, null); return (string?)obj; } diff --git a/Src/Basic.Reference.Assemblies.UnitTests/SanityUnitTests.cs b/Src/Basic.Reference.Assemblies.UnitTests/SanityUnitTests.cs index 75a3008..438644c 100644 --- a/Src/Basic.Reference.Assemblies.UnitTests/SanityUnitTests.cs +++ b/Src/Basic.Reference.Assemblies.UnitTests/SanityUnitTests.cs @@ -13,6 +13,12 @@ namespace Basic.Reference.Assemblies.UnitTests; public class SanityUnitTests(ITestOutputHelper outputHelper) { public ITestOutputHelper TestOutputHelper { get; } = outputHelper; + public bool IsCoreClr => +#if NET + true; +#else + false; +#endif [Theory] [MemberData(nameof(TestData.ApplicationReferences), MemberType = typeof(TestData))] @@ -190,7 +196,11 @@ public static string Go() } } """; - var actual = CompilationUtil.CompileAndRun(source, nameof(RunTuple)); + + var references = IsCoreClr + ? Net80.References.All + : [.. Net461.References.All, .. Net461.ExtraReferences.All]; + var actual = CompilationUtil.CompileAndRun(source, nameof(RunTuple), references); Assert.Equal("(1, 2)", actual); } }