|
|
|
@@ -3,6 +3,7 @@ import io
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import pathlib
|
|
|
|
|
import shutil
|
|
|
|
|
import signal
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
@@ -19,7 +20,6 @@ from failure import Failure
|
|
|
|
|
from test_env import isolated_env
|
|
|
|
|
|
|
|
|
|
BIN = pathlib.Path(__file__).resolve().parents[1]
|
|
|
|
|
TOOL = BIN / "cut-release"
|
|
|
|
|
# cut-release cuts the clone it ships in, so the tests hand its main the clone to cut.
|
|
|
|
|
CUT = [sys.executable, "-c", "import sys; sys.path.insert(0, sys.argv[1]); from cut_release import main; sys.exit(main.main(sys.argv[3:], sys.argv[2]))", str(BIN)]
|
|
|
|
|
|
|
|
|
@@ -157,8 +157,8 @@ class Cut(unittest.TestCase):
|
|
|
|
|
def set_checks(self, checks: str) -> None:
|
|
|
|
|
self.forge_state({**self.forge_state(), "checks": checks})
|
|
|
|
|
|
|
|
|
|
def cut(self) -> subprocess.CompletedProcess[str]:
|
|
|
|
|
return subprocess.run([*CUT, str(self.clone)], capture_output=True, env=self.env, text=True)
|
|
|
|
|
def cut(self, *args: str) -> subprocess.CompletedProcess[str]:
|
|
|
|
|
return subprocess.run([*CUT, str(self.clone), *args], capture_output=True, env=self.env, text=True)
|
|
|
|
|
|
|
|
|
|
def origin_git(self, *args: str) -> str:
|
|
|
|
|
return self.git(self.temp, "--git-dir", str(self.origin), *args)
|
|
|
|
@@ -185,6 +185,14 @@ class Cut(unittest.TestCase):
|
|
|
|
|
self.assertEqual(self.git(self.clone, "rev-parse", "HEAD"), head, "the clone's own checkout stays where it was")
|
|
|
|
|
self.assertEqual(self.git(self.clone, "status", "--porcelain"), "")
|
|
|
|
|
|
|
|
|
|
def test_cuts_the_clone_it_ships_in_whatever_the_directory_it_is_run_from(self):
|
|
|
|
|
# The tools are untracked in this clone, so the cut leaves them as they are.
|
|
|
|
|
shutil.copytree(BIN, self.clone / "bin", ignore=shutil.ignore_patterns("test_*", "__pycache__"))
|
|
|
|
|
|
|
|
|
|
ran = subprocess.run([sys.executable, str(self.clone / "bin" / "cut-release")], capture_output=True, cwd=self.temp, env=self.env, text=True)
|
|
|
|
|
|
|
|
|
|
self.assert_cut(ran)
|
|
|
|
|
|
|
|
|
|
def test_cuts_through_gh_on_a_github_origin(self):
|
|
|
|
|
self.use_github()
|
|
|
|
|
ran = self.cut()
|
|
|
|
@@ -263,7 +271,7 @@ class Cut(unittest.TestCase):
|
|
|
|
|
self.assertTrue(line.startswith("cut-release: "), line)
|
|
|
|
|
for fact in facts:
|
|
|
|
|
self.assertIn(fact, line)
|
|
|
|
|
self.assertEqual(ran.stdout.splitlines()[-1], "Done: v0.2.0 is cut and pushed. Each clone of a release takes it with its bin/self-update.")
|
|
|
|
|
self.assertEqual(ran.stdout.splitlines()[-1], "Done: v0.2.0 is cut and pushed. Each clone of a release takes it with its own bin/self-update.")
|
|
|
|
|
|
|
|
|
|
def test_deletes_the_merged_release_branch_on_origin(self):
|
|
|
|
|
self.assert_cut(self.cut())
|
|
|
|
@@ -277,7 +285,7 @@ class Cut(unittest.TestCase):
|
|
|
|
|
self.assert_cut(ran)
|
|
|
|
|
self.assertIn("cut-release: warning: the branch release-0.2.0 stays on origin:", ran.stderr)
|
|
|
|
|
self.assertIn("deletes are refused", ran.stderr)
|
|
|
|
|
self.assertEqual(ran.stdout.splitlines()[-1], "Done: v0.2.0 is cut and pushed. Each clone of a release takes it with its bin/self-update.")
|
|
|
|
|
self.assertEqual(ran.stdout.splitlines()[-1], "Done: v0.2.0 is cut and pushed. Each clone of a release takes it with its own bin/self-update.")
|
|
|
|
|
|
|
|
|
|
def test_stops_where_the_tag_exists_on_another_commit_and_a_rerun_tags_the_merged_commit(self):
|
|
|
|
|
self.git(self.clone, "switch", "-q", "-c", "side")
|
|
|
|
@@ -597,13 +605,19 @@ class Cut(unittest.TestCase):
|
|
|
|
|
self.assertEqual(self.forge_state()["pulls"], [])
|
|
|
|
|
|
|
|
|
|
def test_cut_patch_needs_its_commits(self):
|
|
|
|
|
ran = subprocess.run([sys.executable, str(TOOL), "--patch"], capture_output=True, cwd=self.clone, env=self.env, text=True)
|
|
|
|
|
ran = self.cut("--patch")
|
|
|
|
|
self.assertEqual(ran.returncode, 1)
|
|
|
|
|
self.assertIn("usage", ran.stderr)
|
|
|
|
|
self.assertEqual(self.forge_state()["calls"], [])
|
|
|
|
|
|
|
|
|
|
def test_cut_patch_refuses_an_option_as_its_commits(self):
|
|
|
|
|
ran = self.cut("--patch", "--force")
|
|
|
|
|
self.assertEqual(ran.returncode, 1)
|
|
|
|
|
self.assertIn("usage", ran.stderr)
|
|
|
|
|
self.assertEqual(self.forge_state()["calls"], [])
|
|
|
|
|
|
|
|
|
|
def test_refuses_an_option_it_does_not_know(self):
|
|
|
|
|
ran = subprocess.run([sys.executable, str(TOOL), "--force"], capture_output=True, cwd=self.clone, env=self.env, text=True)
|
|
|
|
|
ran = self.cut("--force")
|
|
|
|
|
self.assertEqual(ran.returncode, 1)
|
|
|
|
|
self.assertIn("usage", ran.stderr)
|
|
|
|
|
self.assertEqual(self.forge_state()["calls"], [])
|
|
|
|
|