Skip to content

Add acceptance tests to track nullable enabled directives#7869

Open
mchamberlin77 wants to merge 4 commits into
masterfrom
nullable-completed-directories-approval
Open

Add acceptance tests to track nullable enabled directives#7869
mchamberlin77 wants to merge 4 commits into
masterfrom
nullable-completed-directories-approval

Conversation

@mchamberlin77

@mchamberlin77 mchamberlin77 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Add two tests to help ensure progress towards adding nullable annotation context checks across the code base.

  • EnsureFilesInCompletedDirectoriesAreAnnotated() checks the NullableEnable.CompletedFolders.approved.txt file and ensures that for each directory listed all files in that directory contain the #nullable enable directive.
    • This prevents accidental removal of the directive or addition of a new file to the folder without the directive.
    • When all of the files in a directory have the directive that directory should be added to this file.

NullabilityWarnings.cs builds NServiceBus.Core with the nullable enable flag across the entire project and captures the nullability warnings generated from this. That is compared with the known set of warnings in the approval file. If the received file differs from the approved file a test failure occurs.

  • This ensure we are not adding code that results in more nullability warnings if that directive were applied across the project.

BuildIncompleteDirectoriesReport() generates a NullableEnable.IncompleteFolders.txt listing all directories with at least one file that does not have the directive. This test must be explicitly run and is used to get a report of what directories still need to be addressed.

@danielmarbach

Copy link
Copy Markdown
Contributor

I wonder whether we could follow the same approach as "TrimmabilityWarnings.cs", but build with nullable analysis enabled and approve the resulting nullable warnings.

That would give us a stronger quality gate than tracking directories containing "#nullable enable". It would directly enforce that no new nullable warnings are introduced, while allowing the approved warning list to shrink as existing warnings are addressed. Once the approved list reaches zero, nullable warnings could be enabled directly for the project.

To me, that seems like a higher-quality approval because it verifies the outcome we ultimately care about rather than the presence of the directive.

@bording

bording commented Jul 18, 2026

Copy link
Copy Markdown
Member

To me, that seems like a higher-quality approval because it verifies the outcome we ultimately care about rather than the presence of the directive.

The presence of the directive is something we should also care about though, since it's a good signifier that file has been looked at and evaluated.

@mchamberlin77

Copy link
Copy Markdown
Contributor Author

I wonder whether we could follow the same approach as "TrimmabilityWarnings.cs", but build with nullable analysis enabled and approve the resulting nullable warnings.

@danielmarbach Good idea, I agree. I added a NullabilityWarnings.cs in the same style as the TrimmabilityWarnings.cs.

@mchamberlin77
mchamberlin77 marked this pull request as ready for review July 22, 2026 22:03
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.

3 participants