Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 6378fe3

Browse files
committed
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.
1 parent cd50c12 commit 6378fe3

13 files changed

+40
-34
lines changed

test/test_bootstrap.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,9 @@ def test_bootstrap(
2727
paths.bootstrap.chmod(0o775)
2828
run = runner(command=yadm_cmd('bootstrap'))
2929
assert run.code == code
30-
assert run.err == ''
31-
assert expect in run.out
30+
if exists and executable:
31+
assert run.err == ''
32+
assert expect in run.out
33+
else:
34+
assert expect in run.err
35+
assert run.out == ''

test/test_clean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ def test_clean_command(runner, yadm_cmd):
77
# do nothing, this is a dangerous Git command when managing dot files
88
# report the command as disabled and exit as a failure
99
assert run.failure
10-
assert run.err == ''
11-
assert 'disabled' in run.out
10+
assert run.out == ''
11+
assert 'disabled' in run.err

test/test_clone.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def test_clone(
5858
if not good_remote:
5959
# clone should fail
6060
assert run.failure
61-
assert run.err != ''
62-
assert 'Unable to fetch origin' in run.out
61+
assert run.out != ''
62+
assert 'Unable to fetch origin' in run.err
6363
assert not paths.repo.exists()
6464
elif repo_exists and not force:
6565
# can't overwrite data
6666
assert run.failure
67-
assert run.err == ''
68-
assert 'Git repo already exists' in run.out
67+
assert run.out == ''
68+
assert 'Git repo already exists' in run.err
6969
else:
7070
# clone should succeed, and repo should be configured properly
7171
assert successful_clone(run, paths, repo_config)
@@ -297,8 +297,8 @@ def test_alternate_branch(runner, paths, yadm_cmd, repo_config, branch):
297297

298298
if branch == 'invalid':
299299
assert run.failure
300-
assert 'ERROR: Clone failed' in run.out
301-
assert f"'origin/{branch}' does not exist in {remote_url}" in run.out
300+
assert 'ERROR: Clone failed' in run.err
301+
assert f"'origin/{branch}' does not exist in {remote_url}" in run.err
302302
else:
303303
assert successful_clone(run, paths, repo_config)
304304

@@ -344,8 +344,8 @@ def test_no_repo(runner, yadm_cmd, ):
344344
"""Test cloning without specifying a repo"""
345345
run = runner(command=yadm_cmd('clone'))
346346
assert run.failure
347-
assert run.err == ''
348-
assert 'ERROR: No repository provided' in run.out
347+
assert run.out == ''
348+
assert 'ERROR: No repository provided' in run.err
349349

350350

351351
def verify_head(paths, branch):

test/test_encryption.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_symmetric_encrypt(
212212
assert run.err == ''
213213

214214
if missing_encrypt:
215-
assert 'does not exist' in run.out
215+
assert 'does not exist' in run.err
216216
elif bad_phrase:
217217
assert 'Invalid passphrase' in run.err
218218
else:
@@ -313,7 +313,7 @@ def test_asymmetric_encrypt(
313313
runner, gnupg, paths.archive, encrypt_targets)
314314
else:
315315
assert run.failure
316-
assert 'Unable to write' in run.out
316+
assert 'Unable to write' in run.out if expect else run.err
317317

318318
if ask:
319319
assert 'Enter the user ID' in run.out
@@ -380,7 +380,7 @@ def test_asymmetric_decrypt(
380380
assert paths.work.join(filename).read() == filename
381381
else:
382382
assert run.failure
383-
assert 'Unable to extract encrypted files' in run.out
383+
assert 'Unable to extract encrypted files' in run.err
384384

385385

386386
@pytest.mark.parametrize(

test/test_enter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ def test_enter(runner, yadm_cmd, paths, shell, success):
3535

3636
run = runner(command=yadm_cmd('enter'), env=env)
3737
assert run.success == success
38-
assert run.err == ''
3938
prompt = f'yadm shell ({paths.repo})'
4039
if success:
4140
assert run.out.startswith('Entering yadm repo')
4241
assert run.out.rstrip().endswith('Leaving yadm repo')
43-
if not success:
44-
assert 'does not refer to an executable' in run.out
42+
assert run.err == ''
43+
else:
44+
assert 'does not refer to an executable' in run.err
4545
if 'env' in shell:
4646
assert f'GIT_DIR={paths.repo}' in run.out
4747
assert f'GIT_WORK_TREE={paths.work}' in run.out

test/test_ext_crypt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_ext_encryption(runner, yadm, paths, tmpdir, crypt, cmd, var):
4242
else:
4343
assert run.success
4444
assert run.out.strip() == 'ext-crypt ran'
45+
assert run.err == ''
4546
else:
4647
assert run.failure
47-
assert f"command '{pgm}' cannot be located" in run.out
48-
assert run.err == ''
48+
assert f"command '{pgm}' cannot be located" in run.err

test/test_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def test_init(
5252

5353
# run init
5454
run = runner(yadm_cmd(*args), env={'HOME': home})
55-
assert run.err == ''
5655

5756
if repo_present and not force:
5857
assert run.failure
59-
assert 'repo already exists' in run.out
58+
assert 'repo already exists' in run.err
6059
assert old_repo.isfile(), 'Missing original repo'
6160
else:
6261
assert run.success
6362
assert 'Initialized empty shared Git repository' in run.out
63+
assert run.err == ''
6464

6565
if repo_present:
6666
assert not old_repo.isfile(), 'Original repo still exists'

test/test_unit_configure_paths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def run_test(runner, paths, args, expected_matches, expected_code=0):
8585
"""
8686
run = runner(command=['bash'], inp=script)
8787
assert run.code == expected_code
88-
assert run.err == ''
88+
assert run.success == (run.code == 0)
89+
assert (run.err if run.success else run.out) == ''
8990
for match in expected_matches:
90-
assert match in run.out
91+
assert match in run.out if run.success else run.err

test/test_unit_encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ def test_encrypt_decrypt(runner, paths, cipher, mode):
5151
"""
5252
run = runner(command=['bash'], inp=script)
5353

54-
assert run.err == ''
5554
if cipher != 'bad':
5655
assert run.success
5756
assert run.out.startswith(cipher)
5857
assert str(paths.archive) in run.out
58+
assert run.err == ''
5959
else:
6060
assert run.failure
61-
assert 'Unknown cipher' in run.out
61+
assert 'Unknown cipher' in run.err
6262

6363

6464
@pytest.mark.parametrize('condition', ['default', 'override'])

test/test_unit_set_local_alt_values.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test_distro(runner, yadm):
6767

6868
script = f"""
6969
YADM_TEST=1 source {yadm}
70+
function config() {{ echo "$1"; }}
7071
function query_distro() {{ echo "testdistro"; }}
7172
set_local_alt_values
7273
echo "distro='$local_distro'"

0 commit comments

Comments
 (0)