tools: Support removing header in add_header.py
In addition to add a header, also support removing a header in
add_header.py. Since a lot of operations are the same, this is better
than adding a new file doing the remove.
Bug: 3311983
Change-Id: Ia358780d82ceb069bb91c2a898d3966bd8a361d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3318619
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Commit-Queue: Xiaohan Wang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#949172}
diff --git a/tools/add_header_test.py b/tools/add_header_test.py
index 0020518..453bc863 100755
--- a/tools/add_header_test.py
+++ b/tools/add_header_test.py
@@ -360,9 +360,9 @@
])
-class InsertHeaderIntoSourceTest(unittest.TestCase):
+class AddHeaderToSourceTest(unittest.TestCase):
def testAddInclude(self):
- source = add_header.InsertHeaderIntoSource(
+ source = add_header.AddHeaderToSource(
'cow.cc', '\n'.join([
'// Copyright info here.', '', '#include <utility>',
'// For cow speech synthesis.',
@@ -388,13 +388,13 @@
'#include <memory>', '#include "cow.h"', 'namespace bovine {', '',
'// TODO: Implement.', '} // namespace bovine'
])
- self.assertEqual(
- add_header.InsertHeaderIntoSource('cow.cc', source, '<memory>'), source)
+ self.assertEqual(add_header.AddHeaderToSource('cow.cc', source, '<memory>'),
+ None)
def testConditionalIncludesLeftALone(self):
# TODO(dcheng): Conditional header handling could probably be more clever.
# But for the moment, this is probably Good Enough.
- source = add_header.InsertHeaderIntoSource(
+ source = add_header.AddHeaderToSource(
'cow.cc', '\n'.join([
'// Copyright info here.', '', '#include "cow.h"',
'#include <utility>', '// For cow speech synthesis.',
@@ -412,6 +412,28 @@
'#endif // defined(USE_AURA)', ''
]))
+ def testRemoveInclude(self):
+ source = add_header.AddHeaderToSource(
+ 'cow.cc',
+ '\n'.join([
+ '// Copyright info here.', '', '#include <memory>',
+ '#include <utility>', '// For cow speech synthesis.',
+ '#include "moo.h" // TODO: Add Linux audio support.',
+ '#include <time.h>', '#include "cow.h"', 'namespace bovine {', '',
+ '// TODO: Implement.', '} // namespace bovine'
+ ]),
+ '<utility>',
+ remove=True)
+ self.assertEqual(
+ source, '\n'.join([
+ '// Copyright info here.', '', '#include "cow.h"', '',
+ '#include <time.h>', '', '#include <memory>', '',
+ '// For cow speech synthesis.',
+ '#include "moo.h" // TODO: Add Linux audio support.',
+ 'namespace bovine {', '', '// TODO: Implement.',
+ '} // namespace bovine', ''
+ ]))
+
if __name__ == '__main__':
unittest.main()