Skip to content

Commit 8816c78

Browse files
committed
Add wasm test that input prompt using line not character buffering for stdin
1 parent 5ec6e88 commit 8816c78

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

test/test_commit.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytest
44

5+
from .conftest import GIT2CPP_TEST_WASM
6+
57

68
@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
79
def test_commit(commit_env_config, git2cpp_path, tmp_path, all_flag):
@@ -33,10 +35,20 @@ def test_commit(commit_env_config, git2cpp_path, tmp_path, all_flag):
3335
assert "mook_file" not in p_status_2.stdout
3436

3537

36-
@pytest.mark.parametrize("commit_msg", ["Added file", ""])
38+
@pytest.mark.parametrize(
39+
"commit_msg_in,commit_msg_out",
40+
[
41+
("Added file", "Added file"),
42+
("", ""),
43+
("ab\x7fc", "ac"), # Check deletes previous character to prove using stdin line buffering
44+
],
45+
)
3746
def test_commit_message_via_stdin(
38-
commit_env_config, git2cpp_path, tmp_path, run_in_tmp_path, commit_msg
47+
commit_env_config, git2cpp_path, tmp_path, run_in_tmp_path, commit_msg_in, commit_msg_out
3948
):
49+
if not GIT2CPP_TEST_WASM and commit_msg_in != commit_msg_out:
50+
pytest.skip("Skip stdin delete test if not using webassembly")
51+
4052
cmd = [git2cpp_path, "init", "."]
4153
p_init = subprocess.run(cmd)
4254
assert p_init.returncode == 0
@@ -48,9 +60,11 @@ def test_commit_message_via_stdin(
4860
assert p_add.returncode == 0
4961

5062
cmd_commit = [git2cpp_path, "commit"]
51-
p_commit = subprocess.run(cmd_commit, text=True, capture_output=True, input=commit_msg)
63+
p_commit = subprocess.run(
64+
cmd_commit, text=True, capture_output=True, input=commit_msg_in + "\n"
65+
)
5266

53-
if commit_msg == "":
67+
if commit_msg_out == "":
5468
# No commit message
5569
assert p_commit.returncode != 0
5670
assert "Aborting, no commit message specified" in p_commit.stderr
@@ -66,4 +80,4 @@ def test_commit_message_via_stdin(
6680
assert "commit" in lines[0]
6781
assert "Author:" in lines[1]
6882
assert "Date" in lines[2]
69-
assert commit_msg in lines[4]
83+
assert commit_msg_out in lines[4]

0 commit comments

Comments
 (0)