Skip to content

Commit

Permalink
Print errors to stderr
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erijo committed Jan 5, 2021
1 parent cd50c12 commit 6378fe3
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 34 deletions.
8 changes: 6 additions & 2 deletions test/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ''
4 changes: 2 additions & 2 deletions test/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions test/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions test/test_enter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_ext_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions test/test_unit_configure_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/test_unit_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
1 change: 1 addition & 0 deletions test/test_unit_set_local_alt_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
9 changes: 4 additions & 5 deletions test/test_unit_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions test/test_unit_x_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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 changes: 1 addition & 1 deletion yadm
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ function debug() {

function error_out() {

echo_e "ERROR: $*"
echo_e "ERROR: $*" >&2
exit_with_hook 1

}
Expand Down

0 comments on commit 6378fe3

Please sign in to comment.