1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00

Print errors to stderr

This makes it possible to run e.g. "yadm -Y foo introspect repo
2>/dev/null" and get an empty output instead of getting the error
message about foo not being fully qualified.
This commit is contained in:
Erik Flodin 2021-01-05 21:57:32 +01:00
parent cd50c128ba
commit 6378fe3073
No known key found for this signature in database
GPG key ID: 420A7C865EE3F85F
13 changed files with 40 additions and 34 deletions

View file

@ -27,5 +27,9 @@ def test_bootstrap(
paths.bootstrap.chmod(0o775) paths.bootstrap.chmod(0o775)
run = runner(command=yadm_cmd('bootstrap')) run = runner(command=yadm_cmd('bootstrap'))
assert run.code == code assert run.code == code
assert run.err == '' if exists and executable:
assert expect in run.out assert run.err == ''
assert expect in run.out
else:
assert expect in run.err
assert run.out == ''

View file

@ -7,5 +7,5 @@ def test_clean_command(runner, yadm_cmd):
# do nothing, this is a dangerous Git command when managing dot files # do nothing, this is a dangerous Git command when managing dot files
# report the command as disabled and exit as a failure # report the command as disabled and exit as a failure
assert run.failure assert run.failure
assert run.err == '' assert run.out == ''
assert 'disabled' in run.out assert 'disabled' in run.err

View file

@ -58,14 +58,14 @@ def test_clone(
if not good_remote: if not good_remote:
# clone should fail # clone should fail
assert run.failure assert run.failure
assert run.err != '' assert run.out != ''
assert 'Unable to fetch origin' in run.out assert 'Unable to fetch origin' in run.err
assert not paths.repo.exists() assert not paths.repo.exists()
elif repo_exists and not force: elif repo_exists and not force:
# can't overwrite data # can't overwrite data
assert run.failure assert run.failure
assert run.err == '' assert run.out == ''
assert 'Git repo already exists' in run.out assert 'Git repo already exists' in run.err
else: else:
# clone should succeed, and repo should be configured properly # clone should succeed, and repo should be configured properly
assert successful_clone(run, paths, repo_config) assert successful_clone(run, paths, repo_config)
@ -297,8 +297,8 @@ def test_alternate_branch(runner, paths, yadm_cmd, repo_config, branch):
if branch == 'invalid': if branch == 'invalid':
assert run.failure assert run.failure
assert 'ERROR: Clone failed' in run.out assert 'ERROR: Clone failed' in run.err
assert f"'origin/{branch}' does not exist in {remote_url}" in run.out assert f"'origin/{branch}' does not exist in {remote_url}" in run.err
else: else:
assert successful_clone(run, paths, repo_config) assert successful_clone(run, paths, repo_config)
@ -344,8 +344,8 @@ def test_no_repo(runner, yadm_cmd, ):
"""Test cloning without specifying a repo""" """Test cloning without specifying a repo"""
run = runner(command=yadm_cmd('clone')) run = runner(command=yadm_cmd('clone'))
assert run.failure assert run.failure
assert run.err == '' assert run.out == ''
assert 'ERROR: No repository provided' in run.out assert 'ERROR: No repository provided' in run.err
def verify_head(paths, branch): def verify_head(paths, branch):

View file

@ -212,7 +212,7 @@ def test_symmetric_encrypt(
assert run.err == '' assert run.err == ''
if missing_encrypt: if missing_encrypt:
assert 'does not exist' in run.out assert 'does not exist' in run.err
elif bad_phrase: elif bad_phrase:
assert 'Invalid passphrase' in run.err assert 'Invalid passphrase' in run.err
else: else:
@ -313,7 +313,7 @@ def test_asymmetric_encrypt(
runner, gnupg, paths.archive, encrypt_targets) runner, gnupg, paths.archive, encrypt_targets)
else: else:
assert run.failure assert run.failure
assert 'Unable to write' in run.out assert 'Unable to write' in run.out if expect else run.err
if ask: if ask:
assert 'Enter the user ID' in run.out assert 'Enter the user ID' in run.out
@ -380,7 +380,7 @@ def test_asymmetric_decrypt(
assert paths.work.join(filename).read() == filename assert paths.work.join(filename).read() == filename
else: else:
assert run.failure assert run.failure
assert 'Unable to extract encrypted files' in run.out assert 'Unable to extract encrypted files' in run.err
@pytest.mark.parametrize( @pytest.mark.parametrize(

View file

@ -35,13 +35,13 @@ def test_enter(runner, yadm_cmd, paths, shell, success):
run = runner(command=yadm_cmd('enter'), env=env) run = runner(command=yadm_cmd('enter'), env=env)
assert run.success == success assert run.success == success
assert run.err == ''
prompt = f'yadm shell ({paths.repo})' prompt = f'yadm shell ({paths.repo})'
if success: if success:
assert run.out.startswith('Entering yadm repo') assert run.out.startswith('Entering yadm repo')
assert run.out.rstrip().endswith('Leaving yadm repo') assert run.out.rstrip().endswith('Leaving yadm repo')
if not success: assert run.err == ''
assert 'does not refer to an executable' in run.out else:
assert 'does not refer to an executable' in run.err
if 'env' in shell: if 'env' in shell:
assert f'GIT_DIR={paths.repo}' in run.out assert f'GIT_DIR={paths.repo}' in run.out
assert f'GIT_WORK_TREE={paths.work}' in run.out assert f'GIT_WORK_TREE={paths.work}' in run.out

View file

@ -42,7 +42,7 @@ def test_ext_encryption(runner, yadm, paths, tmpdir, crypt, cmd, var):
else: else:
assert run.success assert run.success
assert run.out.strip() == 'ext-crypt ran' assert run.out.strip() == 'ext-crypt ran'
assert run.err == ''
else: else:
assert run.failure assert run.failure
assert f"command '{pgm}' cannot be located" in run.out assert f"command '{pgm}' cannot be located" in run.err
assert run.err == ''

View file

@ -52,15 +52,15 @@ def test_init(
# run init # run init
run = runner(yadm_cmd(*args), env={'HOME': home}) run = runner(yadm_cmd(*args), env={'HOME': home})
assert run.err == ''
if repo_present and not force: if repo_present and not force:
assert run.failure assert run.failure
assert 'repo already exists' in run.out assert 'repo already exists' in run.err
assert old_repo.isfile(), 'Missing original repo' assert old_repo.isfile(), 'Missing original repo'
else: else:
assert run.success assert run.success
assert 'Initialized empty shared Git repository' in run.out assert 'Initialized empty shared Git repository' in run.out
assert run.err == ''
if repo_present: if repo_present:
assert not old_repo.isfile(), 'Original repo still exists' assert not old_repo.isfile(), 'Original repo still exists'

View file

@ -85,6 +85,7 @@ def run_test(runner, paths, args, expected_matches, expected_code=0):
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.code == expected_code assert run.code == expected_code
assert run.err == '' assert run.success == (run.code == 0)
assert (run.err if run.success else run.out) == ''
for match in expected_matches: for match in expected_matches:
assert match in run.out assert match in run.out if run.success else run.err

View file

@ -51,14 +51,14 @@ def test_encrypt_decrypt(runner, paths, cipher, mode):
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.err == ''
if cipher != 'bad': if cipher != 'bad':
assert run.success assert run.success
assert run.out.startswith(cipher) assert run.out.startswith(cipher)
assert str(paths.archive) in run.out assert str(paths.archive) in run.out
assert run.err == ''
else: else:
assert run.failure assert run.failure
assert 'Unknown cipher' in run.out assert 'Unknown cipher' in run.err
@pytest.mark.parametrize('condition', ['default', 'override']) @pytest.mark.parametrize('condition', ['default', 'override'])

View file

@ -67,6 +67,7 @@ def test_distro(runner, yadm):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
function config() {{ echo "$1"; }}
function query_distro() {{ echo "testdistro"; }} function query_distro() {{ echo "testdistro"; }}
set_local_alt_values set_local_alt_values
echo "distro='$local_distro'" echo "distro='$local_distro'"

View file

@ -29,12 +29,11 @@ def test_upgrade_errors(tmpdir, runner, yadm, condition):
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.failure assert run.failure
assert run.err == '' assert 'Unable to upgrade' in run.err
assert 'Unable to upgrade' in run.out
if condition in ['override', 'equal']: if condition in ['override', 'equal']:
assert 'Paths have been overridden' in run.out assert 'Paths have been overridden' in run.err
if condition == 'existing_repo': elif condition == 'existing_repo':
assert 'already exists' in run.out assert 'already exists' in run.err
@pytest.mark.parametrize( @pytest.mark.parametrize(

View file

@ -34,7 +34,6 @@ def test_x_program(
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.success == success assert run.success == success
assert run.err == ''
# [GIT,GPG]_PROGRAM set correctly # [GIT,GPG]_PROGRAM set correctly
if value == 'program': if value == 'program':
@ -44,4 +43,6 @@ def test_x_program(
# error reported about bad config # error reported about bad config
if match: if match:
assert match in run.out assert match in run.err
else:
assert run.err == ''

2
yadm
View file

@ -1745,7 +1745,7 @@ function debug() {
function error_out() { function error_out() {
echo_e "ERROR: $*" echo_e "ERROR: $*" >&2
exit_with_hook 1 exit_with_hook 1
} }