Skip to content

Complete MSTEST0077 test coverage: remaining File.* allowlist entries #10316

Description

@Evangelink

Follow-up to #10305, which completed the Directory.* arm of SharedFileSystemPathInTestAnalyzer's mutating allowlist (CreateDirectory, CreateSymbolicLink, Delete, Move, and all six Set*Time* members) plus the [DoNotParallelize] opt-out branch. That issue deliberately scoped item 2 to Directory.*, so the File.* arm is still only partially pinned.

What is covered today

SharedFileSystemPathInTestAnalyzerTests covers these File.* members: WriteAllText, Copy (both path roles), Move, Replace (backup role), Delete, OpenWrite — plus the negative pins for File.ReadAllText/File.Exists/File.Open.

What is not covered

IsMutatingFileSystemMethod's file arm lists many more entries that have no test:

  • The exact mirrors of what Complete MSTEST0077 test coverage: [DoNotParallelize] opt-out and remaining Directory.* allowlist entries #10305 just added on the Directory.* side, and therefore the cheapest to add:

    • File.CreateSymbolicLink — same (path, pathToTarget) shape as Directory.CreateSymbolicLink; the "pathToTarget is only read, so a constant target must not be flagged" behavior is unpinned on the File side.
    • File.SetCreationTime(Utc), File.SetLastAccessTime(Utc), File.SetLastWriteTime(Utc) — the identical six-member family. The Directory equivalent is a [DataRow]-driven test that can be mirrored almost verbatim.
  • The write/append/create family, which has a few distinct signature shapes so it does not templatize as cleanly: WriteAllTextAsync, WriteAllBytes(Async), WriteAllLines(Async), AppendAllText(Async), AppendAllLines(Async), AppendText, Create, CreateText.

  • The attribute/encryption members: Encrypt, Decrypt, SetAttributes, SetUnixFileMode.

Notes for whoever picks this up

  • [ResourceLock] is not an opt-out for MSTEST0077 — the analyzer never calls HasResourceLockFor/HasAnyResourceLock, unlike CurrentDirectoryMutation…/CultureMutation…. Do not copy a WhenResourceLockDeclared_NoDiagnostic test over from those files.
  • The [DoNotParallelize] opt-out is already covered by Complete MSTEST0077 test coverage: [DoNotParallelize] opt-out and remaining Directory.* allowlist entries #10305 (class-level, method-level, and the fixture-method negative that pins the IsTestMethod restriction); there is no need to repeat it per API.
  • File.Open is intentionally excluded from the allowlist and already has a negative test — do not "fix" that.
  • The analyzer test harness resolves against ReferenceAssemblies.Net.Net80 on both the net472 and net8.0 legs, so .NET 6+ APIs such as File.CreateSymbolicLink and File.SetUnixFileMode compile fine in the snippets without any #if guard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/test-gapMissing or insufficient tests.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions