# Path: pre_commit_hooks/util.py
# class CalledProcessError(RuntimeError):
#     pass
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout
# 
# Path: pre_commit_hooks/util.py
# def zsplit(s: str) -> list[str]:
#     s = s.strip('\0')
#     if s:
#         return s.split('\0')
#     else:
#         return []


import pytest
from pre_commit_hooks.util import CalledProcessError
from pre_commit_hooks.util import cmd_output
from pre_commit_hooks.util import zsplit
from __future__ import annotations




def test_raises_on_error():
    with pytest.raises(CalledProcessError):

# Path: pre_commit_hooks/util.py
# class CalledProcessError(RuntimeError):
#     pass
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout
# 
# Path: pre_commit_hooks/util.py
# def zsplit(s: str) -> list[str]:
#     s = s.strip('\0')
#     if s:
#         return s.split('\0')
#     else:
#         return []


# Path: tests/util_test.py
import pytest
from pre_commit_hooks.util import CalledProcessError
from pre_commit_hooks.util import cmd_output
from pre_commit_hooks.util import zsplit

from __future__ import annotations




def test_raises_on_error():
    with pytest.raises(CalledProcessError):

        cmd_output('sh', '-c', 'exit 1')