mirror of
https://github.com/rizsotto/scan-build.git
synced 2025-12-16 12:00:08 +01:00
Handle os.path.commonprefix exceptions (#124)
fix multidrive win chop
On Windows, when using different drives between source and report, `report.chop` raises an exception "ValueError("path is on mount %r, start on mount %r" % (path_drive, start_drive))"
(see https://github.com/python/cpython/blob/master/Lib/ntpath.py#L703)
This commit is contained in:
@@ -492,8 +492,13 @@ def safe_readlines(filename):
|
|||||||
def chop(prefix, filename):
|
def chop(prefix, filename):
|
||||||
# type: (str, str) -> str
|
# type: (str, str) -> str
|
||||||
""" Create 'filename' from '/prefix/filename' """
|
""" Create 'filename' from '/prefix/filename' """
|
||||||
|
result = filename
|
||||||
return filename if not prefix else os.path.relpath(filename, prefix)
|
if prefix:
|
||||||
|
try:
|
||||||
|
result = os.path.relpath(filename, prefix)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def escape(text):
|
def escape(text):
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ class ReportMethodTest(unittest.TestCase):
|
|||||||
self.assertEqual('lib\\file',
|
self.assertEqual('lib\\file',
|
||||||
sut.chop('c:\\prefix\\', 'c:\\prefix\\lib\\file'))
|
sut.chop('c:\\prefix\\', 'c:\\prefix\\lib\\file'))
|
||||||
self.assertEqual('c:\\prefix\\file', sut.chop('', 'c:\\prefix\\file'))
|
self.assertEqual('c:\\prefix\\file', sut.chop('', 'c:\\prefix\\file'))
|
||||||
|
self.assertEqual('c:\\prefix\\file',
|
||||||
|
sut.chop('e:\\prefix', 'c:\\prefix\\file'))
|
||||||
|
|
||||||
@unittest.skipIf(not IS_WINDOWS, 'windows has different path patterns')
|
@unittest.skipIf(not IS_WINDOWS, 'windows has different path patterns')
|
||||||
def test_chop_when_cwd_on_windows(self):
|
def test_chop_when_cwd_on_windows(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user