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
8 changes: 6 additions & 2 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 Down
12 changes: 12 additions & 0 deletions unittests/source_reader_tester.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 unittest
import os

from . import parser_test_case

Expand Down Expand Up @@ -31,6 +32,17 @@ def test_compound_argument_type(self):
self.assertTrue(do_smth, "unable to find do_smth")
do_smth.function_type()

def test_stderr_present_and_readable(self):
with open(os.path.join('unittests', 'data', self.header), 'r') as f:
source_str = f.read()

err_str = "add some stuff that should not compile"
source_str += err_str
with self.assertRaises(RuntimeError) as e_context:
decls = parser.parse_string(source_str, self.config)

self.assertIn(err_str, e_context.exception.args[0])


def create_suite():
suite = unittest.TestSuite()
Expand Down
Loading