Skip to content

Add test coverage for BodyValidator edge cases (empty/leading-blank messages) #490

Description

@shenxianpeng

Description

The BodyValidator (commit_check/engine.py) should be tested for edge cases involving leading blank lines and whitespace-only messages.

Note: _get_commit_message() (line 127) strips the input before it reaches BodyValidator.validate(), so leading blank lines are removed early. The following tests verify the actual behavior.

Goal

Add test cases in tests/engine_test.py under the existing TestBodyValidator class to cover:

  1. Message with leading blank lines and body content (e.g. "\n\nbody content") — should FAIL (message without subject won't pass require_body)
  2. Message with leading blank lines and no body content (e.g. "\n\n") — should PASS (empty after strip, treated as no commit message)
  3. Message with only whitespace lines (e.g. " \n ") — should PASS (same as above)

These tests will bring coverage to 100% for the BodyValidator.validate() method.

How to verify

pytest tests/engine_test.py::TestBodyValidator -v

Coverage can be checked with:

coverage run -m pytest tests/engine_test.py::TestBodyValidator
coverage report -m

References

  • commit_check/engine.pyBodyValidator class (lines 530–564)
  • tests/engine_test.pyTestBodyValidator class (existing tests start at line 915)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions