Skip to content

Commit

Permalink
Use set operations instead of loop to find unused Names
Browse files Browse the repository at this point in the history
  • Loading branch information
jougs committed Mar 14, 2018
1 parent ac03064 commit 5a58f65
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions testsuite/unittests/test_unused_names.py
Expand Up @@ -77,29 +77,25 @@ def get_names(fname, pattern):
else:
names_defined.add(h)

names_defined = list(names_defined)
names_defined.sort()


# We call to recursive grep in the shell here, because that's much
# simpler than recursive file iteration and regex matching in Python
grep_cmd = ["grep", "-ro", "names::[A-Za-Z0-9_]*", source_dir]
names_used_raw = check_output(grep_cmd)


names_used = set()
for line in names_used_raw.split("\n"):
if "::" in line:
name = line.split("::")[1]
if name != "":
names_used.add(name)

names_used = list(names_used)
names_used.sort()

names_unused = names_defined - names_used
if len(names_unused) != 0:
print("Unused Name definition(s): " + ", ".join(names_unused))
sys.exit(EXIT_UNUSED_NAME)

for d, u in zip(names_defined, names_used):
if d != u:
print("Unused Name definition: {}".format(d))
sys.exit(EXIT_UNUSED_NAME)

sys.exit(EXIT_SUCCESS)

0 comments on commit 5a58f65

Please sign in to comment.