Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into topic/add-equivale…
Browse files Browse the repository at this point in the history
…ncyassertionoptions-to-stringassertions
  • Loading branch information
Valentin Breuß authored and Valentin Breuß committed Jan 3, 2024
2 parents b0c3e84 + e1f7606 commit 303e73a
Show file tree
Hide file tree
Showing 181 changed files with 2,020 additions and 1,980 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Expand Up @@ -152,6 +152,8 @@ dotnet_diagnostic.CA1724.severity = none
dotnet_diagnostic.CA1819.severity = none
# CA1851: Possible multiple enumerations of IEnumerable collection. Related to GH-issue #2000
dotnet_diagnostic.CA1851.severity = suggestion
# CA1859: Use concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = suggestion
# CA1860: Avoid using 'Enumerable.Any()' extension method
dotnet_diagnostic.CA1860.severity = warning
# CA1861: Avoid constant arrays as arguments
Expand Down Expand Up @@ -366,6 +368,9 @@ dotnet_diagnostic.RCS1186.severity = none
# Use bit shift operator.
dotnet_diagnostic.RCS1237.severity = none

# RCS1228: Unused element in documentation comment. (Equivalent to SA1614)
dotnet_diagnostic.RCS1228.severity = suggestion

# Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter
dotnet_diagnostic.MA0002.severity = suggestion

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
fetch-depth: 0

- name: Setup .NET SDKs
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
Expand All @@ -42,7 +42,7 @@ jobs:
file: TestResults/reports/lcov.info

- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: ./Artifacts/*
only-unit-tests:
Expand All @@ -59,7 +59,7 @@ jobs:
fetch-depth: 0

- name: Setup .NET SDKs
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code_quality.yml
Expand Up @@ -18,10 +18,10 @@ jobs:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.2
uses: JetBrains/qodana-action@v2023.3
with:
upload-result: ${{ github.ref_name == 'master' || github.ref_name == 'develop' }}
args: --baseline,qodana.sarif.json,--ide,QDNET-EAP
args: --baseline,qodana.sarif.json,--ide,QDNET
pr-mode: ${{ github.event_name == 'pull_request_target' }}
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
18 changes: 9 additions & 9 deletions Build/Build.cs
Expand Up @@ -99,7 +99,7 @@ class Build : NukeBuild
"Branch spec {branchspec} is a pull request. Adding build number {buildnumber}",
BranchSpec, BuildNumber);
SemVer = string.Join('.', GitVersion.SemVer.Split('.').Take(3).Union(new[] { BuildNumber }));
SemVer = string.Join('.', GitVersion.SemVer.Split('.').Take(3).Union([BuildNumber]));
}
Information("SemVer = {semver}", SemVer);
Expand Down Expand Up @@ -159,14 +159,14 @@ class Build : NukeBuild
ReportTestOutcome(globFilters: $"*{project.Name}.trx");
});

Project[] Projects => new[]
{
Project[] Projects =>
[
Solution.Specs.FluentAssertions_Specs,
Solution.Specs.FluentAssertions_Equivalency_Specs,
Solution.Specs.FluentAssertions_Extensibility_Specs,
Solution.Specs.FSharp_Specs,
Solution.Specs.VB_Specs
};
];

Target UnitTestsNet47 => _ => _
.Unlisted()
Expand Down Expand Up @@ -209,7 +209,7 @@ class Build : NukeBuild
(settings, project) => settings
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks().Except(new[] { net47 }),
project.GetTargetFrameworks().Except([net47]),
(frameworkSettings, framework) => frameworkSettings
.SetFramework(framework)
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
Expand Down Expand Up @@ -272,19 +272,19 @@ void ReportTestOutcome(params string[] globFilters)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
var projects = new[]
{
Project[] projects =
[
Solution.TestFrameworks.MSpec_Specs,
Solution.TestFrameworks.MSTestV2_Specs,
Solution.TestFrameworks.NUnit3_Specs,
Solution.TestFrameworks.NUnit4_Specs,
Solution.TestFrameworks.XUnit2_Specs
};
];
var testCombinations =
from project in projects
let frameworks = project.GetTargetFrameworks()
let supportedFrameworks = EnvironmentInfo.IsWin ? frameworks : frameworks.Except(new[] { "net47" })
let supportedFrameworks = EnvironmentInfo.IsWin ? frameworks : frameworks.Except(["net47"])
from framework in supportedFrameworks
select new { project, framework };
Expand Down
4 changes: 2 additions & 2 deletions Build/_build.csproj
Expand Up @@ -18,10 +18,10 @@
</PropertyGroup>
<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.10.0]" />
<PackageDownload Include="ReportGenerator" Version="[5.1.23]" />
<PackageDownload Include="ReportGenerator" Version="[5.2.0]" />
<PackageDownload Include="xunit.runner.console" Version="[2.6.2]" />
<PackageDownload Include="Node.js.redist" Version="[20.9.0]" />
<PackageReference Include="LibGit2Sharp" Version="0.28.0" />
<PackageReference Include="LibGit2Sharp" Version="0.29.0" />
<PackageReference Include="Nuke.Common" Version="7.0.6" />
<PackageReference Include="Nuke.Components" Version="7.0.6" />
<PackageDownload Include="Yarn.MSBuild" Version="[1.22.19]" />
Expand Down
10 changes: 5 additions & 5 deletions Directory.Build.props
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
Expand All @@ -13,7 +13,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>7.0</AnalysisLevel>
<AnalysisLevel>8.0</AnalysisLevel>
<AnalysisMode>All</AnalysisMode>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>
Expand All @@ -22,19 +22,19 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.6.4">
<PackageReference Include="Roslynator.Analyzers" Version="4.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.112">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.127">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/AggregateExceptionExtractor.cs
Expand Up @@ -13,7 +13,7 @@ public IEnumerable<T> OfType<T>(Exception actualException)
{
if (typeof(T).IsSameOrInherits(typeof(AggregateException)))
{
return actualException is T exception ? new[] { exception } : Enumerable.Empty<T>();
return actualException is T exception ? [exception] : [];
}

return GetExtractedExceptions<T>(actualException);
Expand Down
Expand Up @@ -14,16 +14,16 @@ internal CallerStatementBuilder()
{
statement = new StringBuilder();

priorityOrderedParsingStrategies = new List<IParsingStrategy>
{
priorityOrderedParsingStrategies =
[
new QuotesParsingStrategy(),
new MultiLineCommentParsingStrategy(),
new SingleLineCommentParsingStrategy(),
new SemicolonParsingStrategy(),
new ShouldCallParsingStrategy(),
new AwaitParsingStrategy(),
new AddNonEmptySymbolParsingStrategy()
};
];
}

internal void Append(string symbols)
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/CallerIdentifier.cs
Expand Up @@ -268,7 +268,7 @@ private static StackFrame[] GetFrames(StackTrace stack)
#if !NET6_0_OR_GREATER
if (frames == null)
{
return Array.Empty<StackFrame>();
return [];
}
#endif
return frames
Expand Down
20 changes: 10 additions & 10 deletions Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Expand Up @@ -71,7 +71,7 @@ public GenericCollectionAssertions(TCollection actualValue)
.FailWith("Expected type to be {0}{reason}, but found {context:the collection} is <null>.",
typeof(TExpectation).FullName);

IEnumerable<TExpectation> matches = Enumerable.Empty<TExpectation>();
IEnumerable<TExpectation> matches = [];

if (success)
{
Expand Down Expand Up @@ -218,7 +218,7 @@ public AndConstraint<TAssertions> AllBeAssignableTo(Type expectedType, string be
.FailWith("Expected type to be {0}{reason}, but found {context:collection} is <null>.",
typeof(TExpectation).FullName);

IEnumerable<TExpectation> matches = Enumerable.Empty<TExpectation>();
IEnumerable<TExpectation> matches = [];

if (success)
{
Expand Down Expand Up @@ -701,7 +701,7 @@ public AndConstraint<TAssertions> BeNullOrEmpty(string because = "", params obje
.ForCondition(Subject is not null)
.FailWith("Expected {context:collection} to contain {0}{reason}, but found <null>.", expected);

IEnumerable<T> matches = Enumerable.Empty<T>();
IEnumerable<T> matches = [];

if (success)
{
Expand Down Expand Up @@ -740,7 +740,7 @@ public AndConstraint<TAssertions> BeNullOrEmpty(string because = "", params obje
.ForCondition(Subject is not null)
.FailWith("Expected {context:collection} to contain {0}{reason}, but found <null>.", predicate.Body);

IEnumerable<T> matches = Enumerable.Empty<T>();
IEnumerable<T> matches = [];

if (success)
{
Expand Down Expand Up @@ -1204,7 +1204,7 @@ public AndConstraint<TAssertions> NotContainItemsAssignableTo(Type type, string
.ForCondition(Subject is not null)
.FailWith(expectationPrefix + "but found <null>.", predicate);

T[] matches = Array.Empty<T>();
T[] matches = [];

if (success)
{
Expand Down Expand Up @@ -1304,7 +1304,7 @@ public AndConstraint<TAssertions> EndWith(IEnumerable<T> expectation, string bec
/// </param>
public AndConstraint<TAssertions> EndWith(T element, string because = "", params object[] becauseArgs)
{
return EndWith(new[] { element }, ObjectExtensions.GetComparer<T>(), because, becauseArgs);
return EndWith([element], ObjectExtensions.GetComparer<T>(), because, becauseArgs);
}

/// <summary>
Expand Down Expand Up @@ -2182,7 +2182,7 @@ public AndConstraint<TAssertions> NotBeNullOrEmpty(string because = "", params o
.ForCondition(Subject is not null)
.FailWith("Expected {context:collection} to not contain {0}{reason}, but found <null>.", unexpected);

IEnumerable<T> matched = Enumerable.Empty<T>();
IEnumerable<T> matched = [];

if (success)
{
Expand Down Expand Up @@ -3259,7 +3259,7 @@ public AndConstraint<TAssertions> StartWith(IEnumerable<T> expectation, string b
/// </param>
public AndConstraint<TAssertions> StartWith(T element, string because = "", params object[] becauseArgs)
{
return StartWith(new[] { element }, ObjectExtensions.GetComparer<T>(), because, becauseArgs);
return StartWith([element], ObjectExtensions.GetComparer<T>(), because, becauseArgs);
}

internal AndConstraint<SubsequentOrderingAssertions<T>> BeOrderedBy<TSelector>(
Expand Down Expand Up @@ -3312,7 +3312,7 @@ protected static IEnumerable<TExpectation> RepeatAsManyAs<TExpectation>(TExpecta
{
if (enumerable is null)
{
return Enumerable.Empty<TExpectation>();
return [];
}

return RepeatAsManyAsIterator(value, enumerable);
Expand Down Expand Up @@ -3534,7 +3534,7 @@ private string[] CollectFailuresFromInspectors(IEnumerable<Action<T>> elementIns
.ForCondition(Subject is not null)
.FailWith($"Expected {{context:collection}} to be in {sortOrder} order{{reason}}, but found <null>.");

IOrderedEnumerable<T> ordering = new List<T>(0).OrderBy(x => x);
IOrderedEnumerable<T> ordering = Array.Empty<T>().OrderBy(x => x);

if (success)
{
Expand Down
Expand Up @@ -255,7 +255,7 @@ public GenericDictionaryAssertions(TCollection keyValuePairs)
public WhoseValueConstraint<TCollection, TKey, TValue, TAssertions> ContainKey(TKey expected,
string because = "", params object[] becauseArgs)
{
AndConstraint<TAssertions> andConstraint = ContainKeys(new[] { expected }, because, becauseArgs);
AndConstraint<TAssertions> andConstraint = ContainKeys([expected], because, becauseArgs);

_ = TryGetValue(Subject, expected, out TValue value);

Expand Down Expand Up @@ -447,7 +447,7 @@ public AndConstraint<TAssertions> NotContainKeys(params TKey[] unexpected)
string because = "", params object[] becauseArgs)
{
AndWhichConstraint<TAssertions, IEnumerable<TValue>> innerConstraint =
ContainValuesAndWhich(new[] { expected }, because, becauseArgs);
ContainValuesAndWhich([expected], because, becauseArgs);

return
new AndWhichConstraint<TAssertions, TValue>(
Expand Down
Expand Up @@ -23,9 +23,9 @@ internal class MaximumMatchingProblem<TValue>
Elements.AddRange(elements.Select((element, index) => new Element<TValue>(element, index)));
}

public List<Predicate<TValue>> Predicates { get; } = new();
public List<Predicate<TValue>> Predicates { get; } = [];

public List<Element<TValue>> Elements { get; } = new();
public List<Element<TValue>> Elements { get; } = [];

public MaximumMatchingSolution<TValue> Solve() => new MaximumMatchingSolver<TValue>(this).Solve();
}
Expand Up @@ -14,7 +14,7 @@ namespace FluentAssertions.Collections.MaximumMatching;
internal class MaximumMatchingSolver<TValue>
{
private readonly MaximumMatchingProblem<TValue> problem;
private readonly Dictionary<Predicate<TValue>, List<Element<TValue>>> matchingElementsByPredicate = new();
private readonly Dictionary<Predicate<TValue>, List<Element<TValue>>> matchingElementsByPredicate = [];

public MaximumMatchingSolver(MaximumMatchingProblem<TValue> problem)
{
Expand Down Expand Up @@ -76,7 +76,7 @@ private IEnumerable<Match> FindMatchForPredicate(Predicate<TValue> predicate, Ma
}
}

return Enumerable.Empty<Match>();
return [];
}

private List<Element<TValue>> GetMatchingElements(Predicate<TValue> predicate)
Expand All @@ -98,7 +98,7 @@ private struct Match

private sealed class MatchCollection : IEnumerable<Match>
{
private readonly Dictionary<Element<TValue>, Match> matchesByElement = new();
private readonly Dictionary<Element<TValue>, Match> matchesByElement = [];

public void UpdateFrom(IEnumerable<Match> matches)
{
Expand All @@ -123,7 +123,7 @@ public Predicate<TValue> GetMatchedPredicate(Element<TValue> element)
private sealed class BreadthFirstSearchTracker
{
private readonly Queue<Predicate<TValue>> unmatchedPredicatesQueue = new();
private readonly Dictionary<Predicate<TValue>, Match> previousMatchByPredicate = new();
private readonly Dictionary<Predicate<TValue>, Match> previousMatchByPredicate = [];

private readonly MatchCollection originalMatches;

Expand Down
Expand Up @@ -253,7 +253,7 @@ public AndConstraint<TAssertions> BeEquivalentTo(params string[] expectation)
.ForCondition(Subject is not null)
.FailWith("Expected {context:collection} to contain a match of {0}{reason}, but found <null>.", wildcardPattern);

IEnumerable<string> matched = new List<string>(0);
IEnumerable<string> matched = [];

if (success)
{
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Common/FullFrameworkReflector.cs
Expand Up @@ -47,11 +47,11 @@ private static IEnumerable<Type> GetExportedTypes(Assembly assembly)
}
catch (FileLoadException)
{
return Enumerable.Empty<Type>();
return [];
}
catch (Exception)
{
return Array.Empty<Type>();
return [];
}
}
}
4 changes: 1 addition & 3 deletions Src/FluentAssertions/Common/Guard.cs
Expand Up @@ -120,7 +120,5 @@ public static void ThrowIfArgumentIsNegative(decimal value, [CallerArgumentExpre
/// https://github.com/dotnet/roslyn-analyzers/issues/3451#issuecomment-606690452
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
private sealed class ValidatedNotNullAttribute : Attribute
{
}
private sealed class ValidatedNotNullAttribute : Attribute;
}

0 comments on commit 303e73a

Please sign in to comment.