Skip to content

Commit 269df57

Browse files
committed
fixed the test
1 parent 42dbd78 commit 269df57

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Src/Basic.Reference.Assemblies.UnitTests/CompilationUtil.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp;
3+
using Microsoft.CodeAnalysis.Operations;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -11,14 +12,8 @@
1112
namespace Basic.Reference.Assemblies.UnitTests;
1213
internal static class CompilationUtil
1314
{
14-
public static MemoryStream CompileToLibrary(string code, string assemblyName)
15+
public static MemoryStream CompileToLibrary(string code, string assemblyName, IEnumerable<MetadataReference> references)
1516
{
16-
var references =
17-
#if NET
18-
Net80.References.All;
19-
#else
20-
Net461.References.All;
21-
#endif
2217
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
2318
var compilation = CSharpCompilation.Create(
2419
assemblyName,
@@ -48,23 +43,23 @@ static string GetMessage(IEnumerable<Diagnostic> diagnostics)
4843
}
4944
}
5045

51-
public static Assembly CompileToLibraryAndLoad(string code, string assemblyName)
46+
public static Assembly CompileToLibraryAndLoad(string code, string assemblyName, IEnumerable<MetadataReference> references)
5247
{
53-
var stream = CompileToLibrary(code, assemblyName);
48+
var stream = CompileToLibrary(code, assemblyName, references);
5449
return Load(stream, assemblyName);
5550
}
5651

5752
/// <summary>
5853
/// Compile and run the code expecting to find a static Lib.Go method
5954
/// </summary>
60-
public static string? CompileAndRun(string code, string assemblyName)
55+
public static string? CompileAndRun(string code, string assemblyName, IEnumerable<MetadataReference> references)
6156
{
62-
var assembly = CompileToLibraryAndLoad(code, assemblyName);
57+
var assembly = CompileToLibraryAndLoad(code, assemblyName, references);
6358
var libType = assembly
6459
.GetTypes()
6560
.Where(x => x.Name == "Lib")
6661
.Single();
67-
var method = libType.GetMethod("Go", BindingFlags.Static | BindingFlags.NonPublic);
62+
var method = libType.GetMethod("Go", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
6863
var obj = method!.Invoke(null, null);
6964
return (string?)obj;
7065
}

Src/Basic.Reference.Assemblies.UnitTests/SanityUnitTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ namespace Basic.Reference.Assemblies.UnitTests;
1313
public class SanityUnitTests(ITestOutputHelper outputHelper)
1414
{
1515
public ITestOutputHelper TestOutputHelper { get; } = outputHelper;
16+
public bool IsCoreClr =>
17+
#if NET
18+
true;
19+
#else
20+
false;
21+
#endif
1622

1723
[Theory]
1824
[MemberData(nameof(TestData.ApplicationReferences), MemberType = typeof(TestData))]
@@ -190,7 +196,11 @@ public static string Go()
190196
}
191197
}
192198
""";
193-
var actual = CompilationUtil.CompileAndRun(source, nameof(RunTuple));
199+
200+
var references = IsCoreClr
201+
? Net80.References.All
202+
: [.. Net461.References.All, .. Net461.ExtraReferences.All];
203+
var actual = CompilationUtil.CompileAndRun(source, nameof(RunTuple), references);
194204
Assert.Equal("(1, 2)", actual);
195205
}
196206
}

0 commit comments

Comments
 (0)