Skip to content

Stray extension-less snapshot file crashes every run of its test #1850

Description

@SimonCropp

MatchingFileFinder.SubStringEquals sliced a fixed number of characters off each enumerated file name without checking the name was long enough:

var slice = value.Slice(start, match.Length);

The Win32 search pattern used to enumerate candidates is {prefix}*.received.* / {prefix}*.verified.*, and a trailing .* also matches a name with no extension. So a stray file named exactly {prefix}.received or {prefix}.verified is returned by the enumeration, but is one character shorter than the {prefix}.received. pattern it is compared against, and the slice throws.

Symptom

With a file such as MyTests.MyTest.verified (extension dropped by an editor, a git operation, or a manual rename) sitting beside the snapshots, every subsequent run of MyTests.MyTest throws:

System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.

from MatchingFileFinder.FindVerified / DeleteReceived, during InnerVerifier construction — before the test body executes. The failure gives no hint that an unrelated stray file is the cause.

Fix

Length-check before slicing, so a name shorter than the pattern is simply not a match.

Fixed in a43e52e, covered by MatchingFileFinderTests.StrayFileWithNoExtensionIsIgnored.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions