summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Gräsman <kim.grasman@proceranetworks.com>2017-09-16 21:42:23 +0200
committerKim Gräsman <kim.grasman@gmail.com>2017-09-17 10:34:28 +0200
commit37670ddaff58398a342a690e9dc104e4d150fd73 (patch)
tree93b0fe5cb729884f09d90b912a97afa7c418eafb
parent56e0661c9846124593fab4f054a5518e4e23fa11 (diff)
Make fix_includes.py dry-run return proper exit code
This makes the script match the documentation better, as proposed by issue #479.
-rwxr-xr-xfix_includes.py12
-rwxr-xr-xfix_includes_test.py4
2 files changed, 9 insertions, 7 deletions
diff --git a/fix_includes.py b/fix_includes.py
index 6bfdf77..b95f73b 100755
--- a/fix_includes.py
+++ b/fix_includes.py
@@ -2157,10 +2157,11 @@ def FixManyFiles(iwyu_records, flags):
for iwyu_record in iwyu_records:
try:
fixed_lines = GetFixedFile(iwyu_record, flags)
- if not flags.dry_run and fixed_lines is not None:
+ if fixed_lines is not None:
file_and_fix_pairs.append((iwyu_record.filename, fixed_lines))
- if (flags.checkout_command and
- not os.access(iwyu_record.filename, os.W_OK)):
+ if flags.checkout_command and \
+ not flags.dry_run and \
+ not os.access(iwyu_record.filename, os.W_OK):
files_to_checkout.append(iwyu_record.filename)
except FixIncludesError as why:
print('ERROR: %s - skipping file %s' % (why, iwyu_record.filename))
@@ -2187,8 +2188,9 @@ def FixManyFiles(iwyu_records, flags):
checkout_command += (' -c %d' % flags.append_to_cl)
_RunCommand(checkout_command, files_to_checkout)
- for filename, fixed_lines in file_and_fix_pairs:
- _WriteFileContents(filename, fixed_lines)
+ if not flags.dry_run:
+ for filename, fixed_lines in file_and_fix_pairs:
+ _WriteFileContents(filename, fixed_lines)
files_fixed = [filename for filename, _ in file_and_fix_pairs]
diff --git a/fix_includes_test.py b/fix_includes_test.py
index 70bdc8f..28e255f 100755
--- a/fix_includes_test.py
+++ b/fix_includes_test.py
@@ -291,7 +291,7 @@ The full include-list for unified_diff.cc:
-#include <notused.h>
int main() { return 0; }
-IWYU edited 0 files on your behalf.
+IWYU edited 1 files on your behalf.
"""
@@ -3388,7 +3388,7 @@ The full include-list for dry_run:
num_modified_files = fix_includes.ProcessIWYUOutput(
StringIO(iwyu_output), ['dry_run'], self.flags)
self.assertListEqual([], self.actual_after_contents)
- self.assertEqual(0, num_modified_files)
+ self.assertEqual(1, num_modified_files)
def testAddForwardDeclareAndKeepIwyuNamespaceFormat(self):
"""Tests that --keep_iwyu_namespace_format writes namespace lines