|
| 1 | +from pathlib import Path |
| 2 | +import subprocess |
| 3 | + |
| 4 | + |
| 5 | +def test_init_in_directory(git2cpp_path, tmp_path): |
| 6 | + # tmp_path exists and is empty. |
| 7 | + assert list(tmp_path.iterdir()) == [] |
| 8 | + |
| 9 | + cmd = [git2cpp_path, 'init', '--bare', str(tmp_path)] |
| 10 | + p = subprocess.run(cmd, capture_output=True) |
| 11 | + assert p.returncode == 0 |
| 12 | + assert p.stdout == b'' |
| 13 | + assert p.stderr == b'' |
| 14 | + |
| 15 | + assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [ |
| 16 | + 'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs' |
| 17 | + ] |
| 18 | + |
| 19 | + # TODO: check this is a valid git repo |
| 20 | + |
| 21 | + |
| 22 | +def test_init_in_cwd(git2cpp_path, tmp_path, run_in_tmp_path): |
| 23 | + # tmp_path exists and is empty. |
| 24 | + assert list(tmp_path.iterdir()) == [] |
| 25 | + assert Path.cwd() == tmp_path |
| 26 | + |
| 27 | + cmd = [git2cpp_path, 'init', '--bare'] |
| 28 | + p = subprocess.run(cmd, capture_output=True) |
| 29 | + assert p.returncode == 0 |
| 30 | + assert p.stdout == b'' |
| 31 | + assert p.stderr == b'' |
| 32 | + |
| 33 | + assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [ |
| 34 | + 'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs' |
| 35 | + ] |
| 36 | + |
| 37 | + # TODO: check this is a valid git repo |
| 38 | + |
| 39 | + |
| 40 | +# TODO: Test without bare flag. |
| 41 | + |
| 42 | + |
| 43 | +def test_error_on_unknown_option(git2cpp_path): |
| 44 | + cmd = [git2cpp_path, 'init', '--unknown'] |
| 45 | + p = subprocess.run(cmd, capture_output=True) |
| 46 | + assert p.returncode == 1 |
| 47 | + assert p.stdout == b'' |
| 48 | + assert p.stderr.startswith(b"The following argument was not expected: --unknown") |
| 49 | + |
| 50 | + |
| 51 | +def test_error_on_repeated_directory(git2cpp_path): |
| 52 | + cmd = [git2cpp_path, 'init', 'abc', 'def'] |
| 53 | + p = subprocess.run(cmd, capture_output=True) |
| 54 | + assert p.returncode == 1 |
| 55 | + assert p.stdout == b'' |
| 56 | + assert p.stderr.startswith(b"The following argument was not expected: def") |
0 commit comments