|
13 | 13 | import multiprocessing |
14 | 14 | import os |
15 | 15 | import unittest |
| 16 | +import tempfile |
16 | 17 |
|
17 | 18 | import clcache |
18 | 19 | from clcache import ( |
@@ -939,6 +940,45 @@ def testTouchEntry(self): |
939 | 940 | self.assertEqual(TestManifest.entry2, manifest.entries()[0]) |
940 | 941 |
|
941 | 942 |
|
| 943 | +class TestCreateManifestEntry(unittest.TestCase): |
| 944 | + @classmethod |
| 945 | + def setUpClass(cls): |
| 946 | + cls.tempDir = tempfile.TemporaryDirectory() |
| 947 | + for i in range(10): |
| 948 | + sampleName = 'sample{}.h'.format(i) |
| 949 | + filePath = os.path.join(cls.tempDir.name, '{}.h'.format(sampleName)) |
| 950 | + with open(filePath, 'w') as f: |
| 951 | + f.write('#define {}'.format(sampleName)) |
| 952 | + |
| 953 | + cls.includePaths = list(sorted(clcache.filesBeneath(cls.tempDir.name))) |
| 954 | + cls.manifestHash = 'ffffffffffffffffffffffffffffffff' |
| 955 | + cls.expectedManifestEntry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, |
| 956 | + TestCreateManifestEntry.includePaths) |
| 957 | + |
| 958 | + @classmethod |
| 959 | + def tearDownClass(cls): |
| 960 | + cls.tempDir.cleanup() |
| 961 | + |
| 962 | + def assertManifestEntryIsCorrect(self, entry): |
| 963 | + self.assertEqual(entry.includesContentHash, TestCreateManifestEntry.expectedManifestEntry.includesContentHash) |
| 964 | + self.assertEqual(entry.objectHash, TestCreateManifestEntry.expectedManifestEntry.objectHash) |
| 965 | + self.assertEqual(entry.includeFiles, TestCreateManifestEntry.expectedManifestEntry.includeFiles) |
| 966 | + |
| 967 | + def testIsConsistentWithSameInput(self): |
| 968 | + entry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, TestCreateManifestEntry.includePaths) |
| 969 | + self.assertManifestEntryIsCorrect(entry) |
| 970 | + |
| 971 | + def testIsConsistentWithReverseList(self): |
| 972 | + reversedIncludePaths = list(reversed(TestCreateManifestEntry.includePaths)) |
| 973 | + entry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, reversedIncludePaths) |
| 974 | + self.assertManifestEntryIsCorrect(entry) |
| 975 | + |
| 976 | + def testIsConsistentWithDuplicateEntries(self): |
| 977 | + includePathsWithDuplicates = TestCreateManifestEntry.includePaths + TestCreateManifestEntry.includePaths |
| 978 | + entry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, includePathsWithDuplicates) |
| 979 | + self.assertManifestEntryIsCorrect(entry) |
| 980 | + |
| 981 | + |
942 | 982 | if __name__ == '__main__': |
943 | 983 | unittest.TestCase.longMessage = True |
944 | 984 | unittest.main() |
0 commit comments