Skip to content

Add SuppressSourceLocation to BaseTestAttribute for library-declared tests - #6578

Draft
thomhurst with Copilot wants to merge 2 commits into
mainfrom
copilot/feature-library-declared-tests-expose-location
Draft

Add SuppressSourceLocation to BaseTestAttribute for library-declared tests#6578
thomhurst with Copilot wants to merge 2 commits into
mainfrom
copilot/feature-library-declared-tests-expose-location

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Library-shipped test classes (used via [InheritsTests]) embed the library author's local file paths into test metadata via [CallerFilePath]. These paths are meaningless to consumers and pollute the binary.

Changes

  • BaseTestAttribute: Added bool SuppressSourceLocation property (default false)
  • Source generator (TestMetadataGenerator): Both GetTestMethodSourceLocation overloads return empty location when the property is set via named argument
  • Reflection engine (ReflectionTestDataCollector): ExtractFilePath/ExtractLineNumber return empty/0 when suppressed
  • Public API snapshots: Updated all Core verified files

Usage

public abstract class MyLibraryTests
{
    [Test(SuppressSourceLocation = true)]
    public void LibraryDefinedTest() { }
}

Consumers inheriting this test will see no source location rather than a path to a file on the library author's machine.

When set to true, source file path and line number are cleared to empty/0,
preventing library-declared tests from exposing the library author's file paths.
Updated source generator and reflection engine to respect the new property.

Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix library-declared tests file location exposure Add SuppressSourceLocation to BaseTestAttribute for library-declared tests Aug 10, 2026
Copilot AI requested a review from thomhurst August 10, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Library-declared tests should not have their caller file location exposed

2 participants