diff --git a/requirements-dev.txt b/requirements-dev.txt index 4ca65b4..e079f8a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1 @@ pytest -pytest-git diff --git a/test/test_clang_format.py b/test/test_clang_format.py index d5da57f..c632d85 100644 --- a/test/test_clang_format.py +++ b/test/test_clang_format.py @@ -5,6 +5,13 @@ import tempfile +@pytest.fixture +def repo(tmp_path, monkeypatch): + monkeypatch.chdir(tmp_path) + subprocess.run("git init", shell=True) + return tmp_path + + @pytest.mark.parametrize("testcase", [("helloworld.cc", "helloworld_format.cc")]) def test_clang_format(testcase): # Get full paths to the test data @@ -21,14 +28,14 @@ def test_clang_format(testcase): assert filecmp.cmp(outname, test_output) -def test_git_clang_format(git_repo): +def test_git_clang_format(repo): # Test whether the git-clang-format tool is properly executable # on an empty git repository. # Create a commit with an empty file - open(os.path.join(git_repo.workspace, "test"), "w").close() - git_repo.run("git add test") - git_repo.run("git commit -m initial") + open(repo / "test", "w").close() + subprocess.run("git add test", shell=True) + subprocess.run("git commit -m initial", shell=True) # Check that the clang-format tool runs on the test repo - git_repo.run("git clang-format") + subprocess.run("git clang-format", shell=True)