Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup benchmark test project #380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -48,7 +48,15 @@ public Task SmallCompilation_MultipleSources_StringAssertions_Analyzing()

private async Task<CompilationWithAnalyzers> CreateCompilationFromAsync(params string[] sources)
{
var project = CsProjectGenerator.CreateProject(sources);
var arguments = new CsProjectArguments
{
Language = LanguageNames.CSharp,
Sources = sources,
TargetFramework = TargetFramework.Net8_0,
PackageReferences = new[] { PackageReference.FluentAssertions_6_12_0, PackageReference.MSTestTestFramework_3_1_1 }
};
var project = CsProjectGenerator.CreateProject(arguments);

var compilation = await project.GetCompilationAsync();

if (compilation is null)
Expand Down
64 changes: 0 additions & 64 deletions src/FluentAssertions.Analyzers.TestUtils/CsProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;

using XunitAssert = Xunit.Assert;
using System.Net.Http;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
Expand All @@ -16,76 +15,13 @@ namespace FluentAssertions.Analyzers.TestUtils
{
public class CsProjectGenerator
{
static CsProjectGenerator()
{
References = new[]
{
typeof(object), // System.Private.CoreLib
typeof(Console), // System
typeof(Uri), // System.Private.Uri
typeof(Enumerable), // System.Linq
typeof(CSharpCompilation), // Microsoft.CodeAnalysis.CSharp
typeof(Compilation), // Microsoft.CodeAnalysis
typeof(AssertionScope), // FluentAssertions.Core
typeof(AssertionExtensions), // FluentAssertions
typeof(HttpRequestMessage), // System.Net.Http
typeof(ImmutableArray), // System.Collections.Immutable
typeof(ConcurrentBag<>), // System.Collections.Concurrent
typeof(ReadOnlyDictionary<,>), // System.ObjectModel
typeof(Microsoft.VisualStudio.TestTools.UnitTesting.Assert), // MsTest
typeof(XunitAssert), // Xunit
}.Select(type => type.GetTypeInfo().Assembly.Location)
.Append(GetSystemAssemblyPathByName("System.Globalization.dll"))
.Append(GetSystemAssemblyPathByName("System.Text.RegularExpressions.dll"))
.Append(GetSystemAssemblyPathByName("System.Runtime.Extensions.dll"))
.Append(GetSystemAssemblyPathByName("System.Data.Common.dll"))
.Append(GetSystemAssemblyPathByName("System.Threading.Tasks.dll"))
.Append(GetSystemAssemblyPathByName("System.Runtime.dll"))
.Append(GetSystemAssemblyPathByName("System.Reflection.dll"))
.Append(GetSystemAssemblyPathByName("System.Xml.dll"))
.Append(GetSystemAssemblyPathByName("System.Xml.XDocument.dll"))
.Append(GetSystemAssemblyPathByName("System.Private.Xml.Linq.dll"))
.Append(GetSystemAssemblyPathByName("System.Linq.Expressions.dll"))
.Append(GetSystemAssemblyPathByName("System.Collections.dll"))
.Append(GetSystemAssemblyPathByName("netstandard.dll"))
.Append(GetSystemAssemblyPathByName("System.Xml.ReaderWriter.dll"))
.Append(GetSystemAssemblyPathByName("System.Private.Xml.dll"))
.Select(location => (MetadataReference)MetadataReference.CreateFromFile(location))
.ToImmutableArray();

string GetSystemAssemblyPathByName(string assemblyName)
{
var root = System.IO.Path.GetDirectoryName(typeof(object).Assembly.Location);
return System.IO.Path.Combine(root, assemblyName);
}
}

private static readonly ImmutableArray<MetadataReference> References;

private static readonly string DefaultFilePathPrefix = "Test";
private static readonly string CSharpDefaultFileExt = "cs";
private static readonly string VisualBasicDefaultExt = "vb";
private static readonly string TestProjectName = "TestProject";

public static Document CreateDocument(CsProjectArguments arguments) => CreateProject(arguments).Documents.First();

/// <summary>
/// Create a project using the inputted strings as sources.
/// </summary>
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the source code is in</param>
/// <returns>A Project created out of the Documents created from the source strings</returns>
public static Project CreateProject(string[] sources, string language = LanguageNames.CSharp)
{
var arguments = new CsProjectArguments
{
Language = language,
Sources = sources,
TargetFramework = TargetFramework.Net8_0,
};
return CreateProject(arguments).AddMetadataReferences(References);
}

public static Project CreateProject(CsProjectArguments arguments)
{
string fileNamePrefix = DefaultFilePathPrefix;
Expand Down
4 changes: 0 additions & 4 deletions src/FluentAssertions.Analyzers.Tests/DiagnosticVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ private static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer

#endregion

#region Set up compilation and documents

#endregion

#region Verifier wrappers

/// <summary>
Expand Down
Loading