Skip to content

Commit a1f6040

Browse files
committed
[cmpcodesize] Add some tests for listFunctionSizes
Add unit tests to cmpcodesize. As a basic starting point for unit tests, add some tests for edge cases in listFunctionSizes. Users may now run the unit tests for cmpcodesize by running `python utils/cmpcodesize/setup.py test`.
1 parent 307c1d9 commit a1f6040

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

utils/cmpcodesize/cmpcodesize/compare.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def listFunctionSizes(sizeArray):
192192
for pair in sorted(sizeArray, key=itemgetter(1)):
193193
name = pair[0]
194194
size = pair[1]
195-
print "%8d %s" % (size, name)
195+
return "%8d %s" % (size, name)
196196

197197

198198
def compareFunctionSizes(oldFiles, newFiles):
@@ -227,13 +227,13 @@ def compareFunctionSizes(oldFiles, newFiles):
227227

228228
if onlyInFile1:
229229
print "Only in old file(s)"
230-
listFunctionSizes(onlyInFile1)
230+
print listFunctionSizes(onlyInFile1)
231231
print "Total size of functions only in old file: {}".format(onlyInFile1Size)
232232
print
233233

234234
if onlyInFile2:
235235
print "Only in new files(s)"
236-
listFunctionSizes(onlyInFile2)
236+
print listFunctionSizes(onlyInFile2)
237237
print "Total size of functions only in new file: {}".format(onlyInFile2Size)
238238
print
239239

utils/cmpcodesize/cmpcodesize/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def main():
166166
sizes = collections.defaultdict(int)
167167
for file in oldFiles:
168168
readSizes(sizes, file, True, False)
169-
listFunctionSizes(sizes.items())
169+
print listFunctionSizes(sizes.items())
170170
else:
171171
compareFunctionSizes(oldFiles, newFiles)
172172
else:

utils/cmpcodesize/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
description="A tool to compare the size of Swift compiler build products.",
2121
keywords='compare size swift',
2222

23+
test_suite='tests',
24+
2325
classifiers=[
2426
'Development Status :: 3 - Alpha',
2527
'Environment :: Console',

utils/cmpcodesize/tests/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
3+
from cmpcodesize.compare import listFunctionSizes
4+
5+
6+
class ListFunctionSizesTestCase(unittest.TestCase):
7+
def test_when_size_array_is_none_raises(self):
8+
with self.assertRaises(TypeError):
9+
listFunctionSizes(None)
10+
11+
def test_when_size_array_is_empty_returns_none(self):
12+
self.assertIsNone(listFunctionSizes([]))
13+
14+
15+
if __name__ == '__main__':
16+
unittest.main()

0 commit comments

Comments
 (0)