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
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ concurrency:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
timeout-minutes: 30
1415
steps:
1516
- name: Checkout
1617
uses: actions/checkout@v6

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
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_status_new_file(repo_init_with_commit, git2cpp_path, tmp_path, short_fl
3030
if long_flag != "":
3131
cmd.append(long_flag)
3232
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True, check=True)
33+
p.stdout = strip_ansi_colours(p.stdout)
3334

3435
if (long_flag == "--long") or ((long_flag == "") & (short_flag == "")):
3536
assert "On branch main" in p.stdout
@@ -72,6 +73,7 @@ def test_status_add_file(repo_init_with_commit, git2cpp_path, tmp_path, short_fl
7273
cmd_status.append(long_flag)
7374
p_status = subprocess.run(cmd_status, capture_output=True, cwd=tmp_path, text=True)
7475
assert p_status.returncode == 0
76+
p_status.stdout = strip_ansi_colours(p_status.stdout)
7577

7678
if (long_flag == "--long") or ((long_flag == "") & (short_flag == "")):
7779
assert "Changes to be committed" in p_status.stdout
@@ -144,6 +146,7 @@ def test_status_rename_detection(repo_init_with_commit, git2cpp_path, tmp_path,
144146
cmd_status.append(short_flag)
145147
p = subprocess.run(cmd_status, capture_output=True, cwd=tmp_path, text=True)
146148
assert p.returncode == 0
149+
p.stdout = strip_ansi_colours(p.stdout)
147150

148151
# Should show as renamed, not as deleted + new file
149152
assert "initial.txt -> initial_renamed.txt" in p.stdout
@@ -223,6 +226,8 @@ def test_status_typechange(repo_init_with_commit, git2cpp_path, tmp_path, short_
223226
p = subprocess.run(cmd_status, capture_output=True, cwd=tmp_path, text=True)
224227

225228
assert p.returncode == 0
229+
p.stdout = strip_ansi_colours(p.stdout)
230+
226231
# Should show typechange in unstaged changes
227232
if short_flag == "-s":
228233
assert " T " in p.stdout
@@ -295,6 +300,8 @@ def test_status_ahead_of_upstream(
295300
p = subprocess.run(cmd_status, capture_output=True, cwd=clone_path, text=True)
296301

297302
assert p.returncode == 0
303+
p.stdout = strip_ansi_colours(p.stdout)
304+
298305
if short_flag == "-s":
299306
if branch_flag == "-b":
300307
assert "...origin/main" in p.stdout
@@ -341,6 +348,8 @@ def test_status_with_branch_and_tracking(
341348
p = subprocess.run(cmd_status, capture_output=True, cwd=clone_path, text=True)
342349

343350
assert p.returncode == 0
351+
p.stdout = strip_ansi_colours(p.stdout)
352+
344353
if short_flag == "-s":
345354
assert "## main" in p.stdout # "main" locally, but "master" in the CI
346355
assert "[ahead 1]" in p.stdout

0 commit comments

Comments
 (0)