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

Add standard error to exception message #140

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/pygccxml/parser/source_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def create_xml_file(self, source_file, destination=None):
process = subprocess.Popen(
args=command_line,
shell=True,
stdout=subprocess.PIPE)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

try:
results = []
Expand All @@ -246,9 +247,12 @@ def create_xml_file(self, source_file, destination=None):
for line in process.stdout.readlines():
if line.strip():
results.append(line.rstrip())
for line in process.stderr.readlines():
if line.strip():
results.append(line.rstrip())

exit_status = process.returncode
msg = os.linesep.join([str(s) for s in results])
msg = os.linesep.join([str(s.decode()) for s in results])
if self.__config.ignore_gccxml_output:
if not os.path.isfile(xml_file):
raise RuntimeError(
Expand All @@ -257,18 +261,17 @@ def create_xml_file(self, source_file, destination=None):
": %s status:%s" %
(msg, exit_status))
else:
if msg or exit_status or not \
os.path.isfile(xml_file):
if not os.path.isfile(xml_file):
raise RuntimeError(
"Error occurred while running " +
self.__config.xml_generator.upper() +
" xml file does not exist")
else:
raise RuntimeError(
"Error occurred while running " +
self.__config.xml_generator.upper() +
": %s status:%s" % (msg, exit_status))
if msg or exit_status:
raise RuntimeError(
"Error occurred while running " +
self.__config.xml_generator.upper() +
": %s status:%s" % (msg, exit_status))
if not os.path.isfile(xml_file):
raise RuntimeError(
"Error occurred while running " +
self.__config.xml_generator.upper() +
" xml file does not exist")

except Exception:
utils.remove_file_no_raise(xml_file, self.__config)
raise
Expand Down
13 changes: 13 additions & 0 deletions tests/test_source_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# See http://www.boost.org/LICENSE_1_0.txt

import platform
import os

import pytest

Expand Down Expand Up @@ -35,3 +36,15 @@ def test_compound_argument_type(global_ns):
do_smth = global_ns.calldefs('do_smth')
assert do_smth is not None
do_smth.function_type()


def test_stderr_present_and_readable():
with open(os.path.join('tests', 'data', TEST_FILES[0]), 'r') as f:
source_str = f.read()

err_str = "add some stuff that should not compile"
source_str += err_str
config = autoconfig.cxx_parsers_cfg.config.clone()
with pytest.raises(RuntimeError) as e_context:
parser.parse_string(source_str, config)
assert err_str in str(e_context)
Loading