Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global error message at finish #15

Merged
merged 3 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,7 @@ NOTE: please use them in this order.
- Add tox envs to test with sphinx v5.
- Wide version range for `sphinx` extra to include v5.
- Update `sphinx` `extlinks` config for v5.
- Print error message on non-zero exit code ([#15](https://github.com/rstcheck/rstcheck-core/pull/15))

## 1.0.1.post2 (2022-05-30)

Expand Down
1 change: 1 addition & 0 deletions src/rstcheck_core/runner.py
Expand Up @@ -243,6 +243,7 @@ def print_result(self, output_file: t.Optional[t.TextIO] = None) -> int:

print(message, file=output_file or sys.stderr)

print("Error! Issues detected.", file=output_file or sys.stderr)
return 1

def run(self) -> int: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Expand Up @@ -1230,7 +1230,7 @@ class TestConfigPathLoader:

@staticmethod
def test_raises_on_nonexisting_path() -> None:
"""Test raises OSError on path that is not a file or directory."""
"""Test raises FileNotFoundError on path that is not a file or directory."""
conf_file = pathlib.Path("does-not-exist-cfg")

with pytest.raises(FileNotFoundError, match=re.compile("Passed config path not found.")):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_runner.py
Expand Up @@ -455,6 +455,19 @@ def test_success_message_on_success(capsys: pytest.CaptureFixture[str]) -> None:

assert "Success! No issues detected." in capsys.readouterr().out

@staticmethod
def test_error_message_on_error(
tmp_path: pathlib.Path, capsys: pytest.CaptureFixture[str]
) -> None:
"""Test error message is printed to stderr by default if errors are found."""
test_file = tmp_path / "nonexisting.rst"
init_config = config.RstcheckConfig()
_runner = runner.RstcheckMainRunner([test_file], init_config)

_runner.print_result() # act

assert "Error! Issues detected." in capsys.readouterr().err

@staticmethod
def test_success_message_print_to_file(tmp_path: pathlib.Path) -> None:
"""Test success message is printed to given file."""
Expand Down