Skip to content

Commit

Permalink
fix: report not executable bash program error
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele-Tentoni committed Mar 2, 2022
1 parent 5420909 commit d3e7350
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cc_codechecker/runners/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# Codechecker
from cc_codechecker.runner import Runner

NOT_EXECUTABLE_ERROR = 126


class Bash(Runner):
"""Bash runner.
Expand Down Expand Up @@ -76,7 +78,8 @@ def run(self, *args, **kwargs) -> tuple[int, str]:
"""
bash_path = self._check_position()

cmd: list[str] = ['./bash/program.sh']
program_file_name = './bash/program.sh'
cmd: list[str] = []
bash_run = subprocess.run(
cmd,
capture_output=True,
Expand All @@ -92,6 +95,9 @@ def run(self, *args, **kwargs) -> tuple[int, str]:
if run_verbose:
print(f'Bash run {bash_run}')

if bash_run.returncode is NOT_EXECUTABLE_ERROR and not bash_run.stdout:
bash_run.stdout = f'{program_file_name} is not executable'

return (bash_run.returncode, bash_run.stdout)

def _check_position(self) -> str:
Expand Down
16 changes: 15 additions & 1 deletion tests/runners/bash_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Codechecker
from cc_codechecker.context import Context
from cc_codechecker.runners.bash import Bash
from cc_codechecker.runners.bash import NOT_EXECUTABLE_ERROR, Bash


@pytest.fixture(name='bash_runner')
Expand Down Expand Up @@ -54,3 +54,17 @@ def test_run(run: MagicMock, check: MagicMock, bash_runner: Bash):
ver = bash_runner.run()
assert ver[0] == 0
assert ver[1] == ''

@patch('cc_codechecker.runners.bash.Bash._check_position')
@patch('cc_codechecker.runners.bash.subprocess.run')
def test_not_executable_program(
run: MagicMock,
check: MagicMock,
bash_runner: Bash,
):
"""Test the return value of run method."""
run.return_value = MagicMock(stdout='', returncode=NOT_EXECUTABLE_ERROR)
check.return_value = '/usr/bin/bash'
ver = bash_runner.run()
assert ver[0] == 126
assert ver[1] == './bash/program.sh is not executable'

0 comments on commit d3e7350

Please sign in to comment.