mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-04-01 03:51:31 +00:00
buildman: Add a test helper for creating a line prefix
The split/join code is repeated in a lot of places. Add a function to handle this. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
ce558db34b
commit
c9dd80b3d4
1 changed files with 31 additions and 20 deletions
|
@ -220,6 +220,22 @@ class TestBuild(unittest.TestCase):
|
||||||
Args:
|
Args:
|
||||||
lines: Iterator containing the lines returned from the summary
|
lines: Iterator containing the lines returned from the summary
|
||||||
"""
|
"""
|
||||||
|
def add_line_prefix(prefix, error_str):
|
||||||
|
"""Add a prefix to each line of a string
|
||||||
|
|
||||||
|
The training \n in error_str is removed before processing
|
||||||
|
|
||||||
|
Args:
|
||||||
|
prefix: String prefix to add
|
||||||
|
error_str: Error string containing the lines
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
New string where each line has the prefix added
|
||||||
|
"""
|
||||||
|
lines = error_str.strip().splitlines()
|
||||||
|
new_lines = [prefix + line for line in lines]
|
||||||
|
return '\n'.join(new_lines)
|
||||||
|
|
||||||
# Upstream commit: no errors
|
# Upstream commit: no errors
|
||||||
self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
|
self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
|
||||||
|
|
||||||
|
@ -236,8 +252,8 @@ class TestBuild(unittest.TestCase):
|
||||||
|
|
||||||
# Second commit: The warnings should be listed
|
# Second commit: The warnings should be listed
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, 'w+%s' %
|
|
||||||
errors[0].rstrip().replace('\n', '\nw+'))
|
self.assertEqual(line.text, add_line_prefix('w+', errors[0]))
|
||||||
self.assertEqual(line.colour, col.MAGENTA)
|
self.assertEqual(line.colour, col.MAGENTA)
|
||||||
|
|
||||||
# Third commit: Still fails
|
# Third commit: Still fails
|
||||||
|
@ -250,8 +266,7 @@ class TestBuild(unittest.TestCase):
|
||||||
|
|
||||||
# Expect a compiler error
|
# Expect a compiler error
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, '+%s' %
|
self.assertEqual(line.text, add_line_prefix('+', errors[1]))
|
||||||
errors[1].rstrip().replace('\n', '\n+'))
|
|
||||||
self.assertEqual(line.colour, col.RED)
|
self.assertEqual(line.colour, col.RED)
|
||||||
|
|
||||||
# Fourth commit: Compile errors are fixed, just have warning for board3
|
# Fourth commit: Compile errors are fixed, just have warning for board3
|
||||||
|
@ -269,13 +284,11 @@ class TestBuild(unittest.TestCase):
|
||||||
|
|
||||||
# Compile error fixed
|
# Compile error fixed
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, '-%s' %
|
self.assertEqual(line.text, add_line_prefix('-', errors[1]))
|
||||||
errors[1].rstrip().replace('\n', '\n-'))
|
|
||||||
self.assertEqual(line.colour, col.GREEN)
|
self.assertEqual(line.colour, col.GREEN)
|
||||||
|
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, 'w+%s' %
|
self.assertEqual(line.text, add_line_prefix('w+', errors[2]))
|
||||||
errors[2].rstrip().replace('\n', '\nw+'))
|
|
||||||
self.assertEqual(line.colour, col.MAGENTA)
|
self.assertEqual(line.colour, col.MAGENTA)
|
||||||
|
|
||||||
# Fifth commit
|
# Fifth commit
|
||||||
|
@ -287,14 +300,13 @@ class TestBuild(unittest.TestCase):
|
||||||
# The second line of errors[3] is a duplicate, so buildman will drop it
|
# The second line of errors[3] is a duplicate, so buildman will drop it
|
||||||
expect = errors[3].rstrip().split('\n')
|
expect = errors[3].rstrip().split('\n')
|
||||||
expect = [expect[0]] + expect[2:]
|
expect = [expect[0]] + expect[2:]
|
||||||
|
expect = '\n'.join(expect)
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, '+%s' %
|
self.assertEqual(line.text, add_line_prefix('+', expect))
|
||||||
'\n'.join(expect).replace('\n', '\n+'))
|
|
||||||
self.assertEqual(line.colour, col.RED)
|
self.assertEqual(line.colour, col.RED)
|
||||||
|
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, 'w-%s' %
|
self.assertEqual(line.text, add_line_prefix('w-', errors[2]))
|
||||||
errors[2].rstrip().replace('\n', '\nw-'))
|
|
||||||
self.assertEqual(line.colour, col.CYAN)
|
self.assertEqual(line.colour, col.CYAN)
|
||||||
|
|
||||||
# Sixth commit
|
# Sixth commit
|
||||||
|
@ -305,14 +317,13 @@ class TestBuild(unittest.TestCase):
|
||||||
# The second line of errors[3] is a duplicate, so buildman will drop it
|
# The second line of errors[3] is a duplicate, so buildman will drop it
|
||||||
expect = errors[3].rstrip().split('\n')
|
expect = errors[3].rstrip().split('\n')
|
||||||
expect = [expect[0]] + expect[2:]
|
expect = [expect[0]] + expect[2:]
|
||||||
|
expect = '\n'.join(expect)
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, '-%s' %
|
self.assertEqual(line.text, add_line_prefix('-', expect))
|
||||||
'\n'.join(expect).replace('\n', '\n-'))
|
|
||||||
self.assertEqual(line.colour, col.GREEN)
|
self.assertEqual(line.colour, col.GREEN)
|
||||||
|
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, 'w-%s' %
|
self.assertEqual(line.text, add_line_prefix('w-', errors[0]))
|
||||||
errors[0].rstrip().replace('\n', '\nw-'))
|
|
||||||
self.assertEqual(line.colour, col.CYAN)
|
self.assertEqual(line.colour, col.CYAN)
|
||||||
|
|
||||||
# Seventh commit
|
# Seventh commit
|
||||||
|
@ -322,16 +333,16 @@ class TestBuild(unittest.TestCase):
|
||||||
# Pick out the correct error lines
|
# Pick out the correct error lines
|
||||||
expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
|
expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
|
||||||
expect = expect_str[3:8] + [expect_str[-1]]
|
expect = expect_str[3:8] + [expect_str[-1]]
|
||||||
|
expect = '\n'.join(expect)
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, '+%s' %
|
self.assertEqual(line.text, add_line_prefix('+', expect))
|
||||||
'\n'.join(expect).replace('\n', '\n+'))
|
|
||||||
self.assertEqual(line.colour, col.RED)
|
self.assertEqual(line.colour, col.RED)
|
||||||
|
|
||||||
# Now the warnings lines
|
# Now the warnings lines
|
||||||
expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
|
expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
|
||||||
|
expect = '\n'.join(expect)
|
||||||
line = next(lines)
|
line = next(lines)
|
||||||
self.assertEqual(line.text, 'w+%s' %
|
self.assertEqual(line.text, add_line_prefix('w+', expect))
|
||||||
'\n'.join(expect).replace('\n', '\nw+'))
|
|
||||||
self.assertEqual(line.colour, col.MAGENTA)
|
self.assertEqual(line.colour, col.MAGENTA)
|
||||||
|
|
||||||
def testOutput(self):
|
def testOutput(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue