Skip to content

Commit 0798ce7

Browse files
authored
Documentation (#57)
* refactor * add reporting documentation * docs: document public API of ModVerify.Reporting Add XML doc comments to the exposed (public) types in AET.ModVerify.Reporting following dotnet/runtime conventions: baselines, suppressions, engine error collection, and reporters. Internal JSON DTOs and concrete reporter implementations are left undocumented. * add verifier documentation * update deps * update sub and deps
1 parent 0d5a16f commit 0798ce7

38 files changed

Lines changed: 474 additions & 98 deletions

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300" PrivateAssets="All"/>
3737
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
3838
<PrivateAssets>all</PrivateAssets>
39-
<Version>3.10.85</Version>
39+
<Version>3.10.91</Version>
4040
</PackageReference>
4141
</ItemGroup>
4242

src/ModVerify/Reporting/Baseline/BaselineCollection.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77

88
namespace AET.ModVerify.Reporting.Baseline;
99

10+
/// <summary>Represents a set of identified verification baselines, each distinguished by a unique identifier.</summary>
1011
public sealed class BaselineCollection : IReadOnlyCollection<IdentifiedBaseline>
1112
{
13+
/// <summary>Gets an empty <see cref="BaselineCollection"/> that contains no baselines.</summary>
1214
public static readonly BaselineCollection Empty = new([]);
1315

1416
private readonly IReadOnlyList<IdentifiedBaseline> _baselines;
1517

18+
/// <inheritdoc />
1619
public int Count => _baselines.Count;
1720

21+
/// <summary>Gets a value that indicates whether the collection contains no baselines.</summary>
22+
/// <value><see langword="true"/> if the collection contains no baselines; otherwise, <see langword="false"/>.</value>
1823
public bool IsEmpty => _baselines.Count == 0;
1924

25+
/// <summary>Initializes a new instance of the <see cref="BaselineCollection"/> class with the specified baselines.</summary>
26+
/// <param name="baselines">The identified baselines to include in the collection.</param>
27+
/// <exception cref="ArgumentNullException"><paramref name="baselines"/> is <see langword="null"/>.</exception>
28+
/// <exception cref="ArgumentException">An entry in <paramref name="baselines"/> is <see langword="null"/>, or two entries share the same identifier.</exception>
2029
public BaselineCollection(IEnumerable<IdentifiedBaseline> baselines)
2130
{
2231
if (baselines is null)
@@ -35,6 +44,9 @@ public BaselineCollection(IEnumerable<IdentifiedBaseline> baselines)
3544
_baselines = list;
3645
}
3746

47+
/// <summary>Determines whether any baseline in the collection contains the specified error.</summary>
48+
/// <param name="error">The verification error to locate.</param>
49+
/// <returns><see langword="true"/> if a baseline in the collection contains <paramref name="error"/>; otherwise, <see langword="false"/>.</returns>
3850
public bool Contains(VerificationError error)
3951
{
4052
foreach (var entry in _baselines)
@@ -45,6 +57,10 @@ public bool Contains(VerificationError error)
4557
return false;
4658
}
4759

60+
/// <summary>Gets the identifier of the first baseline in the collection that contains the specified error.</summary>
61+
/// <param name="error">The verification error to locate.</param>
62+
/// <param name="identifier">When this method returns, contains the identifier of the matching baseline if a match was found, or <see langword="null"/> if no baseline contains the error. This parameter is treated as uninitialized.</param>
63+
/// <returns><see langword="true"/> if a baseline containing <paramref name="error"/> was found; otherwise, <see langword="false"/>.</returns>
4864
public bool TryGetMatchingBaseline(VerificationError error, [NotNullWhen(true)] out string? identifier)
4965
{
5066
foreach (var entry in _baselines)
@@ -59,6 +75,10 @@ public bool TryGetMatchingBaseline(VerificationError error, [NotNullWhen(true)]
5975
return false;
6076
}
6177

78+
/// <summary>Filters out the errors that are contained in any baseline of the collection.</summary>
79+
/// <param name="errors">The errors to filter.</param>
80+
/// <returns>The errors that are not contained in any baseline of the collection.</returns>
81+
/// <exception cref="ArgumentNullException"><paramref name="errors"/> is <see langword="null"/>.</exception>
6282
public IEnumerable<VerificationError> Apply(IEnumerable<VerificationError> errors)
6383
{
6484
if (errors is null)
@@ -68,6 +88,13 @@ public IEnumerable<VerificationError> Apply(IEnumerable<VerificationError> error
6888
return errors.Where(e => !Contains(e));
6989
}
7090

91+
/// <summary>Categorizes the specified errors into new, persistent, and resolved errors relative to the baselines in the collection.</summary>
92+
/// <param name="errors">The errors found during verification.</param>
93+
/// <returns>
94+
/// The errors grouped into those not present in any baseline, those matching a baseline, and those present in a
95+
/// baseline but not found again during verification.
96+
/// </returns>
97+
/// <exception cref="ArgumentNullException"><paramref name="errors"/> is <see langword="null"/>.</exception>
7198
public CategorizedVerificationErrors Categorize(IEnumerable<VerificationError> errors)
7299
{
73100
if (errors is null)
@@ -102,6 +129,7 @@ public CategorizedVerificationErrors Categorize(IEnumerable<VerificationError> e
102129
new ReadOnlyValueListDictionary<string, VerificationError>(resolved));
103130
}
104131

132+
/// <inheritdoc />
105133
public IEnumerator<IdentifiedBaseline> GetEnumerator()
106134
{
107135
return _baselines.GetEnumerator();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace AET.ModVerify.Reporting.Baseline;
22

3+
/// <summary>Specifies the origin of a verification baseline.</summary>
34
public enum BaselineSource
45
{
6+
/// <summary>The baseline was loaded from a file on disk.</summary>
57
File,
8+
/// <summary>The baseline is the default baseline embedded in the application.</summary>
69
EmbeddedDefault,
710
}
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
using PG.StarWarsGame.Engine;
1+
using PG.StarWarsGame.Engine;
22

33
namespace AET.ModVerify.Reporting.Baseline;
44

5+
/// <summary>Represents the target that a verification baseline was created for.</summary>
56
public sealed record BaselineVerificationTarget
6-
{
7+
{
8+
/// <summary>Gets or sets the game engine type of the target.</summary>
79
public required GameEngineType Engine { get; init; }
10+
11+
/// <summary>Gets or sets the name of the target.</summary>
812
public required string Name { get; init; }
9-
public GameLocations? Location { get; init; } // Optional compared to Verification Target
13+
14+
/// <summary>Gets or sets the game locations of the target, or <see langword="null"/> if not specified.</summary>
15+
/// <remarks>The location is optional for a baseline target, unlike for a verification target.</remarks>
16+
public GameLocations? Location { get; init; }
17+
18+
/// <summary>Gets or sets the version of the target, or <see langword="null"/> if not specified.</summary>
1019
public string? Version { get; init; }
20+
21+
/// <summary>Gets or sets a value that indicates whether the target is the base game rather than a mod.</summary>
22+
/// <value>
23+
/// <see langword="true"/> if the target is the base game; otherwise, <see langword="false"/>.
24+
/// The default is <see langword="false"/>.
25+
/// </value>
1126
public bool IsGame { get; init; }
1227
}

src/ModVerify/Reporting/Baseline/IdentifiedBaseline.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
namespace AET.ModVerify.Reporting.Baseline;
44

5+
/// <summary>Associates a verification baseline with a unique identifier and the source it was loaded from.</summary>
56
public sealed record IdentifiedBaseline
67
{
8+
/// <summary>Gets the unique identifier of the baseline within its collection.</summary>
79
public string Identifier { get; }
810

11+
/// <summary>Gets the verification baseline.</summary>
912
public VerificationBaseline Baseline { get; }
1013

14+
/// <summary>Gets the source the baseline was loaded from.</summary>
1115
public BaselineSource Source { get; }
1216

17+
/// <summary>Initializes a new instance of the <see cref="IdentifiedBaseline"/> class.</summary>
18+
/// <param name="identifier">The unique identifier of the baseline within its collection.</param>
19+
/// <param name="baseline">The verification baseline.</param>
20+
/// <param name="source">One of the enumeration values that specifies the source the baseline was loaded from.</param>
21+
/// <exception cref="ArgumentException"><paramref name="identifier"/> is <see langword="null"/> or empty.</exception>
22+
/// <exception cref="ArgumentNullException"><paramref name="baseline"/> is <see langword="null"/>.</exception>
1323
public IdentifiedBaseline(string identifier, VerificationBaseline baseline, BaselineSource source)
1424
{
1525
if (string.IsNullOrEmpty(identifier))

src/ModVerify/Reporting/Baseline/InvalidBaselineException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
1+
using System;
22

33
namespace AET.ModVerify.Reporting.Baseline;
44

5+
/// <summary>The exception that is thrown when a verification baseline cannot be parsed or is otherwise invalid.</summary>
56
public sealed class InvalidBaselineException : Exception
67
{
78
internal InvalidBaselineException(string message) : base(message)

src/ModVerify/Reporting/Baseline/VerificationBaseline.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
@@ -11,24 +11,34 @@
1111

1212
namespace AET.ModVerify.Reporting.Baseline;
1313

14+
/// <summary>Represents a frozen set of verification errors that are already known and should be ignored during verification.</summary>
1415
public sealed class VerificationBaseline : IReadOnlyCollection<VerificationError>
1516
{
17+
/// <summary>Gets the latest supported baseline format version.</summary>
1618
public static readonly Version LatestVersion = new(2, 2);
19+
20+
/// <summary>Gets the latest supported baseline format version as a string with two components.</summary>
1721
public static readonly string LatestVersionString = LatestVersion.ToString(2);
1822

23+
/// <summary>Gets an empty <see cref="VerificationBaseline"/> that contains no errors.</summary>
1924
public static readonly VerificationBaseline Empty = new(VerificationSeverity.Information, [], null);
2025

2126
private readonly HashSet<VerificationError> _errors;
2227

28+
/// <summary>Gets the target that this baseline was created for, or <see langword="null"/> if not specified.</summary>
2329
public BaselineVerificationTarget? Target { get; }
24-
30+
31+
/// <summary>Gets the format version of this baseline, or <see langword="null"/> if unknown.</summary>
2532
public Version? Version { get; }
2633

34+
/// <summary>Gets the minimum severity of the errors recorded in this baseline.</summary>
2735
public VerificationSeverity MinimumSeverity { get; }
2836

2937
/// <inheritdoc />
3038
public int Count => _errors.Count;
3139

40+
/// <summary>Gets a value that indicates whether the baseline contains no errors.</summary>
41+
/// <value><see langword="true"/> if the baseline contains no errors; otherwise, <see langword="false"/>.</value>
3242
public bool IsEmpty => Count == 0;
3343

3444
internal VerificationBaseline(JsonVerificationBaseline baseline)
@@ -39,33 +49,55 @@ internal VerificationBaseline(JsonVerificationBaseline baseline)
3949
Target = JsonVerificationTarget.ToTarget(baseline.Target);
4050
}
4151

52+
/// <summary>Initializes a new instance of the <see cref="VerificationBaseline"/> class.</summary>
53+
/// <param name="minimumSeverity">One of the enumeration values that specifies the minimum severity of the errors recorded in the baseline.</param>
54+
/// <param name="errors">The errors to record in the baseline.</param>
55+
/// <param name="target">The target the baseline was created for, or <see langword="null"/> if not specified.</param>
56+
/// <exception cref="ArgumentNullException"><paramref name="errors"/> is <see langword="null"/>.</exception>
4257
public VerificationBaseline(VerificationSeverity minimumSeverity, IEnumerable<VerificationError> errors, BaselineVerificationTarget? target)
4358
{
59+
if (errors == null) throw new ArgumentNullException(nameof(errors));
4460
_errors = [..errors];
4561
Version = LatestVersion;
4662
MinimumSeverity = minimumSeverity;
4763
Target = target;
4864
}
4965

66+
/// <summary>Determines whether the baseline contains the specified error.</summary>
67+
/// <param name="error">The verification error to locate.</param>
68+
/// <returns><see langword="true"/> if the baseline contains <paramref name="error"/>; otherwise, <see langword="false"/>.</returns>
5069
public bool Contains(VerificationError error)
5170
{
5271
return _errors.Contains(error);
5372
}
5473

74+
/// <summary>Filters out the errors that are contained in the baseline.</summary>
75+
/// <param name="errors">The errors to filter.</param>
76+
/// <returns>The errors that are not contained in the baseline.</returns>
5577
public IEnumerable<VerificationError> Apply(IEnumerable<VerificationError> errors)
5678
{
5779
return Count == 0 ? errors : errors.Where(e => !_errors.Contains(e));
5880
}
5981

82+
/// <summary>Serializes the baseline as JSON to the specified stream.</summary>
83+
/// <param name="stream">The stream to write the JSON representation to.</param>
6084
public void ToJson(Stream stream)
6185
{
6286
JsonSerializer.Serialize(stream, new JsonVerificationBaseline(this), ModVerifyJsonSettings.JsonSettings);
6387
}
88+
89+
/// <summary>Asynchronously serializes the baseline as JSON to the specified stream.</summary>
90+
/// <param name="stream">The stream to write the JSON representation to.</param>
91+
/// <returns>A task that represents the asynchronous serialization operation.</returns>
6492
public Task ToJsonAsync(Stream stream)
6593
{
6694
return JsonSerializer.SerializeAsync(stream, new JsonVerificationBaseline(this), ModVerifyJsonSettings.JsonSettings);
6795
}
6896

97+
/// <summary>Deserializes a baseline from its JSON representation.</summary>
98+
/// <param name="stream">The stream to read the JSON representation from.</param>
99+
/// <returns>The deserialized baseline.</returns>
100+
/// <exception cref="InvalidBaselineException">The JSON representation is invalid or cannot be parsed.</exception>
69101
public static VerificationBaseline FromJson(Stream stream)
70102
{
71103
return JsonBaselineParser.Parse(stream);
@@ -82,6 +114,7 @@ IEnumerator IEnumerable.GetEnumerator()
82114
return GetEnumerator();
83115
}
84116

117+
/// <inheritdoc />
85118
public override string ToString()
86119
{
87120
var sb = new StringBuilder($"Baseline [Version={Version}, MinSeverity={MinimumSeverity}, NumErrors={Count}");

src/ModVerify/Reporting/Engine/EngineErrorReporterBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal abstract class EngineErrorReporterBase<T> : IGameVerifierInfo
1515

1616
public IReadOnlyList<IGameVerifierInfo> VerifierChain { get; }
1717

18-
public string Name => GetType().FullName;
18+
public string Name => GetType().FullName!;
1919

2020
public abstract string FriendlyName { get; }
2121

src/ModVerify/Reporting/Engine/GameEngineErrorCollection.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
using System.Collections.Concurrent;
1+
using System.Collections.Concurrent;
22
using System.Collections.Generic;
33
using System.Linq;
44
using PG.StarWarsGame.Engine.ErrorReporting;
55
using PG.StarWarsGame.Files.XML.ErrorHandling;
66

77
namespace AET.ModVerify.Reporting.Engine;
88

9+
/// <summary>Collects the XML, initialization, and assertion errors reported by the game engine during verification.</summary>
910
public sealed class GameEngineErrorCollection : IGameEngineErrorCollection, IGameEngineErrorReporter
1011
{
11-
private readonly ConcurrentBag<XmlError> _xmlErrors = new();
12-
private readonly ConcurrentBag<InitializationError> _initializationErrors = new();
13-
private readonly ConcurrentBag<EngineAssert> _asserts = new();
12+
private readonly ConcurrentBag<XmlError> _xmlErrors = [];
13+
private readonly ConcurrentBag<InitializationError> _initializationErrors = [];
14+
private readonly ConcurrentBag<EngineAssert> _asserts = [];
1415

16+
/// <inheritdoc />
1517
public IEnumerable<XmlError> XmlErrors => _xmlErrors.ToList();
1618

19+
/// <inheritdoc />
1720
public IEnumerable<InitializationError> InitializationErrors => _initializationErrors.ToList();
1821

22+
/// <inheritdoc />
1923
public IEnumerable<EngineAssert> Asserts => _asserts.ToList();
2024

2125
void IXmlParserErrorReporter.Report(XmlError error)

0 commit comments

Comments
 (0)