Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import pytest

GIT2CPP_TEST_WASM = os.getenv('GIT2CPP_TEST_WASM') == "1"
GIT2CPP_TEST_WASM = os.getenv("GIT2CPP_TEST_WASM") == "1"

if GIT2CPP_TEST_WASM:
from .conftest_wasm import *


# Fixture to run test in current tmp_path
@pytest.fixture
def run_in_tmp_path(tmp_path):
Expand All @@ -21,9 +22,10 @@ def run_in_tmp_path(tmp_path):
@pytest.fixture(scope="session")
def git2cpp_path():
if GIT2CPP_TEST_WASM:
return 'git2cpp'
return "git2cpp"
else:
return Path(__file__).parent.parent / 'build' / 'git2cpp'
return Path(__file__).parent.parent / "build" / "git2cpp"


@pytest.fixture
def xtl_clone(git2cpp_path, tmp_path, run_in_tmp_path):
Expand All @@ -39,10 +41,28 @@ def commit_env_config(monkeypatch):
"GIT_AUTHOR_NAME": "Jane Doe",
"GIT_AUTHOR_EMAIL": "jane.doe@blabla.com",
"GIT_COMMITTER_NAME": "Jane Doe",
"GIT_COMMITTER_EMAIL": "jane.doe@blabla.com"
"GIT_COMMITTER_EMAIL": "jane.doe@blabla.com",
}
for key, value in config.items():
if GIT2CPP_TEST_WASM:
subprocess.run(["export", f"{key}='{value}'"], check=True)
else:
monkeypatch.setenv(key, value)


@pytest.fixture
def repo_init_with_commit(commit_env_config, git2cpp_path, tmp_path, run_in_tmp_path):
cmd_init = [git2cpp_path, "init", "."]
p_init = subprocess.run(cmd_init, capture_output=True, cwd=tmp_path, text=True)
assert p_init.returncode == 0

p = tmp_path / "initial.txt"
p.write_text("initial")

cmd_add = [git2cpp_path, "add", "initial.txt"]
p_add = subprocess.run(cmd_add, capture_output=True, cwd=tmp_path, text=True)
assert p_add.returncode == 0

cmd_commit = [git2cpp_path, "commit", "-m", "Initial commit"]
p_commit = subprocess.run(cmd_commit, capture_output=True, cwd=tmp_path, text=True)
assert p_commit.returncode == 0
28 changes: 15 additions & 13 deletions test/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@


@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
def test_add(git2cpp_path, tmp_path, all_flag):
cmd_init = [git2cpp_path, "init", "."]
p_init = subprocess.run(cmd_init, capture_output=True, cwd=tmp_path)
assert p_init.returncode == 0

p = xtl_path / "mook_file.txt"
p.write_text('')
p = tmp_path / "mook_file.txt"
p.write_text("")

p2 = xtl_path / "mook_file_2.txt"
p2.write_text('')
p2 = tmp_path / "mook_file_2.txt"
p2.write_text("")

cmd_add = [git2cpp_path, 'add']
cmd_add = [git2cpp_path, "add"]
if all_flag != "":
cmd_add.append(all_flag)
else:
cmd_add.append("mook_file.txt")
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True)
assert p_add.returncode == 0

cmd_status = [git2cpp_path, 'status', "--long"]
p_status = subprocess.run(cmd_status, cwd=xtl_path, capture_output=True, text=True)
cmd_status = [git2cpp_path, "status", "--long"]
p_status = subprocess.run(cmd_status, cwd=tmp_path, capture_output=True, text=True)
assert p_status.returncode == 0

assert "Changes to be committed" in p_status.stdout
Expand All @@ -33,11 +34,12 @@ def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
else:
assert "Untracked files" in p_status.stdout


def test_add_nogit(git2cpp_path, tmp_path):
p = tmp_path / "mook_file.txt"
p.write_text('')
p.write_text("")

cmd_add = [git2cpp_path, 'add', 'mook_file.txt']
cmd_add = [git2cpp_path, "add", "mook_file.txt"]
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True, capture_output=True)
assert p_add.returncode != 0
assert "error: could not find repository at" in p_add.stderr
47 changes: 23 additions & 24 deletions test/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,51 @@
import pytest


def test_branch_list(xtl_clone, git2cpp_path, tmp_path):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
def test_branch_list(repo_init_with_commit, git2cpp_path, tmp_path):
assert (tmp_path / "initial.txt").exists()

cmd = [git2cpp_path, 'branch']
p = subprocess.run(cmd, capture_output=True, cwd=xtl_path, text=True)
cmd = [git2cpp_path, "branch"]
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode == 0
assert(p.stdout == '* master\n')
assert "* ma" in p.stdout


def test_branch_create_delete(xtl_clone, git2cpp_path, tmp_path):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
def test_branch_create_delete(repo_init_with_commit, git2cpp_path, tmp_path):
assert (tmp_path / "initial.txt").exists()

create_cmd = [git2cpp_path, 'branch', 'foregone']
p_create = subprocess.run(create_cmd, capture_output=True, cwd=xtl_path, text=True)
create_cmd = [git2cpp_path, "branch", "foregone"]
p_create = subprocess.run(create_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_create.returncode == 0

list_cmd = [git2cpp_path, 'branch']
p_list = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
list_cmd = [git2cpp_path, "branch"]
p_list = subprocess.run(list_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_list.returncode == 0
assert(p_list.stdout == ' foregone\n* master\n')
assert " foregone\n* ma" in p_list.stdout

del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
p_del = subprocess.run(del_cmd, capture_output=True, cwd=xtl_path, text=True)
del_cmd = [git2cpp_path, "branch", "-d", "foregone"]
p_del = subprocess.run(del_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_del.returncode == 0

p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_list2.returncode == 0
assert(p_list2.stdout == '* master\n')
assert "* ma" in p_list2.stdout


def test_branch_nogit(git2cpp_path, tmp_path):
cmd = [git2cpp_path, 'branch']
cmd = [git2cpp_path, "branch"]
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode != 0
assert "error: could not find repository at" in p.stderr


def test_branch_new_repo(git2cpp_path, tmp_path, run_in_tmp_path):
# tmp_path exists and is empty.
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []

cmd = [git2cpp_path, 'init']
p = subprocess.run(cmd, cwd = tmp_path)
cmd = [git2cpp_path, "init"]
subprocess.run(cmd, cwd=tmp_path, check=True)

branch_cmd = [git2cpp_path, 'branch']
p_branch = subprocess.run(branch_cmd, cwd = tmp_path)
branch_cmd = [git2cpp_path, "branch"]
p_branch = subprocess.run(branch_cmd, cwd=tmp_path)

assert p_branch.returncode == 0
Loading