Refactoring, moving, and minor edits on CompilerAssert.
MODIFY
EssentialCSharp.sln
EssentialCSharp.sln
@@ -122,6 +122,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{22D1D24E-29B7-478D-ADBA-0F4836D3857A}"
ProjectSection(SolutionItems) = preProject
src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs
+ src\Shared\Tests\CompilerAssert.cs = src\Shared\Tests\CompilerAssert.cs
EndProjectSection
EndProject
Global

MODIFY
src/Chapter06.Tests/Chapter06.Tests.csproj
src/Chapter06.Tests/Chapter06.Tests.csproj
<ChapterNumber>06</ChapterNumber>
</PropertyGroup>
<Import Project="..\ChapterTests.props" />
- <ItemGroup>
- <Compile Include="..\Shared\CompilerAssert.cs" Link="CompilerAssert.cs" />
- </ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.4.0" />
- </ItemGroup>
- <ItemGroup>
<ProjectReference Include="..\Chapter06\Chapter06.csproj" />
- </ItemGroup>
- <ItemGroup>
+ <Compile Include="..\Shared\CompilerAssert.cs" Link="CompilerAssert.cs" />
<PackageReference Update="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
- <PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.4.0" />
- <PackageReference Update="MSTest.TestAdapter" Version="2.2.10" />
- <PackageReference Update="MSTest.TestFramework" Version="2.2.10" />
- <PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />
- <PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" Version="1.1.1" />
</ItemGroup>
</Project>

MODIFY
src/ChapterTests.props
src/ChapterTests.props
<!--
<ProjectReference Include="..\submodules\TestTools\IntelliTect.TestTools.Console\IntelliTect.TestTools.Console.csproj" Condition="Exists('..\submodules\TestTools\IntelliTect.TestTools.Console\IntelliTect.TestTools.Console.csproj')" />
-->
+ <Compile Include="..\Shared\Tests\CompilerAssert.cs" Link="CompilerAssert.cs" />
<PackageReference Include="IntelliTect.TestTools.Console" Version="0.7.1-*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Update="coverlet.msbuild" Version="3.2.0" />
+ <PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />
+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" Version="1.1.1" />
<!--<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.4.0" />-->
<!--<PackageReference Update="MSTest.TestAdapter" Version="2.1.2" />-->
<!--<PackageReference Update="MSTest.TestFramework" Version="2.1.2" />-->

RENAME
src/Chapter06.Tests/CompilerAssert2.cs
src/Shared/Tests/CompilerAssert.cs
@@ -5,11 +5,11 @@ using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using System.Collections.Immutable;
-namespace AddisonWesley.Michaelis.EssentialCSharp.Shared;
+namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests;
-public static class CompilerAssert2
+public static class CompilerAssert
{
- public static async Task Compile2Async(string[] fileNames, string[] expectedErrorIds)
+ public static async Task CompileAsync(string[] fileNames, string[] expectedErrorIds)
{
string code = string.Empty;
foreach (string fileName in fileNames)
@@ -28,6 +28,9 @@ public static class CompilerAssert2
await test.RunAsync();
}
+ public static async Task CompileAsync(string fileName, params string[] expectedErrorIds) =>
+ await CompileAsync(new string[] { fileName }, expectedErrorIds);
+
//Custom verifier to ignore diagnostic locations locations
public class CustomMSTestVerifier : MSTestVerifier
@@ -74,7 +77,11 @@ public static class CompilerAssert2
protected override ParseOptions CreateParseOptions()
=> new CSharpParseOptions(LanguageVersion, DocumentationMode.Diagnose)
- .WithPreprocessorSymbols("INCLUDE");
+ .WithPreprocessorSymbols("COMPILEERROR")
+#if NET7_0_OR_GREATER
+ .WithPreprocessorSymbols("NET7_0_OR_GREATER")
+#endif // NET7_0_OR_GREATER
+ ;
protected override IEnumerable<DiagnosticAnalyzer> GetDiagnosticAnalyzers()
=> Enumerable.Empty<DiagnosticAnalyzer>();

Refactoring, moving, and minor edits on CompilerAssert.