|
2 | 2 | # SPDX-License-Identifier: BSD-3-Clause
|
3 | 3 |
|
4 | 4 | import logging
|
| 5 | +import os |
| 6 | +import tempfile |
5 | 7 | import unittest
|
6 | 8 | from pathlib import Path
|
7 | 9 |
|
@@ -50,8 +52,8 @@ def test_duplicates(self):
|
50 | 52 | setmap = state.get_setmap(codebase)
|
51 | 53 | self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")
|
52 | 54 |
|
53 |
| - def test_symlinks(self): |
54 |
| - """Check that symlinks do not count towards divergence.""" |
| 55 | + def test_symlink_directories(self): |
| 56 | + """Check that symlink directories do not count towards divergence.""" |
55 | 57 |
|
56 | 58 | cpufile = str(self.rootdir / "cpu/foo.cpp")
|
57 | 59 | cpu2file = str(self.rootdir / "cpu2/foo.cpp")
|
@@ -83,6 +85,40 @@ def test_symlinks(self):
|
83 | 85 | setmap = state.get_setmap(codebase)
|
84 | 86 | self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")
|
85 | 87 |
|
| 88 | + def test_symlink_files(self): |
| 89 | + """Check that symlink files do not count towards divergence.""" |
| 90 | + tmp = tempfile.TemporaryDirectory() |
| 91 | + p = Path(tmp.name) |
| 92 | + with open(p / "base.cpp", mode="w") as f: |
| 93 | + f.write("void foo();") |
| 94 | + os.symlink(p / "base.cpp", p / "symlink.cpp") |
| 95 | + |
| 96 | + codebase = CodeBase(p) |
| 97 | + configuration = { |
| 98 | + "test": [ |
| 99 | + { |
| 100 | + "file": str(p / "base.cpp"), |
| 101 | + "defines": [], |
| 102 | + "include_paths": [], |
| 103 | + "include_files": [], |
| 104 | + }, |
| 105 | + { |
| 106 | + "file": str(p / "symlink.cpp"), |
| 107 | + "defines": [], |
| 108 | + "include_paths": [], |
| 109 | + "include_files": [], |
| 110 | + }, |
| 111 | + ], |
| 112 | + } |
| 113 | + |
| 114 | + expected_setmap = {frozenset(["test"]): 1} |
| 115 | + |
| 116 | + state = finder.find(self.rootdir, codebase, configuration) |
| 117 | + setmap = state.get_setmap(codebase) |
| 118 | + self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap") |
| 119 | + |
| 120 | + tmp.cleanup() |
| 121 | + |
86 | 122 |
|
87 | 123 | if __name__ == "__main__":
|
88 | 124 | unittest.main()
|
0 commit comments