Skip to content

CLI: deduplicate overlapping file globs in test-examples #4

Description

@jcouball

Summary

Deduplicate file paths returned by parse_files so overlapping globs/directories do not execute the same example file multiple times.

Motivation

parse_files currently flattens matched paths without uniqueness filtering. Passing overlapping patterns (for example app plus app/**/*.rb) yields duplicate entries, which causes duplicate YARD parsing and duplicate generated tests.

Concrete example

parse_files(['app', 'app/**/*.rb'])
# => ["app/a.rb", "app/a.rb"]

This can inflate run counts and make failures appear multiple times even though source files are unique.

Current behaviour

files = globs.map do |glob|
  glob = "#{glob}/**/*.rb" if File.directory?(glob)
  Dir[glob]
end

files.flatten

Proposed solution

Return a de-duplicated list while preserving stable order (first appearance wins), e.g.:

files.flatten.uniq

Optionally normalize with File.expand_path before dedupe if mixed relative/absolute globs are expected.

Scope

In scope

  • Deduplicate output from parse_files
  • Keep current glob expansion semantics and defaults (app, lib)
  • Add tests for overlapping input patterns

Out of scope

  • Changing how defaults are selected
  • Recursive file type expansion beyond *.rb

Implementation notes

  1. Keep output deterministic for CI and snapshot-friendly tests.
  2. Preserve behavior for non-overlapping glob input.
  3. Ensure no regression in feature scenarios that pass explicit file globs.

Acceptance criteria

  • parse_files(['app', 'app/**/*.rb']) returns each matched file once
  • Run counts do not increase due to duplicate file paths
  • Existing cucumber scenarios continue to pass

Related

  • lib/yard/cli/test_examples.rbparse_files
  • lib/yard/cli/test_examples.rbrun

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions