Skip to content

fix(runner): detect duplicate test functions whose brace is on the next line - #1427

Merged
Chemaclass merged 1 commit into
TypedDevs:mainfrom
bfs2021:fix/1421-duplicate-check-brace-next-line
Oct 29, 2026
Merged

Chemaclass merged 1 commit into
TypedDevs:mainfrom
bfs2021:fix/1421-duplicate-check-brace-next-line

Conversation

@bfs2021

@bfs2021 bfs2021 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #1421

A test file that puts the opening brace on the next line:

function test_dup()
{
  :
}

was not checked for duplicate test functions. Bash keeps only the last definition of a repeated name, so the first test silently never ran.

Root cause

The awk definition matcher in src/helper/discovery.sh required the opening brace on the same line:

/...\(\)[[:space:]]*\{/

A definition whose { sits on the next line never matched, so the duplicate was never recorded.

Fix

After the name() token the pattern now accepts either an opening brace or end of line:

/...\(\)[[:space:]]*(\{|$)/

Same-line definitions keep matching, and the existing field match and name extraction already work on the name() token alone. The duplicate report text is unchanged.

Testing

  • New unit test test_check_duplicate_functions_with_the_brace_on_the_next_line in tests/unit/helper/helper_test.sh, next to the existing duplicate-function checks. It fails on main (the check returned 0) and passes with the fix, also asserting the stored detail test_twice (lines 1, 5).
  • ./bashunit tests/unit/helper/helper_test.sh — 88 passed, 140 assertions
  • ./bashunit tests/unit/runner/discovery_test.sh — 3 passed, 3 assertions
  • ./bashunit tests/acceptance/bashunit_duplicate_parallel_test.sh — 4 passed, 8 assertions (parallel and sequential reports, line numbers, no-duplicate file)

Manual fixtures covering both styles in both modes:

[--no-parallel same_line] exit=1  Duplicate functions: test_dup (lines 1, 2)
[--no-parallel next_line] exit=1  Duplicate functions: test_dup (lines 1, 5)
[--parallel same_line]    exit=1  Duplicate functions: test_dup (lines 1, 2)
[--parallel next_line]    exit=1  Duplicate functions: test_dup (lines 1, 5)

…xt line

The awk definition pattern required the opening brace on the same line, so a definition written as `function test_x()` with `{` on the next line was never counted. Accept either a brace or end of line after the parentheses; the existing field match and name extraction work on the name() token alone.

Closes TypedDevs#1421

@Chemaclass Chemaclass left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!!

@Chemaclass
Chemaclass merged commit 03deae9 into TypedDevs:main Oct 29, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate test functions are not detected when the opening brace is on the next line

2 participants