From 1ecfeac852aefbd8cc8d9223ec289255952ffcda Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Tue, 14 Jul 2026 07:33:33 -0700 Subject: [PATCH] Unify identical ThisAsPointerTest baselines and document the convention The Windows and Unix baselines are byte-identical for each config, so collapse them to the config-level file per the harness fallback chain. Also correct the generator test-model section of the Copilot instructions to describe the actual Baseline harness and require unifying identical baselines by default. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/copilot-instructions.md | 28 +++++++++++++------ ...AsPointerTest.CSharp.Compatible.Windows.cs | 22 --------------- ...=> ThisAsPointerTest.CSharp.Compatible.cs} | 0 ...cs => ThisAsPointerTest.CSharp.Default.cs} | 0 ...ThisAsPointerTest.CSharp.Latest.Windows.cs | 21 -------------- ....cs => ThisAsPointerTest.CSharp.Latest.cs} | 0 .../ThisAsPointerTest.CSharp.Preview.Unix.cs | 21 -------------- ...hisAsPointerTest.CSharp.Preview.Windows.cs | 21 -------------- ...cs => ThisAsPointerTest.CSharp.Preview.cs} | 0 ...isAsPointerTest.Xml.Compatible.Windows.xml | 19 ------------- ...l => ThisAsPointerTest.Xml.Compatible.xml} | 0 ....xml => ThisAsPointerTest.Xml.Default.xml} | 0 .../ThisAsPointerTest.Xml.Latest.Windows.xml | 19 ------------- ...s.xml => ThisAsPointerTest.Xml.Latest.xml} | 0 .../ThisAsPointerTest.Xml.Preview.Unix.xml | 19 ------------- .../ThisAsPointerTest.Xml.Preview.Windows.xml | 19 ------------- ....xml => ThisAsPointerTest.Xml.Preview.xml} | 0 17 files changed, 20 insertions(+), 169 deletions(-) delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.Windows.cs rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.CSharp.Compatible.Unix.cs => ThisAsPointerTest.CSharp.Compatible.cs} (100%) rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.CSharp.Default.Unix.cs => ThisAsPointerTest.CSharp.Default.cs} (100%) delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.Windows.cs rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.CSharp.Default.Windows.cs => ThisAsPointerTest.CSharp.Latest.cs} (100%) delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Unix.cs delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Windows.cs rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.CSharp.Latest.Unix.cs => ThisAsPointerTest.CSharp.Preview.cs} (100%) delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.Windows.xml rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.Xml.Compatible.Unix.xml => ThisAsPointerTest.Xml.Compatible.xml} (100%) rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.Xml.Default.Unix.xml => ThisAsPointerTest.Xml.Default.xml} (100%) delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.Windows.xml rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.Xml.Default.Windows.xml => ThisAsPointerTest.Xml.Latest.xml} (100%) delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Unix.xml delete mode 100644 tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Windows.xml rename tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/{ThisAsPointerTest.Xml.Latest.Unix.xml => ThisAsPointerTest.Xml.Preview.xml} (100%) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 136c2fcf..4079ca85 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -32,17 +32,29 @@ The baseline builds with **0 warnings**; keep it that way. ## Generator test model (read before touching generator output) -Tests are **golden-file** and cover a matrix. `tests/ClangSharp.PInvokeGenerator.UnitTests/Base/*` defines -abstract `*Impl` test methods; per-configuration folders implement them with **inline expected output**: +Tests are **golden-file** and cover a matrix of `CSharp`/`Xml` × `Default`/`Latest`/`Preview`/`Compatible` +× `Windows`/`Unix` (16 variants). Fixtures live in `tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/*.cs` +(e.g. `FunctionDeclarationBodyImportTest`), derive from `BaselineTest`, and are parameterized over every +variant via `[TestFixtureSource]`. A concrete case supplies its C/C++ `inputContents` and a case name once +by calling `ValidateAsync(nameof(TheTest), inputContents, ...)`; the **expected output is a checked-in +baseline file**, not inline text. -- Output modes × language levels × OS: `CSharp`/`Xml` × `Default`/`Latest`/`Preview`/`Compatible` × `Windows`/`Unix`. -- Concrete cases feed `inputContents` (C/C++) + `expectedOutputContents` to `ValidateGenerated...Async`. +Baselines live under `Baseline/Baselines/{Area}/` and are resolved per variant via a most-specific-first +fallback chain (`BaselineHarness.CandidateNames`): +`{Case}.{Mode}.{Config}.{Os}.{ext}` → `{Case}.{Mode}.{Config}.{ext}` → `{Case}.{Mode}.{ext}`. Consequences when you change generator output: -- Update **every affected configuration variant**, not just one — the same case is duplicated across folders. -- Windows/Unix variants are `[Platform(...)]`-gated, so a single-OS run only exercises half the matrix. - CI runs Windows + Linux + macOS (x64 and arm64); confirm both `Windows` and `Unix` expected outputs. -- Add a regression test in `Base/` (+ all variants) for any fix; that is the established pattern here. +- Regenerate baselines with `UPDATE_BASELINES=1` (it also implies `RUN_ALL_VARIANTS=1`, so both OSes are + written from one host via the pinned Unix triple). This writes the **most-specific** file for every + variant — i.e. fully expanded — so you **must then unify** (see below). +- **Always unify identical baselines — do not check in duplicates.** Collapse output that is identical + across the OS axis to the `{Case}.{Mode}.{Config}.{ext}` level, and collapse output identical across + **all 16** variants to a single `{Case}.{Mode}.{ext}` per mode. Keep one file per `Config` when configs + differ, even if two happen to match (matching `AccessUnionMemberTest` / `VirtualTest`); do **not** invent + a global-plus-override mix — the repo doesn't use it. Verify a collapse with + `RUN_ALL_VARIANTS=1 dotnet test ... --filter FullyQualifiedName~TheTest` so both OSes are checked against + the collapsed files. +- Add a regression test (in the matching `Baseline/*Test.cs`) for any fix; that is the established pattern. ## Regenerating the self-hosted bindings diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.Windows.cs deleted file mode 100644 index 3a528a8f..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.Windows.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace ClangSharp.Test -{ - public partial struct TestInterface_ - { - [NativeTypeName("int (*)(MyStruct *)")] - public IntPtr TestMethod; - } - - public unsafe partial struct MyStruct_ - { - [NativeTypeName("const struct TestInterface_ *")] - public TestInterface_* functions; - - public int TestMethod() - { - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - } - } -} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.cs similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.Unix.cs rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Compatible.cs diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Default.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Default.cs similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Default.Unix.cs rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Default.cs diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.Windows.cs deleted file mode 100644 index b614c93a..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.Windows.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace ClangSharp.Test -{ - public unsafe partial struct TestInterface_ - { - [NativeTypeName("int (*)(MyStruct *)")] - public delegate* unmanaged[Cdecl] TestMethod; - } - - public unsafe partial struct MyStruct_ - { - [NativeTypeName("const struct TestInterface_ *")] - public TestInterface_* functions; - - public int TestMethod() - { - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - } - } -} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Default.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.cs similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Default.Windows.cs rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.cs diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Unix.cs deleted file mode 100644 index b614c93a..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Unix.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace ClangSharp.Test -{ - public unsafe partial struct TestInterface_ - { - [NativeTypeName("int (*)(MyStruct *)")] - public delegate* unmanaged[Cdecl] TestMethod; - } - - public unsafe partial struct MyStruct_ - { - [NativeTypeName("const struct TestInterface_ *")] - public TestInterface_* functions; - - public int TestMethod() - { - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - } - } -} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Windows.cs deleted file mode 100644 index b614c93a..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.Windows.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace ClangSharp.Test -{ - public unsafe partial struct TestInterface_ - { - [NativeTypeName("int (*)(MyStruct *)")] - public delegate* unmanaged[Cdecl] TestMethod; - } - - public unsafe partial struct MyStruct_ - { - [NativeTypeName("const struct TestInterface_ *")] - public TestInterface_* functions; - - public int TestMethod() - { - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - } - } -} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.cs similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Latest.Unix.cs rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.CSharp.Preview.cs diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.Windows.xml deleted file mode 100644 index 07bfe207..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.Windows.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - IntPtr - - - - - TestInterface_* - - - int - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - - - - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.xml similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.Unix.xml rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Compatible.xml diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Default.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Default.xml similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Default.Unix.xml rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Default.xml diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.Windows.xml deleted file mode 100644 index 415de9ed..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.Windows.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - delegate* unmanaged[Cdecl]<MyStruct_*, int> - - - - - TestInterface_* - - - int - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - - - - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Default.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.xml similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Default.Windows.xml rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.xml diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Unix.xml deleted file mode 100644 index 415de9ed..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Unix.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - delegate* unmanaged[Cdecl]<MyStruct_*, int> - - - - - TestInterface_* - - - int - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - - - - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Windows.xml deleted file mode 100644 index 415de9ed..00000000 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.Windows.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - delegate* unmanaged[Cdecl]<MyStruct_*, int> - - - - - TestInterface_* - - - int - return functions->TestMethod((MyStruct_*)Unsafe.AsPointer(ref this)); - - - - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.xml similarity index 100% rename from tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Latest.Unix.xml rename to tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ThisAsPointerTest.Xml.Preview.xml