Filter tests when diff'ing against master branch (#103)

This commit is contained in:
Douglas Stebila 2019-04-11 15:23:39 -04:00 committed by GitHub
parent a15bbfcfe0
commit d07e8ae7cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -132,4 +132,39 @@ def permit_test(testname, thing, **args):
if scheme.name.lower() in os.environ['PQCLEAN_SKIP_SCHEMES'].lower().split(','):
return False
if 'PQCLEAN_ONLY_DIFF' in os.environ:
if shutil.which('git') != None:
# if we're on a non-master branch, and the only changes are in schemes,
# only run tests on those schemes
branch_result = subprocess.run(
['git', 'status', '--porcelain=2', '--branch'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
# ensure we're in a working directory
if branch_result.returncode != 0:
return True
# ensure we're not on master branch
for branch_line in branch_result.stdout.decode('utf-8').splitlines():
tokens = branch_line.split(' ')
if tokens[0] == '#' and tokens[1] == 'branch.head':
if tokens[2] == 'master':
return True
# where are there changes?
diff_result = subprocess.run(
['git', 'diff', '--name-only', 'master'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
assert(diff_result.returncode == 0), "Got unexpected return code {}".format(diff_result.returncode)
for diff_line in diff_result.stdout.decode('utf-8').splitlines():
# don't skip test if there are any changes outside schemes
if not(diff_line.startswith('crypto_kem')) and not (diff_line.startswith('crypto_sign')):
return True
# do test if the scheme in question has been changed
if diff_line.startswith(thing.path(base='')):
return True
# there were no changes outside schemes, and the scheme in question had no diffs
return False
return True

View File

@ -77,7 +77,7 @@ class Implementation:
return i
def path(self, base='..') -> str:
return os.path.join(self.scheme.path(), self.name)
return os.path.join(self.scheme.path(base=base), self.name)
def libname(self) -> str:
if os.name == 'nt':