Skip to content

Instantly share code, notes, and snippets.

@firesofmay
Last active March 5, 2016 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firesofmay/4c8eedf7940c6aa759d0 to your computer and use it in GitHub Desktop.
Save firesofmay/4c8eedf7940c6aa759d0 to your computer and use it in GitHub Desktop.
Python script to run tests on several commits from origin/<your-branch> to HEAD by deafult
$ test-commits.py -c "lein do clean, deps, compile :all, test :all"
Will check commits in following order
['c4aa669a0f101e8b0ac21b96769148594fee6406', '007f8ab0168b914edbeb85d01248fb4f402bb85c', 'fc876d16ff9daba920fd0b99e61516083041f71b']
~~~~~~~~~~~~~~~~~~
Note: checking out 'c4aa669a0f101e8b0ac21b96769148594fee6406'.
HEAD is now at c4aa669... Add basic operations for aerospike
Compiling clojero.core
lein test clojero.core-test
lein test clojero.test-helper
Ran 1 tests containing 6 assertions.
0 failures, 0 errors.
1/3) Passed for commit: c4aa669a0f101e8b0ac21b96769148594fee6406
~~~~~~~~~~~~~~~~~~
Previous HEAD position was c4aa669... Add basic operations for aerospike
HEAD is now at 007f8ab... Add write-policy helper functions.
Compiling clojero.core
Compiling clojero.policy
lein test clojero.core-test
lein test clojero.policy-test
lein test clojero.test-helper
Ran 5 tests containing 11 assertions.
0 failures, 0 errors.
2/3) Passed for commit: 007f8ab0168b914edbeb85d01248fb4f402bb85c
~~~~~~~~~~~~~~~~~~
Previous HEAD position was 007f8ab... Add write-policy helper functions.
HEAD is now at fc876d1... Add policy helper functions
Compiling clojero.core
Compiling clojero.policy
lein test clojero.core-test
lein test clojero.policy-test
lein test clojero.test-helper
Ran 7 tests containing 13 assertions.
0 failures, 0 errors.
3/3) Passed for commit: fc876d16ff9daba920fd0b99e61516083041f71b
Switching back branch
Switched to branch 'feature/init'
Your branch is ahead of 'origin/feature/init' by 3 commits.
(use "git push" to publish your local commits)
~~~~~~~~~~~All commits passed!~~~~~~~~~~~~~
#!/usr/bin/env python
import subprocess, sys, argparse
p = argparse.ArgumentParser(description="test-commits.py")
p.add_argument("-c", "--cmd", dest="cmd", type=str, default="make", help="Command to execute")
p.add_argument("-oc", "--old-commit", dest="old_commit", type=str, help="Oldest commit to pick")
p.add_argument("-lc", "--latest-commit", dest="latest_commit", type=str, help="Latest commit to pick")
args = p.parse_args()
if args.latest_commit == None:
args.latest_commit = "HEAD"
branch_cmd = "git rev-parse --abbrev-ref HEAD"
branch = subprocess.check_output(branch_cmd, shell=True).strip()
if args.old_commit == None:
args.old_commit = "origin/" + branch
list_of_commits_cmd = "git rev-list {}..{}".format(args.old_commit,args.latest_commit)
commits = subprocess.check_output(list_of_commits_cmd, shell=True).split()
# Oldest commit should run first
commits.reverse()
total_commits = len(commits)
print "Will check commits in following order"
print commits
switch_cmd = "git checkout "+ branch
for commit_number, commit in enumerate(commits, start=1):
print "\n\n~~~~~~~~~~~~~~~~~~"
checkout_commit = "git checkout " + commit
subprocess.call(checkout_commit, shell=True)
exit_code = subprocess.call(args.cmd, shell=True)
if exit_code == 0:
print "{}/{}) Passed for commit: {}".format(commit_number, total_commits, commit)
else:
print "{}/{}) Tests failed for: ".format(commit_number, total_commits)
subprocess.call("git log HEAD^..HEAD", shell=True)
print "Switching back branch"
subprocess.call(switch_cmd, shell=True)
print "\n~~~~~~~~~~~Failed!~~~~~~~~~~~~~"
sys.exit(1)
print "Switching back branch"
subprocess.call(switch_cmd, shell=True)
print "\n~~~~~~~~~~~All commits passed!~~~~~~~~~~~~~"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment