summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-12-27 08:49:24 +0200
committerLars Wirzenius <liw@liw.fi>2023-12-27 08:49:24 +0200
commit72db607705260ce6cb1ee1c5454f46ff161c343b (patch)
treee741b0695f565b8d599b0931fc0b8315049af50f
parente10866211a6781d35f5b402a7e45167c9e69ec5a (diff)
downloadwumpus-hunter-72db607705260ce6cb1ee1c5454f46ff161c343b.tar.gz
feat: actually run tests
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rwxr-xr-xwumpus-hunter71
1 files changed, 71 insertions, 0 deletions
diff --git a/wumpus-hunter b/wumpus-hunter
index 306d823..7e7041a 100755
--- a/wumpus-hunter
+++ b/wumpus-hunter
@@ -1,10 +1,15 @@
#!/usr/bin/python3
import argparse
+import logging
+import os
+import subprocess
HEARTWOOD_URL = "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git"
HEARTWOOD_REF = "master"
+CLONE_DIR = os.path.expanduser("~/src")
+TEST_CMD = "timeout 600s cargo test"
def parse_args():
@@ -13,12 +18,78 @@ def parse_args():
"--url", default=HEARTWOOD_URL, help="URL for git repository to test"
)
p.add_argument("--ref", default=HEARTWOOD_REF, help="Ref to test")
+ p.add_argument(
+ "--dir", default=CLONE_DIR, help="Directory where to clone the repository"
+ )
+ p.add_argument("--test", default=TEST_CMD, help="Command to run tests")
return p.parse_args()
+def setup_logging():
+ logging.basicConfig(level=logging.DEBUG)
+
+
+def get_code(url, ref, dirname):
+ if not os.path.exists(dirname):
+ git_clone(url, dirname)
+ git_checkout(dirname, ref)
+ else:
+ git_checkout(dirname, ref)
+ git_remote_update(url, dirname)
+ git_clean(dirname)
+ git_status(dirname)
+ git_show_head(dirname)
+
+
+def git_clone(url, dirname):
+ logging.info(f"clone repository {url} to {dirname}")
+ git("clone", url, dirname)
+
+
+def git_checkout(dirname, ref):
+ logging.info(f"checkout {ref} in {dirname}")
+ git("checkout", ref, cwd=dirname)
+
+
+def git_remote_update(url, dirname):
+ logging.info(f"update clone of {url} in {dirname}")
+ git("remote", "update", cwd=dirname)
+
+
+def git_clean(dirname):
+ logging.info(f"remove files not in git in {dirname}")
+ git("clean", "-fdx", cwd=dirname)
+
+
+def git_status(dirname):
+ logging.info("show git status in {dirname}")
+ git("status", "--ignored", cwd=dirname)
+
+
+def git_show_head(dirname):
+ logging.info("show current commit in {dirname}")
+ git("--no-pager", "show", "HEAD", cwd=dirname)
+
+
+def git(*args, cwd=None):
+ p = subprocess.run(["git"] + list(args), check=True, cwd=cwd)
+ if p.returncode != 0:
+ return Exception(f"git {args} failed")
+
+
+def run_tests(dirname, cmd):
+ logging.info(f"run tests in {dirname}: {cmd}")
+ p = subprocess.run(["bash", "-c", cmd], check=True, cwd=dirname)
+ if p.returncode != 0:
+ return Exception(f"test command failed {cmd}")
+
+
def main():
args = parse_args()
print(args)
+ setup_logging()
+ get_code(args.url, args.ref, args.dir)
+ run_tests(args.dir, args.test)
main()