diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-07 22:13:00 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-07 22:49:27 +0200 |
commit | 9ba12e5496c49f48f40ad52e816641dfdbb0474e (patch) | |
tree | 47c04ea350c077219eb5dca461e182551e26d954 /test/py/test_basic.py | |
parent | support code coverage report generation (diff) | |
download | cimple-9ba12e5496c49f48f40ad52e816641dfdbb0474e.tar.gz cimple-9ba12e5496c49f48f40ad52e816641dfdbb0474e.zip |
test: add some basic command-line usage tests
Diffstat (limited to 'test/py/test_basic.py')
-rw-r--r-- | test/py/test_basic.py | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/test/py/test_basic.py b/test/py/test_basic.py index ab062e5..9737552 100644 --- a/test/py/test_basic.py +++ b/test/py/test_basic.py @@ -6,12 +6,64 @@ import re -def test_server_and_workers_run(server_and_workers): +def _test_cmd_line_version_internal(cmd_line, name, version): + for flag in ('--version', '-V'): + output = cmd_line.run(flag).removesuffix('\n') + match = re.match(r'^cimple-(\w+) v(\d+\.\d+\.\d+) \([0-9a-f]{40,}\)$', output) + assert match, f'Invalid {flag} output:\n{output}' + assert match.group(1) == name + assert match.group(2) == version + + +def test_cmd_line_version(server_exe, worker_exe, client_exe, version): + _test_cmd_line_version_internal(server_exe, 'server', version) + _test_cmd_line_version_internal(worker_exe, 'worker', version) + _test_cmd_line_version_internal(client_exe, 'client', version) + + +def _test_cmd_line_help_internal(cmd_line, name): + for flag in ('--help', '-h'): + output = cmd_line.run(flag).removesuffix('\n') + match = re.match(r'^usage: cimple-(\w+) ', output) + assert match, f'Invalid {flag} output:\n{output}' + assert match.group(1) == name + + +def test_cmd_line_help(server_exe, worker_exe, client_exe): + _test_cmd_line_help_internal(server_exe, 'server') + _test_cmd_line_help_internal(worker_exe, 'worker') + _test_cmd_line_help_internal(client_exe, 'client') + + +def _test_cmd_line_invalid_option_internal(cmd_line, name): + for args in (['-x'], ['--invalid', 'value']): + ec, output = cmd_line.try_run(*args) + assert ec != 0, f'Invalid exit code {ec}, output:\n{output}' + + +def test_cmd_line_invalid_option(server_exe, worker_exe, client_exe): + _test_cmd_line_invalid_option_internal(server_exe, 'server') + _test_cmd_line_invalid_option_internal(worker_exe, 'worker') + _test_cmd_line_invalid_option_internal(client_exe, 'client') + + +def test_run_client_no_msg(client): + ec, output = client.try_run() + assert ec != 0, f'Invalid exit code {ec}, output:\n{output}' + prefix = 'usage error: no message to send to the server\n' + assert output.startswith(prefix), f'Invalid output:\n{output}' + + +def test_run_client_invalid_msg(server, client): + ec, output = client.try_run('hello') + assert ec != 0, f'Invalid exit code {ec}, output:\n{output}' + suffix = "Failed to connect to server or it couldn't process the request\n" + assert output.endswith(suffix), f'Invalid output:\n{output}' + + +def test_run_noop_server(server): pass -def test_client_version(client, version): - output = client.run('--version').removesuffix('\n') - match = re.match(r'^cimple-client v(\d+\.\d+\.\d+) \([0-9a-f]{40,}\)$', output) - assert match, f'Invalid --version output: {output}' - assert match.group(1) == version +def test_run_noop_server_and_workers(server_and_workers): + pass |