Fix find_tests line-number search for test names at the start of a line - #851
Merged
mvandervoord merged 1 commit intoSep 10, 2026
Merged
Conversation
The line-number search in UnityTestRunnerGenerator#find_tests requires
whitespace before the test name. A definition written as
void
test_something(void)
puts the name at column 0, so the regex never matches the definition
line. The search then scans to the end of the file for every test,
O(tests x lines), and reports line number 0 for all of them.
Accept start-of-line as well as whitespace before the name, and compile
the regex once per test instead of once per line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mandatory 🍍
UnityTestRunnerGenerator#find_testsinauto/generate_test_runner.rblocates each test's line number with a forward cursor and the regex/\s+#{name}(?:\s|\()/. The leading\s+(added in f278c18 for #288) requires whitespace before the name on the same line, so a definition written asnever matches its own line. Two things follow:
line_number0 in the generated runner;On a 10,000-line file with 367 tests this costs about 14 s of Ruby time per file on an Apple M-series laptop (Ruby 2.6 and 4.0), and 20 s or more on typical CI runners. Projects that write the return type on its own line hit this on every runner generation, including through Ceedling, which vendors this file.
Change
/(?:^|\s)#{name}(?:\s|\()/.(?:\s|\()is unchanged, so the partial-name case from Invalid line number in runner generator in very specific case #288 (test_my_functionvstest_my_function_invalid_behavior) still resolves to the right line.Tests
Two cases added to
test/tests/test_generate_test_runner.rb:FindTestsLineNumbersWhenNameStartsTheLine: names at column 0 get their real line numbers. Fails before this change (both reported as 0), passes after.FindTestsLineNumbersWhenOneNameIsAPrefixOfAnother: the Invalid line number in runner generator in very specific case #288 case, passes before and after.cd test && rake test:scripts: 69/69 before, 71/71 after.rubocop ../auto/generate_test_runner.rb --config .rubocop.yml(1.57.2, as in CI): no offenses.Measurement
Synthetic file, 367 tests of 25 lines each in the
void/test_x(void)style, 11,015 lines, onefind_testscall:Reproduction (from the repository root, before and after this change):
Notes
The regex has had this form in every tag from v2.4.2 to v2.7.0 and on current master. I found no existing issue or PR about it.
I used Claude Code in making this PR.