Skip to content

bazel: convert man_tcl_check to unittest py_test#9831

Open
oharboe wants to merge 11 commits intoThe-OpenROAD-Project:masterfrom
Pinata-Consulting:man-tcl-check-unittest
Open

bazel: convert man_tcl_check to unittest py_test#9831
oharboe wants to merge 11 commits intoThe-OpenROAD-Project:masterfrom
Pinata-Consulting:man-tcl-check-unittest

Conversation

@oharboe
Copy link
Collaborator

@oharboe oharboe commented Mar 19, 2026

Summary

  • Refactor docs/src/scripts/man_tcl_check.py from a standalone script with os.chdir() into an importable count_commands() function
  • Convert all 24 *_man_tcl_check.py tests to unittest.TestCase with assertEqual assertions
  • Use py_test from @rules_python instead of the shell-based regression_test runner
  • Delete all 24 .ok golden files (assertions replace output diffing)

Depends on #9830.

What changed per module

  • src/<module>/BUILD: add doc_files filegroup exporting README.md + src/*.tcl
  • src/<module>/test/BUILD: add py_test entry, remove from MANUAL_TESTS
  • src/<module>/test/<module>_man_tcl_check.py: thin unittest wrapper calling count_commands()
  • src/<module>/test/<module>_man_tcl_check.ok: deleted

Why

The old golden-file approach tested output stability, not correctness — .ok files with "Command counts do not match." passed the test. The new assertEqual assertions fail immediately with a clear message like AssertionError: 0 != 1 : proc count (0) != readme count (1).

Test plan

  • 9 modules with matching counts PASS
  • 15 modules with mismatched counts FAIL with clear assertion messages
  • Count mismatches to be fixed in a follow-up PR

🤖 Generated with Claude Code

oharboe and others added 3 commits March 19, 2026 13:17
Previously, man_tcl_check tests passed even when help/proc/readme
counts didn't match because .ok golden files encoded the broken
state. Add sys.exit(1) so the Python script exits non-zero on
mismatch, and add set -o pipefail to regression_test.sh so the
exit code propagates through the tee pipe.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Refactor docs/src/scripts/man_tcl_check.py from a standalone script
with os.chdir() into an importable count_commands() function that
takes explicit paths. Add BUILD with py_library so it can be used
as a Bazel dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Replace golden-file doc_check tests with proper unittest assertions.
Each module's *_man_tcl_check.py is now a thin unittest.TestCase that
calls count_commands() and asserts help == proc == readme counts.

- Add doc_files filegroup to each module BUILD for data deps
- Add py_test entries to each test BUILD
- Remove from MANUAL_TESTS (no longer uses regression_test runner)
- Delete .ok golden files (assertions replace output diffing)

9 modules pass (counts match), 15 fail with clear assertEqual
messages showing the exact count mismatch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe oharboe requested a review from luarss March 19, 2026 12:30
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the man_tcl_check.py script into a modular count_commands function and converts the associated tests to unittest.TestCase using py_test rules. This significantly improves the test infrastructure by replacing golden file comparisons with explicit assertions, leading to clearer failure messages and better maintainability. The changes are well-structured and align with best practices for Python testing and modular design. A potential runtime error was introduced in the refactored script regarding the handling of missing README.md files, which has been highlighted for correction.

oharboe and others added 2 commits March 19, 2026 13:43
Guard against FileNotFoundError when a module has no README.md
by checking os.path.exists() before opening.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Rename py_test targets from e.g. ant_man_tcl_check to
ant_man_tcl_check_test to follow Bazel naming conventions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe
Copy link
Collaborator Author

oharboe commented Mar 19, 2026

/gemini review

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@oharboe oharboe requested a review from maliberty March 19, 2026 12:47
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the man_tcl_check.py script into a reusable count_commands function and integrates it into the Bazel build system. This involves creating filegroup targets in each module's BUILD file to expose documentation and TCL files, and then creating dedicated py_test targets for each module. These new tests use the refactored count_commands function to verify that the number of help, proc, and readme commands match within each module, replacing the previous ad-hoc script execution. Additionally, set -o pipefail is added to regression_test.sh for improved error handling. Review comments suggest improving the man_tcl_check.py script by replacing magic strings like "ICeWall", "PdnGen", and "pad", and the magic number 1 with named constants for better readability and maintainability.

oharboe and others added 2 commits March 19, 2026 13:51
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

oharboe and others added 2 commits March 19, 2026 14:10
…_tcl_check

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Many modules have pre-existing mismatches between help, proc, and
readme command counts. Assert against the actual expected counts
per module so tests pass while still catching regressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

test_dir = os.path.dirname(os.path.abspath(__file__))
module_dir = os.path.dirname(test_dir)
h, p, r = count_commands(module_dir)
self.assertEqual(h, 0, f"help count ({h}) != expected (0)")
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably make this a constant on top of each file for easy maintenance e.g.

HELP_COUNT=0
PROC_COUNT=0
README_COUNT=1

...
self.assertEqual(p, PROC_COUNT, f"proc count ({p}) != expected ({PROC_COUNT})")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

test_dir = os.path.dirname(os.path.abspath(__file__))
module_dir = os.path.dirname(test_dir)
h, p, r = count_commands(module_dir)
self.assertEqual(h, p, f"help count ({h}) != proc count ({p})")
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally, all should be assertEqual

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

… tests

Address review feedback: extract expected counts into HELP_COUNT/PROC_COUNT/
README_COUNT constants at module level, use assertEqual with explicit expected
values for all 24 modules (replacing relative h==p comparisons), and format
with black.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe oharboe force-pushed the man-tcl-check-unittest branch from f212906 to 0379bc5 Compare March 19, 2026 14:15
@oharboe oharboe requested a review from luarss March 19, 2026 14:16
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

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.

2 participants