Add wasm test that input prompt using line not character buffering fo… · QuantStack/git2cpp@1ea8bec · GitHub
Skip to content

Commit 1ea8bec

Browse files
authored
Add wasm test that input prompt using line not character buffering for stdin (#146)
* Add wasm test that input prompt using line not character buffering for stdin * Set timeout on wasm test CI run * Update wasm tests in line with latest changes
1 parent 5b2e65e commit 1ea8bec

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

.github/workflows/test-wasm.yml

Lines changed: 1 addition & 0 deletions

test/conftest_wasm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def pytest_ignore_collect(collection_path: pathlib.Path) -> bool:
3434
"test_revlist.py",
3535
"test_revparse.py",
3636
"test_rm.py",
37+
"test_showref.py",
3738
"test_stash.py",
3839
"test_status.py",
3940
"test_tag.py",
@@ -46,7 +47,7 @@ def run_web_server():
4647
cwd = pathlib.Path(__file__).parent.parent / "wasm/test"
4748
proc = subprocess.Popen(["npm", "run", "serve"], stdout=f, stderr=f, cwd=cwd)
4849
# Wait a bit until server ready to receive connections.
49-
time.sleep(0.5)
50+
time.sleep(1)
5051
yield
5152
proc.terminate()
5253

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]

test/test_status.py

Lines changed: 9 additions & 0 deletions

0 commit comments

Comments
 (0)