Repository navigation
Fix CommandGuesser mislabelling suites from incidental path substrings - #1251
Conversation
78c1131 to
61055d0
Compare
|
Verified on the machine that reproduces it, at 61055d0. The 3 examples in Issue repro, plus your ARGV half and the cases the anchoring could have broken: You were right not to take the One real gap. The anchors are forward-slash-only, so Windows backslash arguments lose matches
SEGMENT_START = %r{(?<![^\s/\\])}
SEGMENT_END = %r{(?=[\s/\\]|\z)}With that, the Windows case reads Second, minor — the only other place this reads worse than SimpleCov::CommandGuesser.original_run_command = "/opt/My Ruby/bin/rspec features"
# main => RSpec #1251 => Cucumber FeaturesThe first-token fallback yields Unrelated:
|
|
@copilot resolve the merge conflicts in this pull request |
Resolved by merging |
b88215e to
07c6f36
Compare
The framework patterns were bare substrings matched against
"#{$PROGRAM_NAME} #{ARGV.join(' ')}", so a "test/" anywhere in that
string decided the suite name. A Ruby installed under a "latest/bin"
directory (the layout mise creates) put "test/" in the path of every
binary run through it, and because "test/" is checked before "spec/",
RSpec and Cucumber suites alike came out as "Unit Tests". Arguments were
affected too, so "rspec spec/greatest/foo_spec.rb" was mislabelled the
same way. Under merging the command name is the resultset key, so a
mislabelled suite was filed under the wrong key rather than failing
loudly.
The patterns now match only at a path segment boundary, where a boundary
is the start of the string, whitespace, a forward slash, or a backslash.
Counting only forward slashes would drop matches the bare substrings used
to make on a Windows argument like "spec\foo_spec.rb", and no CI job
catches that: windows-latest invokes with forward slashes, and a
recognized executable short-circuits before the patterns run.
Segment matching alone would have regressed "rspec features", an RSpec
suite whose examples live in features/, which passed before only because
the unanchored "spec" pattern matched the letters inside "rspec". So the
invoked executable is now consulted first. Generic runners are
deliberately absent from that table, letting "ruby test/integration/
foo_test.rb" and rake's test loader still reach the path patterns that
draw the unit, functional, and integration distinction.
The executable is read from $PROGRAM_NAME, recorded separately as
CommandGuesser.original_program_name. Recovering it from the flattened
command by taking the first token would truncate a program path that
contains a space, so "/opt/My Ruby/bin/rspec features" would lose the
executable and be claimed by the features pattern. Assigning the
flattened command clears the recorded name so the two cannot describe
different runs, and callers that set only the command still get the
first-token derivation.
Reported with an exemplary diagnosis by @andriytyurnikov, who also
verified the fix on an affected machine and found the Windows gap.
Resolves #1249.
07c6f36 to
344664e
Compare
CommandGuessermatches its framework patterns against"#{$PROGRAM_NAME} #{ARGV.join(' ')}", and those patterns were bare substrings, so atest/anywhere in that string decided the suite name. A Ruby installed under alatest/bindirectory (the layout mise creates alongside the versioned one) putstest/into the path of every binary run through it, and becausetest/is checked ahead ofspec/, RSpec and Cucumber suites alike came out asUnit Tests.Under merging the command name is the resultset key, so this is wrong data rather than a cosmetic label. A mislabelled suite is filed under the wrong key, letting two genuinely different suites merge into each other rather than failing loudly.
The false positive also fires from
ARGV, so paths inside the project are affected too.rspec spec/greatest/foo_spec.rbandcucumber features/contest/foo.featureboth returnedUnit Tests. Sanitising only$PROGRAM_NAME, as the issue proposes, would leave this half standing.rspec featuresworks today only by accident. It returnsRSpecbecause the unanchoredspecpattern matches the letters inside the wordrspecand is checked ahead offeatures. Tightening the patterns without compensating would flip that case toCucumber Features.The patterns now require the keyword to begin a path segment or an argument, so
latest/,contest/, andgreatest/no longer read astest/. This applies to$PROGRAM_NAMEandARGValike, which covers both halves of the bug.An
rspecorcucumberbinary names the framework regardless of what surrounds it on the command line, which keepsrspec featuresreporting asRSpec. An RSpec suite whose examples live infeatures/is still an RSpec suite, and after anchoring the executable name is the only thing that says so. Generic runners are deliberately absent from that table, soruby test/integration/foo_test.rband rake's test loader still fall through to the path patterns that draw the unit, functional, and integration distinction.That executable comes from
$PROGRAM_NAME, whichdefaults.rbnow records separately asCommandGuesser.original_program_name, because recovering it from the flattened command by taking the first token would truncate a program path containing a space and hand/opt/My Ruby/bin/rspec featuresto thefeaturespattern. Assigning the command clears the recorded name so the two cannot describe different runs, and callers that set only the command still get the first-token derivation.Reported by @andriytyurnikov in #1249.