Commit dce20078 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

utils.ShellWriter: Don't indent empty lines



Empty lines shouldn't get indented. Unittest included.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent bac6ea51
......@@ -268,12 +268,16 @@ class ShellWriter:
"""
assert self._indent >= 0
self._fh.write(self._indent * self.INDENT_STR)
if args:
self._fh.write(txt % args)
line = txt % args
else:
self._fh.write(txt)
line = txt
if line:
# Indent only if there's something on the line
self._fh.write(self._indent * self.INDENT_STR)
self._fh.write(line)
self._fh.write("\n")
......
......@@ -315,6 +315,27 @@ class TestShellWriter(unittest.TestCase):
sw = None
self.assertEqual(buf.getvalue(), "")
def testEmptyLines(self):
buf = StringIO()
sw = utils.ShellWriter(buf)
def _AddLevel(level):
if level == 6:
return
sw.IncIndent()
try:
# Add empty line, it should not be indented
sw.Write("")
sw.Write(str(level))
_AddLevel(level + 1)
finally:
sw.DecIndent()
_AddLevel(1)
self.assertEqual(buf.getvalue(),
"".join("\n%s%s\n" % (i * " ", i) for i in range(1, 6)))
class TestNormalizeAndValidateMac(unittest.TestCase):
def testInvalid(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment