Skip to content
Snippets Groups Projects
Commit e6b3004d authored by Simon McVittie's avatar Simon McVittie
Browse files

tests: Test -adverb command

parent c7be64f7
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# Copyright 2020 Collabora Ltd.
#
# SPDX-License-Identifier: MIT
import logging
import os
import signal
import subprocess
import sys
import tempfile
try:
import typing
typing # placate pyflakes
except ImportError:
pass
from testutils import (
BaseTest,
test_main,
)
logger = logging.getLogger('test-adverb')
class TestAdverb(BaseTest):
def setUp(self) -> None:
super().setUp()
if 'PRESSURE_VESSEL_UNINSTALLED' in os.environ:
self.adverb = self.command_prefix + [
os.path.join(
self.top_builddir,
'src',
'pressure-vessel-adverb'
),
]
else:
self.skipTest('Not available as an installed-test')
def test_stdio_passthrough(self) -> None:
proc = subprocess.Popen(
self.adverb + [
'--',
'sh', '-euc',
'''
if [ "$(cat)" != "hello, world!" ]; then
exit 1
fi
echo $$
exec >/dev/null
exec sleep infinity
''',
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=2,
universal_newlines=True,
)
pid = 0
try:
stdin = proc.stdin
assert stdin is not None
stdin.write('hello, world!')
stdin.close()
stdout = proc.stdout
assert stdout is not None
pid = int(stdout.read().strip())
finally:
if pid:
os.kill(pid, signal.SIGTERM)
else:
proc.terminate()
self.assertIn(
proc.wait(),
(128 + signal.SIGTERM, -signal.SIGTERM),
)
def tearDown(self) -> None:
super().tearDown()
if __name__ == '__main__':
assert sys.version_info >= (3, 4), \
'Python 3.4+ is required'
test_main()
# vi: set sw=4 sts=4 et:
......@@ -31,6 +31,7 @@ test_env.set(
test_env.set('PRESSURE_VESSEL_UNINSTALLED', 'yes')
tests = [
'adverb.py',
'cheap-copy.py',
'containers.py',
'invocation.py',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment