diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 4fc1b5e61..ee8767acb 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -73,6 +73,9 @@ let rec expand_message_string message an = expand_message_string message' an with Not_found -> message +let remove_new_lines message = + String.substr_replace_all ~pattern:"\n" ~with_:" " message + let string_to_err_kind = function | "WARNING" -> Exceptions.Kwarning | "ERROR" -> Exceptions.Kerror @@ -206,7 +209,8 @@ let get_current_method context (an : Ctl_parser_types.ast_node) = | _ -> context.CLintersContext.current_method let fill_issue_desc_info_and_log context an key issue_desc loc = - let desc = expand_message_string issue_desc.CIssue.description an in + let desc = remove_new_lines + (expand_message_string issue_desc.CIssue.description an) in let issue_desc' = {issue_desc with CIssue.description = desc; CIssue.loc = loc } in log_frontend_issue context.CLintersContext.translation_unit_context diff --git a/infer/src/clang/cFrontend_errors.mli b/infer/src/clang/cFrontend_errors.mli index d0312b908..6401158df 100644 --- a/infer/src/clang/cFrontend_errors.mli +++ b/infer/src/clang/cFrontend_errors.mli @@ -19,3 +19,5 @@ val expand_checkers : CTL.ctl_checker list -> CTL.ctl_checker list val make_condition_issue_desc_pair : CTL.ctl_checker list -> unit + +val remove_new_lines : string -> string diff --git a/infer/src/unit/clang/CFrontend_errorsTests.ml b/infer/src/unit/clang/CFrontend_errorsTests.ml new file mode 100644 index 000000000..21c82fecd --- /dev/null +++ b/infer/src/unit/clang/CFrontend_errorsTests.ml @@ -0,0 +1,31 @@ +(* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) + +open! IStd +open OUnit2 + +let test_correct_removing_new_lines = + let pp_diff_of_desc fmt (expected, actual) = + Format.fprintf fmt "Expected: [%s] Found: [%s]" expected actual in + let create_test (desc : string) (expected_desc : string) _ = + let output = CFrontend_errors.remove_new_lines desc in + let cmp = fun s1 s2 -> String.equal s1 s2 in + assert_equal ~pp_diff:pp_diff_of_desc ~cmp expected_desc output in + [ + ( + "test_correct_removing_new_lines", + "The selector m is not available in the required iOS SDK version\n8.0", + "The selector m is not available in the required iOS SDK version 8.0" + ); + ] + |> List.map + ~f:(fun (name, test_input, expected_output) -> + name >:: create_test test_input expected_output) + +let tests = "cfrontend_errors_suite" >::: test_correct_removing_new_lines diff --git a/infer/src/unit/clang/ClangTests.ml b/infer/src/unit/clang/ClangTests.ml index 73c2871e9..e350dde14 100644 --- a/infer/src/unit/clang/ClangTests.ml +++ b/infer/src/unit/clang/ClangTests.ml @@ -11,4 +11,5 @@ open! IStd let tests = [ CiOSVersionNumbersTests.tests; QualifiedCppNameTests.tests; + CFrontend_errorsTests.tests; ]