factor out process call and fix returncode in suppress test
@@ -21,6 +21,24 @@ from libtest import codechecker
from libtest.thrift_client_to_db import get_all_run_results
+def call_cmd(command, cwd, env):
+ try:
+ print(' '.join(command))
+ proc = subprocess.Popen(
+ shlex.split(' '.join(command)),
+ cwd=cwd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ env=env)
+ out, err = proc.communicate()
+ print(out)
+ print(err)
+ return proc.returncode
+ except CalledProcessError as cerr:
+ print("Failed to call:\n" + ' '.join(cerr.cmd))
+ return cerr.returncode
+
+
class TestSuppress(unittest.TestCase):
"""
Test source-code level suppression data writing to suppress file.
@@ -54,23 +72,6 @@ class TestSuppress(unittest.TestCase):
Test exporting a source suppress comment automatically to file.
"""
- def __call(command):
- try:
- print(' '.join(command))
- proc = subprocess.Popen(
- shlex.split(' '.join(command)),
- cwd=self._test_project_path,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env=env.test_env(self._test_workspace))
- out, err = proc.communicate()
- print(out)
- print(err)
- return 0
- except CalledProcessError as cerr:
- print("Failed to call:\n" + ' '.join(cerr.cmd))
- return cerr.returncode
-
generated_file = os.path.join(self._test_workspace,
"generated.suppress")
@@ -80,7 +81,9 @@ class TestSuppress(unittest.TestCase):
"--export-source-suppress"
]
- ret = __call(extract_cmd)
+ ret = call_cmd(extract_cmd,
+ self._test_project_path,
+ env.test_env(self._test_workspace))
self.assertEqual(ret, 0, "Failed to generate suppress file.")
with open(generated_file, 'r') as generated:
