Skip to content

patrol_log assumes the default _test.dart suffix when parsing test names #3171

Description

@pdenert

Context

patrol_cli allows configuring a custom test file suffix via patrol.test_file_suffix in pubspec.yaml (default: _test.dart). However, the log-parsing layer in patrol_log has no access to that setting and relies on name heuristics that assume the default suffix:

  1. Display (TestEntry) — since fix(patrol, patrol_log): report correct test description when test fails #3167, a finished test entry strips the leading file-group prefix (to render description (dir/file.dart)) only when the first token of the name ends with _test. With a custom suffix (e.g. _spec.dart, producing group names like example_spec or flows.example_spec), the prefix is not recognized, so the line is printed with the prefix inline (✅ flows.example_spec grants permission) and without the file-path decoration. Cosmetic only — nothing is lost.
  2. Start/finish matching (PatrolLogReader._normalizeTestName) — pre-existing: the reader strips the prefix from finish entries only when the first token contains a .. For a top-level test file with a custom suffix (group name example_spec, no dot), the finish entry is not normalized and may fail to match its start entry, affecting execution-time reporting.

Note the heuristics cannot be made smarter from the name alone — flows.example_spec (a file prefix) is indistinguishable from MyClass.myMethod (the first word of a description). A compile-time define also doesn't work here, because pretty()/_normalizeTestName run in the CLI process, which is compiled at activation time without project dart-defines.

Proposal

Thread the configured suffix from PubspecReader (patrol_cli) into PatrolLogReader at runtime (it is constructed by the test backends, which have access to the pubspec config), and use it — sanitized the same way TestBundler._createTestName sanitizes file names (drop .dart, replace non-identifier chars with _) — for both prefix detection in TestEntry display and _normalizeTestName matching, defaulting to _test when not provided.

Affected code

  • packages/patrol_log/lib/src/entries/test_entry.dart (_hasFilePathPrefix, nameWithPath)
  • packages/patrol_log/lib/src/patrol_log_reader.dart (_normalizeTestName)
  • packages/patrol_cli/lib/src/android/android_test_backend.dart and other backends constructing PatrolLogReader

Severity

Low — only affects projects that override test_file_suffix, and for display it is purely cosmetic. Related: #3048, #3167.

Metadata

Metadata

Assignees

Labels

P2Issues not at the top of the work listpackage: patrol_cliRelated to the patrol_cli packagepackage: patrol_logRelated to logging

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions