From 2cccb137a7f936a34abf0a24d51edc0a07e55ef6 Mon Sep 17 00:00:00 2001 From: Adrianno Sampaio Date: Wed, 24 Oct 2018 14:56:37 -0300 Subject: [PATCH 1/5] Include error message when clang-format is not found --- esss_fix_format/cli.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/esss_fix_format/cli.py b/esss_fix_format/cli.py index 4fdd75a..8a431ad 100644 --- a/esss_fix_format/cli.py +++ b/esss_fix_format/cli.py @@ -165,7 +165,19 @@ def _process_file(filename, check, format_code): changed = b' Date: Fri, 26 Oct 2018 10:03:24 -0300 Subject: [PATCH 2/5] Apply fix-format to the code, remove extra error message and add unit test --- esss_fix_format/cli.py | 5 ++--- tests/test_esss_fix_format.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/esss_fix_format/cli.py b/esss_fix_format/cli.py index 8a431ad..d4c4c59 100644 --- a/esss_fix_format/cli.py +++ b/esss_fix_format/cli.py @@ -165,19 +165,18 @@ def _process_file(filename, check, format_code): changed = b' Date: Fri, 26 Oct 2018 16:21:05 -0300 Subject: [PATCH 3/5] Fix incompatible message in test and improve error message --- esss_fix_format/cli.py | 3 ++- tests/test_esss_fix_format.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/esss_fix_format/cli.py b/esss_fix_format/cli.py index d4c4c59..563ec2a 100644 --- a/esss_fix_format/cli.py +++ b/esss_fix_format/cli.py @@ -171,7 +171,8 @@ def _process_file(filename, check, format_code): try: subprocess.check_output('clang-format -i "%s"' % filename, shell=True) except subprocess.CalledProcessError as e: - msg = ': ERROR (%s: %s)' % (type(e).__name__, e) + msg = ': ERROR (%s: %s): ' % (type(e).__name__, e) + msg += 'Please check if "clang-format" is installed and accessible' error_msg = click.format_filename(filename) + msg click.secho(error_msg, fg='red') errors.append(error_msg) diff --git a/tests/test_esss_fix_format.py b/tests/test_esss_fix_format.py index 65683cc..bf73cbe 100644 --- a/tests/test_esss_fix_format.py +++ b/tests/test_esss_fix_format.py @@ -405,18 +405,24 @@ def test_missing_clang_format(tmpdir, mocker, dot_clang_format_to_tmpdir): # File will not pass in the format check check_invalid_file(filename, formatter='clang-format') - expected_failed_command = 'clang-format -i "main.cpp"' + expected_command = 'clang-format -i "main.cpp"' expected_error_code = 1 - expected_error_message = "Command 'clang-format -i \"main.cpp\"' returned non-zero exit status 1" + expected_error_message = "Command '%s' returned non-zero exit status 1" % expected_command + message_extra_details = 'Please check if "clang-format" is installed and accessible' - m = mocker.patch.object( + mocker.patch.object( subprocess, 'check_output', - side_effect=subprocess.CalledProcessError(expected_error_code, expected_failed_command)) + side_effect=subprocess.CalledProcessError(expected_error_code, expected_command)) # Check if the command-line instruction returned an exception # of type CalledProcessError with the correct error message - check_cli_error_output(filename, expected_error_message, formatter='clang-format') + check_cli_error_output( + filename, + expected_error_message, + message_extra_details, + formatter='clang-format' + ) # test should skip file, so no changes are made obtained = filename.read() @@ -451,9 +457,10 @@ def fix_invalid_file(input_file, formatter=None): output.fnmatch_lines(str(input_file) + ': Fixed' + _get_formatter_msg(formatter)) -def check_cli_error_output(input_file, expected_error_message, formatter=None): +def check_cli_error_output(input_file, expected_error_message, message_details, formatter=None): output = run([str(input_file)], expected_exit=1) - msg = ': ERROR (CalledProcessError: %s)' % (expected_error_message) + msg = ': ERROR (CalledProcessError: %s): ' % (expected_error_message) + msg += message_details output.fnmatch_lines(str(input_file) + msg) From b484b179f775b6dbda5b293bb7f2c31bc7b8413d Mon Sep 17 00:00:00 2001 From: Adrianno Sampaio Date: Tue, 30 Oct 2018 11:14:10 -0300 Subject: [PATCH 4/5] Fix py36 unit test expected message --- tests/test_esss_fix_format.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_esss_fix_format.py b/tests/test_esss_fix_format.py index bf73cbe..40765c9 100644 --- a/tests/test_esss_fix_format.py +++ b/tests/test_esss_fix_format.py @@ -408,6 +408,8 @@ def test_missing_clang_format(tmpdir, mocker, dot_clang_format_to_tmpdir): expected_command = 'clang-format -i "main.cpp"' expected_error_code = 1 expected_error_message = "Command '%s' returned non-zero exit status 1" % expected_command + if sys.version_info.major == 2: + expected_error_message += '.' message_extra_details = 'Please check if "clang-format" is installed and accessible' mocker.patch.object( From 72fda4e0bef85cebdd33c4cf8a411693b2ba8939 Mon Sep 17 00:00:00 2001 From: Adrianno Sampaio Date: Wed, 31 Oct 2018 10:27:12 -0300 Subject: [PATCH 5/5] Update expected message --- tests/test_esss_fix_format.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_esss_fix_format.py b/tests/test_esss_fix_format.py index 40765c9..9527383 100644 --- a/tests/test_esss_fix_format.py +++ b/tests/test_esss_fix_format.py @@ -407,9 +407,10 @@ def test_missing_clang_format(tmpdir, mocker, dot_clang_format_to_tmpdir): expected_command = 'clang-format -i "main.cpp"' expected_error_code = 1 - expected_error_message = "Command '%s' returned non-zero exit status 1" % expected_command - if sys.version_info.major == 2: - expected_error_message += '.' + + # The '*' is used to indicate that there may be a '.' in + # the message depending on the python version + expected_error_message = "Command '%s' returned non-zero exit status 1*" % expected_command message_extra_details = 'Please check if "clang-format" is installed and accessible' mocker.patch.object(