1
0
Fork 0
mirror of synced 2024-11-17 06:45:33 -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)
run = runner(command=yadm_cmd('bootstrap'))
assert run.code == code
assert run.err == ''
assert expect in run.out
if exists and executable:
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
# report the command as disabled and exit as a failure
assert run.failure
assert run.err == ''
assert 'disabled' in run.out
assert run.out == ''
assert 'disabled' in run.err

View file

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

View file

@ -212,7 +212,7 @@ def test_symmetric_encrypt(
assert run.err == ''
if missing_encrypt:
assert 'does not exist' in run.out
assert 'does not exist' in run.err
elif bad_phrase:
assert 'Invalid passphrase' in run.err
else:
@ -313,7 +313,7 @@ def test_asymmetric_encrypt(
runner, gnupg, paths.archive, encrypt_targets)
else:
assert run.failure
assert 'Unable to write' in run.out
assert 'Unable to write' in run.out if expect else run.err
if ask:
assert 'Enter the user ID' in run.out
@ -380,7 +380,7 @@ def test_asymmetric_decrypt(
assert paths.work.join(filename).read() == filename
else:
assert run.failure
assert 'Unable to extract encrypted files' in run.out
assert 'Unable to extract encrypted files' in run.err
@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)
assert run.success == success
assert run.err == ''
prompt = f'yadm shell ({paths.repo})'
if success:
assert run.out.startswith('Entering yadm repo')
assert run.out.rstrip().endswith('Leaving yadm repo')
if not success:
assert 'does not refer to an executable' in run.out
assert run.err == ''
else:
assert 'does not refer to an executable' in run.err
if 'env' in shell:
assert f'GIT_DIR={paths.repo}' 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:
assert run.success
assert run.out.strip() == 'ext-crypt ran'
assert run.err == ''
else:
assert run.failure
assert f"command '{pgm}' cannot be located" in run.out
assert run.err == ''
assert f"command '{pgm}' cannot be located" in run.err

View file

@ -52,15 +52,15 @@ def test_init(
# run init
run = runner(yadm_cmd(*args), env={'HOME': home})
assert run.err == ''
if repo_present and not force:
assert run.failure
assert 'repo already exists' in run.out
assert 'repo already exists' in run.err
assert old_repo.isfile(), 'Missing original repo'
else:
assert run.success
assert 'Initialized empty shared Git repository' in run.out
assert run.err == ''
if repo_present:
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)
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:
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)
assert run.err == ''
if cipher != 'bad':
assert run.success
assert run.out.startswith(cipher)
assert str(paths.archive) in run.out
assert run.err == ''
else:
assert run.failure
assert 'Unknown cipher' in run.out
assert 'Unknown cipher' in run.err
@pytest.mark.parametrize('condition', ['default', 'override'])

View file

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

View file

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

View file

@ -34,7 +34,6 @@ def test_x_program(
"""
run = runner(command=['bash'], inp=script)
assert run.success == success
assert run.err == ''
# [GIT,GPG]_PROGRAM set correctly
if value == 'program':
@ -44,4 +43,6 @@ def test_x_program(
# error reported about bad config
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() {
echo_e "ERROR: $*"
echo_e "ERROR: $*" >&2
exit_with_hook 1
}