Skip to content
Merged
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
3 changes: 2 additions & 1 deletion Broadside.Core.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"tests/Broadside.Rendering.Tests/Broadside.Rendering.Tests.csproj",
"tests/Broadside.Rendering.Skia.Tests/Broadside.Rendering.Skia.Tests.csproj",
"tests/Broadside.Fonts.Standard14.Tests/Broadside.Fonts.Standard14.Tests.csproj",
"tests/Broadside.Fonts.Cmaps.Tests/Broadside.Fonts.Cmaps.Tests.csproj"
"tests/Broadside.Fonts.Cmaps.Tests/Broadside.Fonts.Cmaps.Tests.csproj",
"tests/ConformanceCheck.Tests/ConformanceCheck.Tests.csproj"
]
}
}
2 changes: 2 additions & 0 deletions Broadside.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
<Project Path="tests/Broadside.Rendering.Tests/Broadside.Rendering.Tests.csproj" />
<Project Path="tests/Broadside.Tests/Broadside.Tests.csproj" />
<Project Path="tests/Broadside.TestSupport/Broadside.TestSupport.csproj" />
<Project Path="tests/ConformanceCheck.Tests/ConformanceCheck.Tests.csproj" />
</Folder>
<Folder Name="/tools/">
<Project Path="tools/ConformanceCheck/ConformanceCheck.csproj" />
<Project Path="tools/CorpusFetcher/CorpusFetcher.csproj" />
</Folder>
</Solution>
42 changes: 42 additions & 0 deletions docs/conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,45 @@ One file per specification. One row per clause. Status is one of `not started`,
| [iso-14289-2.md](./iso-14289-2.md) | ISO 14289-2:2024 PDF/UA-2 |

PDF/A and PDF/X get files when their documents are purchased; see `docs/research/missing-iso-specs.md`. The PDF Association's Tagged PDF Best Practice Guide in `Specs/` is guidance, not a conformance target.

## Row format

Every table has exactly these six columns, in this order:

| Cell | Content |
|---|---|
| Clause | The clause number as the specification numbers it (`7.5.4`, `Annex F`, `BPC-1`). Unique within the file. |
| Title | The clause title from the specification's table of contents. |
| Status | `not started`, `partial`, `done` or `n/a`, exactly, in lower case. |
| Implementing types | Empty, or a comma-separated list of backticked simple type names declared under `src/`: `` `CosDictionary`, `CosLexer` ``. No namespace, no type arguments (`` `CosArray` `` for `CosArray<T>`). Each must be the name of a `class`, `struct`, `interface`, `enum` or `record` in `src/**/*.cs`. |
| Tests | Empty, or a comma-separated list of backticked test identifiers, each a fully qualified test method `` `Namespace.Class.Method` `` or a test class `` `Namespace.Class` ``: `` `Broadside.Tests.Cos.LexerTests.Reads_names`, `Broadside.Tests.Cos.FilterTests` ``. The class is the one that directly declares the method, in the namespace its file declares; the method must carry `[Fact]` or `[Theory]`. Each must exist under `tests/**/*.cs`. |
| Notes | Free text. Required on `n/a` rows (why the clause is not applicable) and, under `--strict`, on `partial` rows (what is still missing). |

A `|` inside a cell is written `\|`.

## Rules

`tools/ConformanceCheck` enforces these over every `docs/conformance/*.md` except this README; each failure is printed as `docs/conformance/<file>.md:<line>: <message>`.

1. Every table row has exactly six cells, and the header row is `Clause | Title | Status | Implementing types | Tests | Notes`.
2. Clause is non-empty and unique within the file.
3. Status is one of `not started`, `partial`, `done`, `n/a`.
4. A `done` row names at least one test in the Tests cell.
5. An `n/a` row has a non-empty Notes cell.
6. Every identifier in the Tests cell resolves to a test class or a `[Fact]`/`[Theory]` method under `tests/`.
7. Every name in the Implementing types cell is declared as a `class`, `struct`, `interface`, `enum` or `record` under `src/`.
8. With `--strict` only: a `partial` row names at least one test and has a non-empty Notes cell.

The code lookups are a line-level scan of the `.cs` files (`namespace`, type and attributed method declarations), not a compile, so they run in milliseconds and need no build; `bin`, `obj` and `Fixtures` directories are skipped.

## Running the checker

```sh
dotnet run --project tools/ConformanceCheck -- --summary # from anywhere inside the checkout
dotnet run --project tools/ConformanceCheck -- --root . --summary # what CI runs, from the repository root
dotnet run --project tools/ConformanceCheck -- --strict # also require tests and notes on partial rows
```

`--root` defaults to the nearest parent of the current directory that contains `Broadside.slnx`. `--summary` prints a Markdown table of row counts per status for every file plus a total. The exit code is 0 when the map is valid and 1 when any rule fails.

The checker runs in three places: the `conformance` CI job runs `dotnet run --project tools/ConformanceCheck -- --root . --summary` on every pull request; `tests/ConformanceCheck.Tests` runs the same validation against the checkout as part of `dotnet test Broadside.Core.slnf`, so a wrong row also fails the test suite; and the fixture tests in that project pin the exact violation for each rule.
20 changes: 20 additions & 0 deletions tests/ConformanceCheck.Tests/ConformanceCheck.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- Drives tools/ConformanceCheck against fixture repositories (one per rule) and against this checkout. -->
<PropertyGroup>
<RootNamespace>Broadside.Tools.ConformanceCheck.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../tools/ConformanceCheck/ConformanceCheck.csproj" />
<PackageReference Include="xunit.v3" />
</ItemGroup>

<!-- Fixtures are tiny fake repositories: their .cs files are scanned by the checker, never compiled, and are copied next to the test assembly. -->
<ItemGroup>
<Compile Remove="Fixtures/**" />
<None Remove="Fixtures/**" />
<None Include="Fixtures/**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
132 changes: 132 additions & 0 deletions tests/ConformanceCheck.Tests/ConformanceCheckerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
namespace Broadside.Tools.ConformanceCheck.Tests;

/// <summary>
/// One fixture repository per rule under <c>Fixtures/</c> (copied next to the test assembly), each with a <c>docs/conformance/x.md</c>,
/// a <c>tests/Foo.Tests/FooTests.cs</c> and a <c>src/Foo/Foo.cs</c>, plus a run against the real checkout so <c>dotnet test</c> fails when the map is wrong.
/// </summary>
public class ConformanceCheckerTests
{
private const string FixtureFile = "docs/conformance/x.md";

[Fact]
public void Valid_map_has_no_violations()
{
ConformanceReport report = Check("valid");

Assert.Empty(report.Violations);
Assert.True(report.IsValid);
ConformanceFile file = Assert.Single(report.Files);
Assert.Equal(FixtureFile, file.File);
Assert.Equal(4, file.Rows.Count);
Assert.Equal(1, file.Count(ConformanceStatus.Done));
Assert.Equal(1, file.Count(ConformanceStatus.Partial));
Assert.Equal(1, file.Count(ConformanceStatus.NotApplicable));
Assert.Equal(1, file.Count(ConformanceStatus.NotStarted));
}

[Fact]
public void Valid_map_summary_lists_every_status_and_a_total()
{
ConformanceReport report = Check("valid");

string expected = string.Join(
Environment.NewLine,
"| Specification | not started | partial | done | n/a | Rows |",
"|---|---:|---:|---:|---:|---:|",
"| x.md | 1 | 1 | 1 | 1 | 4 |",
"| **Total** | 1 | 1 | 1 | 1 | 4 |");
Assert.Equal(expected, report.ToMarkdownSummary());
}

[Fact]
public void Done_row_without_tests_is_a_violation()
{
AssertSingleViolation("done-without-tests", $"{FixtureFile}:5: done row must name at least one test in the Tests cell");
}

[Fact]
public void Done_row_naming_a_test_that_does_not_exist_is_a_violation()
{
AssertSingleViolation(
"done-with-missing-test",
$"{FixtureFile}:7: test 'Foo.Tests.FooTests.Helper' was not found in tests/: no class 'Foo.Tests.FooTests.Helper' and no [Fact]/[Theory] method 'Helper' on class 'Foo.Tests.FooTests'");
}

[Fact]
public void Unknown_status_is_a_violation()
{
AssertSingleViolation("bad-status", $"{FixtureFile}:5: status 'in progress' is not one of: not started, partial, done, n/a");
}

[Fact]
public void Row_with_wrong_cell_count_is_a_violation()
{
AssertSingleViolation("wrong-cell-count", $"{FixtureFile}:5: expected 6 cells (Clause, Title, Status, Implementing types, Tests, Notes) but found 5");
}

[Fact]
public void Na_row_without_notes_is_a_violation()
{
AssertSingleViolation("na-without-notes", $"{FixtureFile}:5: n/a row must say why in the Notes cell");
}

[Fact]
public void Duplicate_clause_is_a_violation()
{
AssertSingleViolation("duplicate-clause", $"{FixtureFile}:7: duplicate clause '1' (first at line 5)");
}

[Fact]
public void Implementing_type_that_does_not_exist_is_a_violation()
{
AssertSingleViolation("missing-implementing-type", $"{FixtureFile}:5: implementing type 'Bar' is not declared as a class, struct, interface, enum or record in src/");
}

[Fact]
public void Partial_row_without_tests_or_notes_passes_unless_strict()
{
Assert.Empty(Check("partial-without-tests").Violations);

ConformanceReport strict = Check("partial-without-tests", strict: true);

Assert.Equal(
[
$"{FixtureFile}:7: partial row must name at least one test in the Tests cell (--strict)",
$"{FixtureFile}:7: partial row must say what is missing in the Notes cell (--strict)",
],
strict.Violations.Select(static violation => violation.ToString()).ToArray());
}

[Fact]
public void Root_without_a_conformance_directory_throws()
{
Assert.Throws<DirectoryNotFoundException>(() => ConformanceChecker.Check(Path.Combine(FixturesDirectory, "valid", "src"), strict: false));
}

[Fact]
public void Repository_conformance_map_is_valid()
{
string root = RepositoryLocator.FindRoot(AppContext.BaseDirectory)
?? throw new DirectoryNotFoundException($"Could not find {RepositoryLocator.Marker} above '{AppContext.BaseDirectory}'.");

ConformanceReport report = ConformanceChecker.Check(root, strict: false);

Assert.Empty(report.Violations.Select(static violation => violation.ToString()));
Assert.NotEmpty(report.Files);
Assert.Contains(report.Files, static file => file.File == "docs/conformance/iso-32000-2.md");
Assert.DoesNotContain(report.Files, static file => file.File.EndsWith("README.md", StringComparison.Ordinal));
}

private static string FixturesDirectory => Path.Combine(AppContext.BaseDirectory, "Fixtures");

private static ConformanceReport Check(string fixture, bool strict = false) => ConformanceChecker.Check(Path.Combine(FixturesDirectory, fixture), strict);

private static void AssertSingleViolation(string fixture, string expected)
{
ConformanceReport report = Check(fixture);

Violation violation = Assert.Single(report.Violations);
Assert.Equal(expected, violation.ToString());
Assert.False(report.IsValid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fixture spec: unknown status value

| Clause | Title | Status | Implementing types | Tests | Notes |
|---|---|---|---|---|---|
| 1 | Parsing | in progress | | | |
| 2 | Later | not started | | | |
12 changes: 12 additions & 0 deletions tests/ConformanceCheck.Tests/Fixtures/bad-status/src/Foo/Foo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Foo;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public sealed class Foo
{
}

public interface IFoo
{
}

public readonly record struct FooOptions(int Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Xunit;

namespace Foo.Tests;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public class FooTests
{
[Fact]
public void Parses()
{
}

[Theory]
[InlineData(1)]
public void Rejects(int value)
{
}

// Not a test: no [Fact] or [Theory], so the conformance map may not cite it.
public void Helper()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Fixture spec: done row naming a test that does not exist

`Helper` is a method of `FooTests` but carries no `[Fact]` or `[Theory]`, so it is not a test.

| Clause | Title | Status | Implementing types | Tests | Notes |
|---|---|---|---|---|---|
| 1 | Parsing | done | `Foo` | `Foo.Tests.FooTests.Helper` | |
| 2 | Later | not started | | | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Foo;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public sealed class Foo
{
}

public interface IFoo
{
}

public readonly record struct FooOptions(int Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Xunit;

namespace Foo.Tests;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public class FooTests
{
[Fact]
public void Parses()
{
}

[Theory]
[InlineData(1)]
public void Rejects(int value)
{
}

// Not a test: no [Fact] or [Theory], so the conformance map may not cite it.
public void Helper()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fixture spec: done row without tests

| Clause | Title | Status | Implementing types | Tests | Notes |
|---|---|---|---|---|---|
| 1 | Parsing | done | `Foo` | | |
| 2 | Later | not started | | | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Foo;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public sealed class Foo
{
}

public interface IFoo
{
}

public readonly record struct FooOptions(int Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Xunit;

namespace Foo.Tests;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public class FooTests
{
[Fact]
public void Parses()
{
}

[Theory]
[InlineData(1)]
public void Rejects(int value)
{
}

// Not a test: no [Fact] or [Theory], so the conformance map may not cite it.
public void Helper()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Fixture spec: the same clause twice

| Clause | Title | Status | Implementing types | Tests | Notes |
|---|---|---|---|---|---|
| 1 | Parsing | not started | | | |
| 2 | Later | not started | | | |
| 1 | Parsing again | not started | | | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Foo;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public sealed class Foo
{
}

public interface IFoo
{
}

public readonly record struct FooOptions(int Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Xunit;

namespace Foo.Tests;

// Fixture for tools/ConformanceCheck: scanned by the checker, never compiled.
public class FooTests
{
[Fact]
public void Parses()
{
}

[Theory]
[InlineData(1)]
public void Rejects(int value)
{
}

// Not a test: no [Fact] or [Theory], so the conformance map may not cite it.
public void Helper()
{
}
}
Loading
Loading