From c2efbd38c877c7258e90ff55f8fd16a91ffbb400 Mon Sep 17 00:00:00 2001 From: Craig Date: Tue, 21 May 2024 08:56:20 -0700 Subject: [PATCH 01/20] Add plural rules to CPP --- executors/cpp/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/executors/cpp/main.cpp b/executors/cpp/main.cpp index de3ff528..60d81cb8 100644 --- a/executors/cpp/main.cpp +++ b/executors/cpp/main.cpp @@ -45,14 +45,16 @@ extern const string test_langnames(json_object *json_in); extern const string test_likely_subtags(json_object *json_in); extern const string test_list_fmt(json_object *json_in); extern const string test_numfmt(json_object *json_in); +extern const string TestPluralRules(json_object *json_in); -std::string supported_tests[6] = { +std::string supported_tests[7] = { "collation_short", "datetime_fmt", "likely_subtags", "list_fmt", "lang_names", - "number_fmt" + "number_fmt", + "plural_rules" }; @@ -120,6 +122,9 @@ int main(int argc, const char** argv) else if (test_type == "lang_names") { outputLine = test_langnames(json_input); } + else if (test_type == "plural_rules") { + outputLine = TestPluralRules(json_input); + } else { outputLine = "# BAD TEST " + test_type; // "{\"error\": \"unknown test type\"," + From d790a5d17041e00573b32b3c1bb26c3ce60c6006 Mon Sep 17 00:00:00 2001 From: Craig Date: Tue, 28 May 2024 16:59:35 -0700 Subject: [PATCH 02/20] Clang-tidy applied to *.cpp --- executors/cpp/coll.cpp | 30 ++++------- executors/cpp/datetime_fmt.cpp | 11 +--- executors/cpp/langnames.cpp | 9 +--- executors/cpp/likely_subtags.cpp | 26 ++++----- executors/cpp/list_fmt.cpp | 12 ++--- executors/cpp/number_fmt.cpp | 90 +++++++++++++------------------- executors/cpp/plural_rules.cpp | 11 ++-- 7 files changed, 64 insertions(+), 125 deletions(-) diff --git a/executors/cpp/coll.cpp b/executors/cpp/coll.cpp index 37718d1a..a85e42b2 100644 --- a/executors/cpp/coll.cpp +++ b/executors/cpp/coll.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -132,8 +133,7 @@ const string TestCollator(json_object *json_in) { if (rules_string != "") { char uni_rules_out[1000] = ""; - int32_t rule_chars_out = - uni_rules.extract(uni_rules_out, 1000, nullptr, status); + uni_rules.extract(uni_rules_out, 1000, nullptr, status); // ignore length // Make sure normalization is consistent rb_coll = new RuleBasedCollator(uni_rules, UCOL_ON, status); @@ -165,10 +165,9 @@ const string TestCollator(json_object *json_in) { delete rb_coll; } else { // Not a rule-based collator. - if (locale_string == "") { + if (strlen(locale_string) <= 0) { uni_coll = Collator::createInstance(status); } else { - cout << "# Locale set to " << locale_string << endl; uni_coll = Collator::createInstance(Locale(locale_string), status); } @@ -219,20 +218,10 @@ const string TestCollator(json_object *json_in) { } // Just to check the result. - UColAttributeValue alternate_value = - uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); + uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore return - // Try two differen APIs - uni_result_utf8 = uni_coll->compareUTF8(string1, string2, status); - // This one seems to work better. + // Perform the string comparison uni_result = uni_coll->compare(us1, us2, status); - - if (uni_result != uni_result_utf8) { - cout << "# UNI_COLL COMPARE Unicode String " << uni_result << " "; - cout << "# UNI_COLL COMPARE UTF8 String " << uni_result_utf8 << endl; - cout << "# ******* results different in " << label_string << endl; - } - if (U_FAILURE(status)) { json_object_object_add( return_json, @@ -243,8 +232,7 @@ const string TestCollator(json_object *json_in) { error_message << endl; } if (uni_coll) { - UColAttributeValue alternate_value = - uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); + uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore result } delete uni_coll; } @@ -259,7 +247,7 @@ const string TestCollator(json_object *json_in) { // Check unescaped versions. char char_out1[1000] = ""; char char_out2[1000] = ""; - int32_t chars_out = us1.extract(char_out1, 1000, nullptr, status); + us1.extract(char_out1, 1000, nullptr, status); // ignore result if (U_FAILURE(status)) { test_result = error_message; json_object_object_add( @@ -270,7 +258,7 @@ const string TestCollator(json_object *json_in) { test_result << endl; } - int32_t chars_out2 = us2.extract(char_out2, 1000, nullptr, status); + us2.extract(char_out2, 1000, nullptr, status); // ignore result if (U_FAILURE(status)) { test_result = error_message; // TODO: report the error in creating the instance @@ -289,7 +277,7 @@ const string TestCollator(json_object *json_in) { json_object_object_add( return_json, "s2", json_object_new_string(string2.c_str())); - // What was the actual returned value? + // Record the actual returned value json_object_object_add( return_json, "compare", json_object_new_int64(uni_result)); } else { diff --git a/executors/cpp/datetime_fmt.cpp b/executors/cpp/datetime_fmt.cpp index 2fc5a4cc..9c3c9744 100644 --- a/executors/cpp/datetime_fmt.cpp +++ b/executors/cpp/datetime_fmt.cpp @@ -1,9 +1,5 @@ /******************************************************************** - * Comments and license as needed - ************************************ - -/****** - * testing datetime format + * testing icu4c datetime format */ #include @@ -251,11 +247,8 @@ const string TestDatetimeFmt(json_object *json_in) { df->format(test_date_time, formatted_result); // Get the resulting value as a string - string test_result; - int32_t chars_out; // Extracted characters from Unicode string char test_result_string[1000] = ""; - chars_out = formatted_result.extract( - test_result_string, 1000, nullptr, status); + formatted_result.extract(test_result_string, 1000, nullptr, status); // ignore return value if (U_FAILURE(status)) { json_object_object_add( diff --git a/executors/cpp/langnames.cpp b/executors/cpp/langnames.cpp index 80fa1bd0..38cdff6c 100644 --- a/executors/cpp/langnames.cpp +++ b/executors/cpp/langnames.cpp @@ -1,9 +1,5 @@ /******************************************************************** - * Comments and license as needed - ************************************ - -/****** - * testing language display names + * testing icu4c for language display names */ #include @@ -60,8 +56,7 @@ const string TestLangNames (json_object *json_in) { char test_result_string[1000] = ""; - int32_t chars_out = testLang.extract( - test_result_string, 1000, nullptr, status); + testLang.extract(test_result_string, 1000, nullptr, status); // ignore return if (U_FAILURE(status)) { json_object_object_add( return_json, diff --git a/executors/cpp/likely_subtags.cpp b/executors/cpp/likely_subtags.cpp index bfbe59f7..1ca09766 100644 --- a/executors/cpp/likely_subtags.cpp +++ b/executors/cpp/likely_subtags.cpp @@ -39,11 +39,7 @@ const string TestLikelySubtags(json_object *json_in) { Locale displayLocale(locale_string.c_str()); - const char* test_result; - const string error_message_max = "error in maximize"; - const string error_message_min = "error in minimize"; - const string protected_msg = "This ICU4C API is protected"; - const char* empty_result = ""; + string test_result = ""; json_object *return_json = json_object_new_object(); json_object_object_add(return_json, "label", label_obj); @@ -52,17 +48,13 @@ const string TestLikelySubtags(json_object *json_in) { string name_string; StringByteSink byteSink(&name_string); - // If needed. - json_object *error_msg = json_object_new_object(); - - test_result = empty_result; if (option_string == "maximize") { // This makes the maximized form Locale maximized(displayLocale); maximized.addLikelySubtags(status); if (U_FAILURE(status)) { - test_result = error_message_max.c_str(); + test_result = "error in maximize"; } else { maximized.toLanguageTag(byteSink, status); @@ -72,17 +64,18 @@ const string TestLikelySubtags(json_object *json_in) { "error", json_object_new_string("toLanguageTag")); } - test_result = name_string.c_str(); + test_result = name_string; } } else if (option_string == "minimize" || option_string == "minimizeFavorRegion") { // Minimize displayLocale.minimizeSubtags(status); if (U_FAILURE(status)) { - test_result = error_message_min.c_str(); + const string error_message_min = "error in minimize"; + test_result = error_message_min; } else { displayLocale.toLanguageTag(byteSink, status); - test_result = name_string.c_str(); + test_result = name_string; if (U_FAILURE(status)) { json_object_object_add( @@ -105,7 +98,8 @@ const string TestLikelySubtags(json_object *json_in) { json_object_new_string(option_string.c_str())); json_object_object_add(return_json, "error_detail", - json_object_new_string(protected_msg.c_str())); + json_object_new_string("This ICU4C API is protected")); + // This is a protected API in ICU4C. // displayLocale.minimizeSubtags(favorScript, status); } else { @@ -123,12 +117,12 @@ const string TestLikelySubtags(json_object *json_in) { if (U_FAILURE(status)) { json_object_object_add(return_json, "error", - json_object_new_string(test_result)); + json_object_new_string(test_result.c_str())); } else { // The output of the likely subtag operation. json_object_object_add(return_json, "result", - json_object_new_string(test_result)); + json_object_new_string(test_result.c_str())); } return json_object_to_json_string(return_json); diff --git a/executors/cpp/list_fmt.cpp b/executors/cpp/list_fmt.cpp index a1fbe09c..7c54d31b 100644 --- a/executors/cpp/list_fmt.cpp +++ b/executors/cpp/list_fmt.cpp @@ -1,9 +1,5 @@ /******************************************************************** - * Comments and license as needed - ************************************ - -/****** - * testing list formatting + * testing list formatting in icu4c */ #include @@ -51,7 +47,6 @@ const string TestListFmt (json_object* json_in) { std::vector u_strings; int u_strings_size = 0; if (input_list_obj) { - struct array_list* input_list_array = json_object_get_array(input_list_obj); int input_length = json_object_array_length(input_list_obj); // Construct the list of Unicode Strings @@ -61,7 +56,7 @@ const string TestListFmt (json_object* json_in) { string item_string = json_object_get_string(item); u_strings.push_back(item_string.c_str()); } - u_strings_size = u_strings_size = u_strings.size(); + u_strings_size = u_strings.size(); } else { json_object_object_add( return_json, @@ -121,8 +116,7 @@ const string TestListFmt (json_object* json_in) { "error", json_object_new_string("calling list format")); } else { - int32_t chars_out = - u_result_string.extract(test_result_string, 1000, nullptr, status); + u_result_string.extract(test_result_string, 1000, nullptr, status); // result ignored } if (U_FAILURE(status)) { diff --git a/executors/cpp/number_fmt.cpp b/executors/cpp/number_fmt.cpp index f7cc036c..6b1b4cb7 100644 --- a/executors/cpp/number_fmt.cpp +++ b/executors/cpp/number_fmt.cpp @@ -1,10 +1,7 @@ /******************************************************************** - * Comments and license as needed - ************************************ - -/****** - * testing number format + * testing icu4c number format */ + #include #include @@ -56,8 +53,6 @@ using icu::number::Notation; using icu::number::Precision; using icu::number::Scale; -const char error_message[] = "error"; - // Get the integer value of a settting int16_t get_integer_setting(string key_value_string) { int16_t return_val = -1; @@ -215,7 +210,6 @@ const string TestNumfmt(json_object *json_in) { // Other parts of the input. json_object *options_obj = json_object_object_get(json_in, "options"); json_object *skeleton_obj = json_object_object_get(json_in, "skeleton"); - json_object *pattern_obj = json_object_object_get(json_in, "pattern"); // The locale for numbers json_object *locale_label_obj = json_object_object_get(json_in, "locale"); @@ -226,15 +220,6 @@ const string TestNumfmt(json_object *json_in) { const Locale displayLocale(locale_string.c_str()); - // Try using the skeleton to create the formatter - json_object *skelecton_obj = json_object_object_get(json_in, "skeleton"); - UnicodeString unicode_skeleton_string; - string skeleton_string; - if (skeleton_obj) { - skeleton_string = json_object_get_string(skeleton_obj); - unicode_skeleton_string = skeleton_string.c_str(); - } - // Get options json_object *notation_obj; json_object *unit_obj; @@ -339,7 +324,7 @@ const string TestNumfmt(json_object *json_in) { string currencyDisplay_string = json_object_get_string(currencyDisplay_obj); unit_width_setting = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; - if (currencyDisplay_string == "narrowSymbol") { + if (currencyDisplay_string == "narrowSymbol") { unit_width_setting = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; } else if (currencyDisplay_string == "symbol") { unit_width_setting = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT; @@ -441,12 +426,7 @@ const string TestNumfmt(json_object *json_in) { int32_t chars_out; // Results of extracting characters from Unicode string bool no_error = true; - char test_result_string[1000] = ""; - - string test_result; - - // Get the numeric value - double input_double = std::stod(input_string); + char test_result[1000] = ""; LocalizedNumberFormatter nf; if (notation_string == "scientific") { @@ -468,35 +448,38 @@ const string TestNumfmt(json_object *json_in) { } if (skeleton_obj) { - // If present, use the skeleton + // Use the skeleton provided + UnicodeString unicode_skeleton_string; + string skeleton_string = json_object_get_string(skeleton_obj); + unicode_skeleton_string = skeleton_string.c_str(); + nf = NumberFormatter::forSkeleton( unicode_skeleton_string, status).locale(displayLocale); } else { - // Use settings to initialize the formatter - nf = NumberFormatter::withLocale(displayLocale) - .notation(notation_setting) - .decimal(separator_setting) - .precision(precision_setting) - .integerWidth(integerWidth_setting) - .grouping(grouping_setting) - .adoptSymbols(numbering_system) - .roundingMode(rounding_setting) - .scale(scale_setting) - .sign(signDisplay_setting) - .unit(unit_setting) - .unitWidth(unit_width_setting); + // Use settings to initialize the formatter + nf = NumberFormatter::withLocale(displayLocale) + .notation(notation_setting) + .decimal(separator_setting) + .precision(precision_setting) + .integerWidth(integerWidth_setting) + .grouping(grouping_setting) + .adoptSymbols(numbering_system) + .roundingMode(rounding_setting) + .scale(scale_setting) + .sign(signDisplay_setting) + .unit(unit_setting) + .unitWidth(unit_width_setting); } if (U_FAILURE(status)) { - test_result = error_message; - const char* error_name = u_errorName(status); - json_object_object_add( - return_json, - "error", json_object_new_string("error in constructor")); - json_object_object_add( - return_json, - "error_detail", json_object_new_string(error_name)); - no_error = false; + const char* error_name = u_errorName(status); + json_object_object_add( + return_json, + "error", json_object_new_string("error in constructor")); + json_object_object_add( + return_json, + "error_detail", json_object_new_string(error_name)); + no_error = false; } if (no_error) { @@ -512,13 +495,10 @@ const string TestNumfmt(json_object *json_in) { json_object_object_add( return_json, "error_detail", json_object_new_string(error_name)); - no_error = false; } // Get the resulting value as a string - chars_out = number_result.extract( - test_result_string, 1000, nullptr, status); - test_result = test_result_string; + number_result.extract(test_result, 1000, nullptr, status); // ignore result if (U_FAILURE(status)) { // Report a failure @@ -528,20 +508,20 @@ const string TestNumfmt(json_object *json_in) { json_object_new_string("error in string extract")); json_object_object_add( return_json, "error_detail", json_object_new_string(error_name)); - no_error = false; } else { // It worked! json_object_object_add(return_json, "result", - json_object_new_string(test_result.c_str())); + json_object_new_string(test_result)); } } + // To see what was actually used. UnicodeString u_skeleton_out = nf.toSkeleton(status); - chars_out = u_skeleton_out.extract(test_result_string, 1000, nullptr, status); + u_skeleton_out.extract(test_result, 1000, nullptr, status); // result ignored json_object_object_add(return_json, "actual_skeleton", - json_object_new_string(test_result_string)); + json_object_new_string(test_result)); string return_string = json_object_to_json_string(return_json); return return_string; diff --git a/executors/cpp/plural_rules.cpp b/executors/cpp/plural_rules.cpp index dbd2f1d1..f3803a34 100644 --- a/executors/cpp/plural_rules.cpp +++ b/executors/cpp/plural_rules.cpp @@ -1,10 +1,6 @@ /******************************************************************** - * Comments and license as needed - ************************************ - -/****** - * testing plural rules - * Based on code of ICU4C testing: + * testing plural rules in icu4c + * * https://github.com/unicode-org/icu/blob/maint/maint-75/icu4c/source/test/intltest/plurfmts.cpp */ @@ -137,8 +133,7 @@ const string TestPluralRules (json_object* json_in) { json_object_new_string("calling plural rules select")); return json_object_to_json_string(return_json); } else { - int32_t chars_out = - u_result.extract(test_result_string, 1000, nullptr, status); + u_result.extract(test_result_string, 1000, nullptr, status); // ignore result } if (U_FAILURE(status)) { From 756fdb6faae10ec12a175d5576a1721f5631ffb0 Mon Sep 17 00:00:00 2001 From: Craig Date: Tue, 28 May 2024 17:24:43 -0700 Subject: [PATCH 03/20] More style fixes --- executors/cpp/coll.cpp | 2 +- executors/cpp/datetime_fmt.cpp | 3 ++- executors/cpp/likely_subtags.cpp | 42 ++++++++++++++++++-------------- executors/cpp/list_fmt.cpp | 9 ++++--- executors/cpp/plural_rules.cpp | 13 ++++++---- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/executors/cpp/coll.cpp b/executors/cpp/coll.cpp index a85e42b2..f9f59e54 100644 --- a/executors/cpp/coll.cpp +++ b/executors/cpp/coll.cpp @@ -218,7 +218,7 @@ const string TestCollator(json_object *json_in) { } // Just to check the result. - uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore return + uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore return // Perform the string comparison uni_result = uni_coll->compare(us1, us2, status); diff --git a/executors/cpp/datetime_fmt.cpp b/executors/cpp/datetime_fmt.cpp index 9c3c9744..6179d242 100644 --- a/executors/cpp/datetime_fmt.cpp +++ b/executors/cpp/datetime_fmt.cpp @@ -248,7 +248,8 @@ const string TestDatetimeFmt(json_object *json_in) { // Get the resulting value as a string char test_result_string[1000] = ""; - formatted_result.extract(test_result_string, 1000, nullptr, status); // ignore return value + formatted_result.extract( + test_result_string, 1000, nullptr, status); // ignore return value if (U_FAILURE(status)) { json_object_object_add( diff --git a/executors/cpp/likely_subtags.cpp b/executors/cpp/likely_subtags.cpp index 1ca09766..85db2fac 100644 --- a/executors/cpp/likely_subtags.cpp +++ b/executors/cpp/likely_subtags.cpp @@ -87,18 +87,22 @@ const string TestLikelySubtags(json_object *json_in) { } else if (option_string == "minimizeFavorScript") { // Minimize with script preferred. bool favorScript = true; - json_object_object_add(return_json, - "error", - json_object_new_string("unsupported option")); - json_object_object_add(return_json, - "error_type", - json_object_new_string("unsupported")); - json_object_object_add(return_json, - "unsupported", - json_object_new_string(option_string.c_str())); - json_object_object_add(return_json, - "error_detail", - json_object_new_string("This ICU4C API is protected")); + json_object_object_add( + return_json, + "error", + json_object_new_string("unsupported option")); + json_object_object_add( + return_json, + "error_type", + json_object_new_string("unsupported")); + json_object_object_add( + return_json, + "unsupported", + json_object_new_string(option_string.c_str())); + json_object_object_add( + return_json, + "error_detail", + json_object_new_string("This ICU4C API is protected")); // This is a protected API in ICU4C. // displayLocale.minimizeSubtags(favorScript, status); @@ -115,14 +119,16 @@ const string TestLikelySubtags(json_object *json_in) { } if (U_FAILURE(status)) { - json_object_object_add(return_json, - "error", - json_object_new_string(test_result.c_str())); + json_object_object_add( + return_json, + "error", + json_object_new_string(test_result.c_str())); } else { // The output of the likely subtag operation. - json_object_object_add(return_json, - "result", - json_object_new_string(test_result.c_str())); + json_object_object_add( + return_json, + "result", + json_object_new_string(test_result.c_str())); } return json_object_to_json_string(return_json); diff --git a/executors/cpp/list_fmt.cpp b/executors/cpp/list_fmt.cpp index 7c54d31b..ece56fbe 100644 --- a/executors/cpp/list_fmt.cpp +++ b/executors/cpp/list_fmt.cpp @@ -105,9 +105,9 @@ const string TestListFmt (json_object* json_in) { UnicodeString *u_array = &u_strings[0]; UnicodeString u_result_string; u_result_string = list_formatter->format(u_array, - u_strings_size, - u_result_string, - status); + u_strings_size, + u_result_string, + status); char test_result_string[1000] = ""; if (U_FAILURE(status)) { @@ -116,7 +116,8 @@ const string TestListFmt (json_object* json_in) { "error", json_object_new_string("calling list format")); } else { - u_result_string.extract(test_result_string, 1000, nullptr, status); // result ignored + u_result_string.extract( + test_result_string, 1000, nullptr, status); // result ignored } if (U_FAILURE(status)) { diff --git a/executors/cpp/plural_rules.cpp b/executors/cpp/plural_rules.cpp index f3803a34..33cb5829 100644 --- a/executors/cpp/plural_rules.cpp +++ b/executors/cpp/plural_rules.cpp @@ -56,8 +56,9 @@ const string TestPluralRules (json_object* json_in) { string sample_string = json_object_get_string(sample_obj); if (sample_string.find('c') != std::string::npos) { - + // TODO: Handle compact numbers } + if (sample_string.find('.') != std::string::npos) { // Convert into an integer, decimal, or compact decimal input_double_sample = std::stod(sample_string); @@ -133,7 +134,8 @@ const string TestPluralRules (json_object* json_in) { json_object_new_string("calling plural rules select")); return json_object_to_json_string(return_json); } else { - u_result.extract(test_result_string, 1000, nullptr, status); // ignore result + u_result.extract( + test_result_string, 1000, nullptr, status); // ignore result } if (U_FAILURE(status)) { @@ -144,9 +146,10 @@ const string TestPluralRules (json_object* json_in) { return json_object_to_json_string(return_json); } else { // It all seems to work! - json_object_object_add(return_json, - "result", - json_object_new_string(test_result_string)); + json_object_object_add( + return_json, + "result", + json_object_new_string(test_result_string)); } // The JSON output. From 16a3cb3b3d85408777334af9ebe36f30d6cf4b4b Mon Sep 17 00:00:00 2001 From: Craig Date: Thu, 10 Oct 2024 09:15:03 -0700 Subject: [PATCH 04/20] DDT-234 Apply clang-tidy to *.cpp --- executors/cpp/coll.cpp | 22 +++--- executors/cpp/datetime_fmt.cpp | 50 +++++++------- executors/cpp/likely_subtags.cpp | 16 ++--- executors/cpp/list_fmt.cpp | 34 ++++++---- executors/cpp/localedisplaynames.cpp | 4 +- executors/cpp/main.cpp | 2 +- executors/cpp/number_fmt.cpp | 92 +++++++++++++------------- executors/cpp/plural_rules.cpp | 8 +-- executors/cpp/relativedatetime_fmt.cpp | 35 +++++----- executors/cpp/util.cpp | 6 +- 10 files changed, 141 insertions(+), 128 deletions(-) diff --git a/executors/cpp/coll.cpp b/executors/cpp/coll.cpp index 86d3dbd7..576b914a 100644 --- a/executors/cpp/coll.cpp +++ b/executors/cpp/coll.cpp @@ -45,7 +45,7 @@ const char error_message[] = "error"; /** * TestCollator -- process JSON inputs, run comparator, return result */ -const string TestCollator(json_object *json_in) { +string TestCollator(json_object *json_in) { UErrorCode status = U_ZERO_ERROR; json_object *label_obj = json_object_object_get(json_in, "label"); @@ -66,7 +66,7 @@ const string TestCollator(json_object *json_in) { json_object *locale_obj = json_object_object_get(json_in, "locale"); const char *locale_string; - if (locale_obj) { + if (locale_obj != nullptr) { locale_string = json_object_get_string(locale_obj); } else { locale_string = "und"; @@ -76,7 +76,7 @@ const string TestCollator(json_object *json_in) { json_object *compare_type_obj = json_object_object_get(json_in, "compare_type"); string compare_type_string = ""; - if (compare_type_obj) { + if (compare_type_obj != nullptr) { compare_type_string = json_object_get_string(compare_type_obj); } @@ -85,7 +85,7 @@ const string TestCollator(json_object *json_in) { string strength_string = ""; json_object *strength_obj = json_object_object_get(json_in, "strength"); - if (strength_obj) { + if (strength_obj != nullptr) { strength_string = json_object_get_string(strength_obj); if (strength_string == "primary") { strength_type = Collator::PRIMARY; @@ -103,14 +103,14 @@ const string TestCollator(json_object *json_in) { // Check for rule-based collation json_object *rules_obj = json_object_object_get(json_in, "rules"); string rules_string = ""; - if (rules_obj) { + if (rules_obj != nullptr) { rules_string = json_object_get_string(rules_obj); } UnicodeString uni_rules = UnicodeString::fromUTF8(rules_string); // Allow for different levels or types of comparison. json_object *compare_type = json_object_object_get(json_in, "compare_type"); - if (compare_type) { + if (compare_type != nullptr) { // TODO: Apply this in tests. const char *comparison_type = json_object_get_string(compare_type); } @@ -170,12 +170,12 @@ const string TestCollator(json_object *json_in) { return json_object_to_json_string(return_json); } - if (strength_obj) { + if (strength_obj != nullptr) { uni_coll->setStrength(strength_type); } - if (ignore_obj) { - const bool ignore_punctuation_bool = json_object_get_boolean(ignore_obj); + if (ignore_obj != nullptr) { + const bool ignore_punctuation_bool = json_object_get_boolean(ignore_obj) != 0; if (ignore_punctuation_bool) { uni_coll->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status); if (check_icu_error( @@ -200,7 +200,7 @@ const string TestCollator(json_object *json_in) { return json_object_to_json_string(return_json); } - if (uni_coll) { + if (uni_coll != nullptr) { uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore result } delete uni_coll; @@ -224,7 +224,7 @@ const string TestCollator(json_object *json_in) { } json_object_object_add( - return_json, "result", json_object_new_boolean(coll_result)); + return_json, "result", json_object_new_boolean(static_cast(coll_result))); return json_object_to_json_string(return_json); } diff --git a/executors/cpp/datetime_fmt.cpp b/executors/cpp/datetime_fmt.cpp index acd72e84..494cb67b 100644 --- a/executors/cpp/datetime_fmt.cpp +++ b/executors/cpp/datetime_fmt.cpp @@ -4,8 +4,8 @@ #include -#include -#include +#include +#include #include #include @@ -33,15 +33,19 @@ using std::cout; using std::endl; using std::string; -icu::DateFormat::EStyle StringToEStyle(string style_string) { - if (style_string == "full") return icu::DateFormat::kFull; - if (style_string == "long") return icu::DateFormat::kLong; - if (style_string == "medium") return icu::DateFormat::kMedium; - if (style_string == "short") return icu::DateFormat::kShort; +auto StringToEStyle(string style_string) -> icu::DateFormat::EStyle { + if (style_string == "full") { return icu::DateFormat::kFull; +} + if (style_string == "long") { return icu::DateFormat::kLong; +} + if (style_string == "medium") { return icu::DateFormat::kMedium; +} + if (style_string == "short") { return icu::DateFormat::kShort; +} return icu::DateFormat::kNone; } -const string TestDatetimeFmt(json_object *json_in) { +string TestDatetimeFmt(json_object *json_in) { UErrorCode status = U_ZERO_ERROR; json_object *label_obj = json_object_object_get(json_in, "label"); @@ -55,7 +59,7 @@ const string TestDatetimeFmt(json_object *json_in) { // The locale for formatted output json_object *locale_label_obj = json_object_object_get(json_in, "locale"); string locale_string; - if (locale_label_obj) { + if (locale_label_obj != nullptr) { locale_string = json_object_get_string(locale_label_obj); } else { locale_string = "und"; @@ -72,11 +76,11 @@ const string TestDatetimeFmt(json_object *json_in) { // Get fields out of the options if present json_object* options_obj = json_object_object_get(json_in, "options"); - if (options_obj) { + if (options_obj != nullptr) { // Check for timezone and calendar json_object* option_item = json_object_object_get(options_obj, "timeZone"); - if (option_item) { + if (option_item != nullptr) { string timezone_str = json_object_get_string(option_item); UnicodeString u_tz(timezone_str.c_str()); tz = TimeZone::createTimeZone(u_tz); @@ -84,7 +88,7 @@ const string TestDatetimeFmt(json_object *json_in) { json_object* cal_item = json_object_object_get(options_obj, "calendar"); - if (cal_item) { + if (cal_item != nullptr) { calendar_str = json_object_get_string(cal_item); } } @@ -93,12 +97,12 @@ const string TestDatetimeFmt(json_object *json_in) { locale_string = locale_string + "@calendar=" + calendar_str; display_locale = locale_string.c_str(); - if (tz) { + if (tz != nullptr) { cal = Calendar::createInstance(tz, display_locale, status); } else { cal = Calendar::createInstance(display_locale, status); } - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { json_object_object_add( return_json, "error", @@ -125,15 +129,15 @@ const string TestDatetimeFmt(json_object *json_in) { // skeleton or date_style. string default_skeleton_string = "M/d/yyyy"; - if (options_obj) { + if (options_obj != nullptr) { json_object* option_item = json_object_object_get(options_obj, "dateStyle"); - if (option_item) { + if (option_item != nullptr) { dateStyle_str = json_object_get_string(option_item); date_style = StringToEStyle(dateStyle_str); } option_item = json_object_object_get(options_obj, "timeStyle"); - if (option_item) { + if (option_item != nullptr) { timeStyle_str = json_object_get_string(option_item); time_style = StringToEStyle(timeStyle_str); } @@ -146,13 +150,13 @@ const string TestDatetimeFmt(json_object *json_in) { time_style == icu::DateFormat::EStyle::kNone) { skeleton_string = default_skeleton_string; } - if (date_skeleton_obj) { + if (date_skeleton_obj != nullptr) { // Data specifies a date time skeleton. Make a formatter based on this. skeleton_string = json_object_get_string(date_skeleton_obj); } if (skeleton_string != "") { UnicodeString u_skeleton(skeleton_string.c_str()); - if (cal) { + if (cal != nullptr) { df = DateFormat::createInstanceForSkeleton(cal, u_skeleton, display_locale, @@ -183,7 +187,7 @@ const string TestDatetimeFmt(json_object *json_in) { } // !!! IS OFFSET ALREADY CONSIDERED? - if (tz) { + if (tz != nullptr) { df->setTimeZone(*tz); } @@ -194,7 +198,7 @@ const string TestDatetimeFmt(json_object *json_in) { json_object *input_millis = json_object_object_get(json_in, "input_millis"); UDate test_date_time; - if (input_string_obj) { + if (input_string_obj != nullptr) { Locale und_locale("und"); string input_date_string = json_object_get_string(input_string_obj); @@ -219,7 +223,7 @@ const string TestDatetimeFmt(json_object *json_in) { // TODO: handles the offset +/- SimpleDateFormat iso_date_fmt(u"y-M-d'T'h:m:sZ", und_locale, status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { string error_name = u_errorName(status); string error_message = "# iso_date_fmt constructor failure: " + @@ -240,7 +244,7 @@ const string TestDatetimeFmt(json_object *json_in) { "# iso_date_fmt parse failure" + input_date_string)) { return json_object_to_json_string(return_json); } - } else if (input_millis) { + } else if (input_millis != nullptr) { test_date_time = json_object_get_double(input_millis); } else { json_object_object_add( diff --git a/executors/cpp/likely_subtags.cpp b/executors/cpp/likely_subtags.cpp index 5cda131e..f2f770ea 100644 --- a/executors/cpp/likely_subtags.cpp +++ b/executors/cpp/likely_subtags.cpp @@ -10,8 +10,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -25,7 +25,7 @@ using icu::Locale; using icu::StringByteSink; using icu::UnicodeString; -const string TestLikelySubtags(json_object *json_in) { +string TestLikelySubtags(json_object *json_in) { UErrorCode status = U_ZERO_ERROR; json_object *label_obj = json_object_object_get(json_in, "label"); @@ -55,12 +55,12 @@ const string TestLikelySubtags(json_object *json_in) { Locale maximized(displayLocale); maximized.addLikelySubtags(status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { test_result = "error in maximize"; } else { maximized.toLanguageTag(byteSink, status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { json_object_object_add( return_json, "error", @@ -72,14 +72,14 @@ const string TestLikelySubtags(json_object *json_in) { option_string == "minimizeFavorRegion") { // Minimize displayLocale.minimizeSubtags(status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { const string error_message_min = "error in minimize"; test_result = error_message_min; } else { displayLocale.toLanguageTag(byteSink, status); test_result = name_string; - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { json_object_object_add( return_json, "error", @@ -120,7 +120,7 @@ const string TestLikelySubtags(json_object *json_in) { json_object_new_string(option_string.c_str())); } - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { json_object_object_add( return_json, "error", diff --git a/executors/cpp/list_fmt.cpp b/executors/cpp/list_fmt.cpp index 99913f41..3d2ccb5c 100644 --- a/executors/cpp/list_fmt.cpp +++ b/executors/cpp/list_fmt.cpp @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -29,7 +29,7 @@ using std::endl; using std::string; /* Main test function */ -const string TestListFmt (json_object* json_in) { +string TestListFmt (json_object* json_in) { UErrorCode status = U_ZERO_ERROR; json_object* label_obj = json_object_object_get(json_in, "label"); @@ -38,7 +38,7 @@ const string TestListFmt (json_object* json_in) { // The locale in which the name is given. string locale_string = "und"; json_object* locale_label_obj = json_object_object_get(json_in, "locale"); - if (locale_label_obj) { + if (locale_label_obj != nullptr) { locale_string = json_object_get_string(locale_label_obj); } Locale displayLocale(locale_string.c_str()); @@ -51,7 +51,7 @@ const string TestListFmt (json_object* json_in) { std::vector u_strings; int u_strings_size = 0; - if (input_list_obj) { + if (input_list_obj != nullptr) { int input_length = json_object_array_length(input_list_obj); // Construct the list of Unicode Strings @@ -78,22 +78,28 @@ const string TestListFmt (json_object* json_in) { UListFormatterType format_type = ULISTFMT_TYPE_AND; UListFormatterWidth format_width = ULISTFMT_WIDTH_WIDE; - if (option_list_obj) { + if (option_list_obj != nullptr) { json_object* style_obj = json_object_object_get( option_list_obj, "style"); - if (style_obj) { + if (style_obj != nullptr) { style_string = json_object_get_string(style_obj); - if (style_string == "long") format_width = ULISTFMT_WIDTH_WIDE; - if (style_string == "short") format_width = ULISTFMT_WIDTH_SHORT; - if (style_string == "narrow") format_width = ULISTFMT_WIDTH_NARROW; + if (style_string == "long") { format_width = ULISTFMT_WIDTH_WIDE; +} + if (style_string == "short") { format_width = ULISTFMT_WIDTH_SHORT; +} + if (style_string == "narrow") { format_width = ULISTFMT_WIDTH_NARROW; +} } json_object* type_obj = json_object_object_get( option_list_obj, "type"); - if (type_obj) { + if (type_obj != nullptr) { type_string = json_object_get_string(type_obj); - if (type_string == "conjunction") format_type = ULISTFMT_TYPE_AND; - if (type_string == "disjunction") format_type = ULISTFMT_TYPE_OR; - if (type_string == "unit") format_type = ULISTFMT_TYPE_UNITS; + if (type_string == "conjunction") { format_type = ULISTFMT_TYPE_AND; +} + if (type_string == "disjunction") { format_type = ULISTFMT_TYPE_OR; +} + if (type_string == "unit") { format_type = ULISTFMT_TYPE_UNITS; +} } } diff --git a/executors/cpp/localedisplaynames.cpp b/executors/cpp/localedisplaynames.cpp index 565fa679..9100ab43 100644 --- a/executors/cpp/localedisplaynames.cpp +++ b/executors/cpp/localedisplaynames.cpp @@ -19,7 +19,7 @@ using icu::Locale; using icu::UnicodeString; using icu::LocaleDisplayNames; -const string TestLocaleDisplayNames (json_object *json_in) { +string TestLocaleDisplayNames (json_object *json_in) { UErrorCode status = U_ZERO_ERROR; json_object *label_obj = json_object_object_get(json_in, "label"); @@ -40,7 +40,7 @@ const string TestLocaleDisplayNames (json_object *json_in) { string language_display_string = "standard"; json_object *language_display_obj = json_object_object_get( json_in, "languageDisplay"); - if (language_display_obj) { + if (language_display_obj != nullptr) { language_display_string = json_object_get_string(language_display_obj); } diff --git a/executors/cpp/main.cpp b/executors/cpp/main.cpp index d75d1457..e577c593 100644 --- a/executors/cpp/main.cpp +++ b/executors/cpp/main.cpp @@ -60,7 +60,7 @@ extern const string TestRelativeDateTimeFmt(json_object *json_in); * commands start with "#" * test data is JSON format */ -int main(int argc, const char** argv) { +auto main(int argc, const char** argv) -> int { // All the currently supported test types. std::vector supported_tests; supported_tests = { diff --git a/executors/cpp/number_fmt.cpp b/executors/cpp/number_fmt.cpp index f5dc12e0..458b71c1 100644 --- a/executors/cpp/number_fmt.cpp +++ b/executors/cpp/number_fmt.cpp @@ -26,8 +26,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -56,7 +56,7 @@ using icu::number::Precision; using icu::number::Scale; // Get the integer value of a settting -int16_t get_integer_setting(string key_value_string) { +auto get_integer_setting(string key_value_string) -> int16_t { int16_t return_val = -1; size_t colon_pos = key_value_string.find(":"); if (colon_pos >= 0) { @@ -67,7 +67,7 @@ int16_t get_integer_setting(string key_value_string) { } // Get the double value of a settting -double get_double_setting(string key_value_string) { +auto get_double_setting(string key_value_string) -> double { double return_val = -1.0; size_t colon_pos = key_value_string.find(":"); if (colon_pos >= 0) { @@ -78,9 +78,9 @@ double get_double_setting(string key_value_string) { } // Get integer width settings -IntegerWidth set_integerWidth(json_object* options_obj) { +auto set_integerWidth(json_object* options_obj) -> IntegerWidth { IntegerWidth integerWidth_setting = IntegerWidth::zeroFillTo(1); - if (!options_obj) { + if (options_obj == nullptr) { return integerWidth_setting; } string int_width_string; @@ -89,19 +89,19 @@ IntegerWidth set_integerWidth(json_object* options_obj) { options_obj, "minimumIntegerDigits"); json_object* integer_obj_max = json_object_object_get( options_obj, "maximumIntegerDigits"); - if (integer_obj_min && integer_obj_max) { + if ((integer_obj_min != nullptr) && (integer_obj_max != nullptr)) { int_width_string = json_object_get_string(integer_obj_min); int32_t val_min32 = get_integer_setting(int_width_string); int_width_string = json_object_get_string(integer_obj_max); int32_t val_max32 = get_integer_setting(int_width_string); integerWidth_setting = IntegerWidth::zeroFillTo(val_min32).truncateAt(val_max32); - } else if (integer_obj_min && !integer_obj_max) { + } else if ((integer_obj_min != nullptr) && (integer_obj_max == nullptr)) { int_width_string = json_object_get_string(integer_obj_min); int32_t val_min32 = get_integer_setting(int_width_string); int_width_string = json_object_get_string(integer_obj_min); integerWidth_setting = IntegerWidth::zeroFillTo(val_min32); - } else if (!integer_obj_min && integer_obj_max) { + } else if ((integer_obj_min == nullptr) && (integer_obj_max != nullptr)) { int_width_string = json_object_get_string(integer_obj_max); int32_t val_max32 = get_integer_setting(int_width_string); integerWidth_setting = IntegerWidth::zeroFillTo(1).truncateAt(val_max32); @@ -110,10 +110,10 @@ IntegerWidth set_integerWidth(json_object* options_obj) { } // Get fraction and siginfication digits settings -Precision set_precision_digits(json_object* options_obj, - Precision previous_setting) { +auto set_precision_digits(json_object* options_obj, + Precision previous_setting) -> Precision { Precision precision_setting = previous_setting; - if (!options_obj) { + if (options_obj == nullptr) { return precision_setting; } @@ -127,20 +127,20 @@ Precision set_precision_digits(json_object* options_obj, int16_t val_max = 0; int16_t val_min = 0; - if (precision_obj_max) { + if (precision_obj_max != nullptr) { val_max = get_integer_setting( json_object_get_string(precision_obj_max)); } - if (precision_obj_min) { + if (precision_obj_min != nullptr) { val_min = get_integer_setting( json_object_get_string(precision_obj_min)); } - if (precision_obj_max && precision_obj_min) { + if ((precision_obj_max != nullptr) && (precision_obj_min != nullptr)) { // Both are set precision_setting = Precision::minMaxFraction(val_min, val_max); - } else if (!precision_obj_max && precision_obj_min) { + } else if ((precision_obj_max == nullptr) && (precision_obj_min != nullptr)) { precision_setting = Precision::minFraction(val_min); - } else if (precision_obj_max && !precision_obj_min) { + } else if ((precision_obj_max != nullptr) && (precision_obj_min == nullptr)) { precision_setting = Precision::maxFraction(val_max); } @@ -150,37 +150,37 @@ Precision set_precision_digits(json_object* options_obj, precision_obj_min = json_object_object_get(options_obj, "minimumSignificantDigits"); - if (precision_obj_max) { + if (precision_obj_max != nullptr) { val_max = get_integer_setting( json_object_get_string(precision_obj_max)); } - if (precision_obj_min) { + if (precision_obj_min != nullptr) { val_min = get_integer_setting( json_object_get_string(precision_obj_min)); } - if (precision_obj_max && precision_obj_min) { + if ((precision_obj_max != nullptr) && (precision_obj_min != nullptr)) { // Both are set precision_setting = Precision::minMaxSignificantDigits(val_min, val_max); - } else if (!precision_obj_max && precision_obj_min) { + } else if ((precision_obj_max == nullptr) && (precision_obj_min != nullptr)) { precision_setting = Precision::minSignificantDigits(val_min); - } else if (precision_obj_max && !precision_obj_min) { + } else if ((precision_obj_max != nullptr) && (precision_obj_min == nullptr)) { precision_setting = Precision::maxSignificantDigits(val_max); } return precision_setting; } -UNumberSignDisplay set_sign_display(json_object* options_obj) { +auto set_sign_display(json_object* options_obj) -> UNumberSignDisplay { UNumberSignDisplay signDisplay_setting = UNUM_SIGN_AUTO; - if (!options_obj) { + if (options_obj == nullptr) { return signDisplay_setting; } json_object* signDisplay_obj = json_object_object_get(options_obj, "signDisplay"); - if (signDisplay_obj) { + if (signDisplay_obj != nullptr) { string signDisplay_string = json_object_get_string(signDisplay_obj); if (signDisplay_string == "exceptZero") { @@ -202,7 +202,7 @@ UNumberSignDisplay set_sign_display(json_object* options_obj) { return signDisplay_setting; } -const string TestNumfmt(json_object *json_in) { +string TestNumfmt(json_object *json_in) { UErrorCode status = U_ZERO_ERROR; // label information @@ -216,7 +216,7 @@ const string TestNumfmt(json_object *json_in) { // The locale for numbers json_object *locale_label_obj = json_object_object_get(json_in, "locale"); string locale_string = "und"; - if (locale_label_obj) { + if (locale_label_obj != nullptr) { locale_string = json_object_get_string(locale_label_obj); } @@ -266,17 +266,17 @@ const string TestNumfmt(json_object *json_in) { NumberingSystem::createInstance(displayLocale, status); // Check all the options - if (options_obj) { + if (options_obj != nullptr) { signDisplay_setting = set_sign_display(options_obj); notation_obj = json_object_object_get(options_obj, "notation"); - if (notation_obj) { + if (notation_obj != nullptr) { notation_string = json_object_get_string(notation_obj); } // TODO: Initialize setting based on this string. unit_obj = json_object_object_get(options_obj, "unit"); - if (unit_obj) { + if (unit_obj != nullptr) { unit_string = json_object_get_string(unit_obj); if (unit_string == "percent") { unit_setting = icu::NoUnit::percent(); @@ -288,7 +288,7 @@ const string TestNumfmt(json_object *json_in) { } unitDisplay_obj = json_object_object_get(options_obj, "unitDisplay"); - if (unitDisplay_obj) { + if (unitDisplay_obj != nullptr) { unitDisplay_string = json_object_get_string(unitDisplay_obj); if (unitDisplay_string == "narrow") { unit_width_setting = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; @@ -298,12 +298,12 @@ const string TestNumfmt(json_object *json_in) { } style_obj = json_object_object_get(options_obj, "style"); - if (style_obj) { + if (style_obj != nullptr) { style_string = json_object_get_string(style_obj); } compactDisplay_obj = json_object_object_get(options_obj, "compactDisplay"); - if (compactDisplay_obj) { + if (compactDisplay_obj != nullptr) { compactDisplay_string = json_object_get_string(compactDisplay_obj); if (compactDisplay_string == "short") { notation_setting = Notation::compactShort(); @@ -313,7 +313,7 @@ const string TestNumfmt(json_object *json_in) { } currency_obj = json_object_object_get(options_obj, "currency"); - if (currency_obj) { + if (currency_obj != nullptr) { string currency_string = json_object_get_string(currency_obj); // Set the unit to a currency value unit_setting = CurrencyUnit(icu::StringPiece(currency_string), status); @@ -322,7 +322,7 @@ const string TestNumfmt(json_object *json_in) { // TODO: make a function currencyDisplay_obj = json_object_object_get(options_obj, "currencyDisplay"); - if (currencyDisplay_obj) { + if (currencyDisplay_obj != nullptr) { string currencyDisplay_string = json_object_get_string(currencyDisplay_obj); unit_width_setting = UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW; @@ -337,7 +337,7 @@ const string TestNumfmt(json_object *json_in) { // TODO: Make this a function rather than inline. roundingMode_obj = json_object_object_get(options_obj, "roundingMode"); - if (roundingMode_obj) { + if (roundingMode_obj != nullptr) { string roundingMode_string = json_object_get_string(roundingMode_obj); if (roundingMode_string == "floor") { rounding_setting = UNUM_ROUND_FLOOR; @@ -363,7 +363,7 @@ const string TestNumfmt(json_object *json_in) { // TODO: make a function group_obj = json_object_object_get(options_obj, "useGrouping"); - if (group_obj) { + if (group_obj != nullptr) { string group_string = json_object_get_string(group_obj); if (group_string == "false") { grouping_setting = UNUM_GROUPING_OFF; @@ -384,7 +384,7 @@ const string TestNumfmt(json_object *json_in) { // Check on scaling the value json_object* scale_obj = json_object_object_get( options_obj, "conformanceScale"); - if (scale_obj) { + if (scale_obj != nullptr) { string scale_string = json_object_get_string(scale_obj); double scale_val = get_double_setting(scale_string); scale_setting = Scale::byDouble(scale_val); @@ -396,7 +396,7 @@ const string TestNumfmt(json_object *json_in) { json_object* numbering_system_obj = json_object_object_get(options_obj, "numberingSystem"); - if (numbering_system_obj) { + if (numbering_system_obj != nullptr) { string numbering_system_string = json_object_get_string(numbering_system_obj); numbering_system = NumberingSystem::createInstanceByName( @@ -406,7 +406,7 @@ const string TestNumfmt(json_object *json_in) { // Handling decimal point json_object* decimal_always_obj = json_object_object_get(options_obj, "conformanceDecimalAlways"); - if (decimal_always_obj) { + if (decimal_always_obj != nullptr) { string separator_string = json_object_get_string( decimal_always_obj); if (separator_string == "true") { @@ -432,10 +432,10 @@ const string TestNumfmt(json_object *json_in) { LocalizedNumberFormatter nf; if (notation_string == "scientific") { notation_setting = Notation::scientific(); - if (options_obj) { + if (options_obj != nullptr) { json_object* conformanceExponent_obj = json_object_object_get(options_obj, "conformanceExponent"); - if (conformanceExponent_obj) { + if (conformanceExponent_obj != nullptr) { // Check for the number of digits and sign string confExp_string = json_object_get_string(conformanceExponent_obj); // https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/unumberformatter_8h.html#a18092ae1533c9c260f01c9dbf25589c9 @@ -448,7 +448,7 @@ const string TestNumfmt(json_object *json_in) { } } - if (skeleton_obj) { + if (skeleton_obj != nullptr) { // Use the skeleton provided UnicodeString unicode_skeleton_string; string skeleton_string = json_object_get_string(skeleton_obj); @@ -472,7 +472,7 @@ const string TestNumfmt(json_object *json_in) { .unitWidth(unit_width_setting); } - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { const char* error_name = u_errorName(status); json_object_object_add( return_json, @@ -488,7 +488,7 @@ const string TestNumfmt(json_object *json_in) { // Use formatDecimal, passing the string instead of a double. FormattedNumber fmt_number = nf.formatDecimal(input_string, status); number_result = fmt_number.toString(status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { const char* error_name = u_errorName(status); json_object_object_add( return_json, @@ -502,7 +502,7 @@ const string TestNumfmt(json_object *json_in) { string test_result; number_result.toUTF8String(test_result); - if (U_FAILURE(status)) { + if (U_FAILURE(status) != 0) { // Report a failure const char* error_name = u_errorName(status); json_object_object_add( diff --git a/executors/cpp/plural_rules.cpp b/executors/cpp/plural_rules.cpp index 31a6cfac..1b85bb25 100644 --- a/executors/cpp/plural_rules.cpp +++ b/executors/cpp/plural_rules.cpp @@ -22,7 +22,7 @@ using icu::UnicodeString; using std::string; -const string TestPluralRules (json_object* json_in) { +string TestPluralRules (json_object* json_in) { UErrorCode status = U_ZERO_ERROR; json_object* label_obj = json_object_object_get(json_in, "label"); @@ -33,7 +33,7 @@ const string TestPluralRules (json_object* json_in) { string type_string = ""; json_object* locale_label_obj = json_object_object_get(json_in, "locale"); - if (locale_label_obj) { + if (locale_label_obj != nullptr) { locale_string = json_object_get_string(locale_label_obj); } Locale display_locale(locale_string.c_str()); @@ -53,7 +53,7 @@ const string TestPluralRules (json_object* json_in) { std::vector u_strings; int u_strings_size = 0; - if (sample_obj) { + if (sample_obj != nullptr) { // Get the number string sample_string = json_object_get_string(sample_obj); @@ -78,7 +78,7 @@ const string TestPluralRules (json_object* json_in) { // Get option fields json_object* type_obj = json_object_object_get(json_in, "type"); - if (type_obj) { + if (type_obj != nullptr) { type_string = json_object_get_string(type_obj); } UPluralType plural_type; diff --git a/executors/cpp/relativedatetime_fmt.cpp b/executors/cpp/relativedatetime_fmt.cpp index df20ca0a..5977ac27 100644 --- a/executors/cpp/relativedatetime_fmt.cpp +++ b/executors/cpp/relativedatetime_fmt.cpp @@ -11,8 +11,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -30,22 +30,25 @@ using std::string; /* * Check for ICU errors and add to output if needed. */ -extern const bool check_icu_error(UErrorCode error_code, +extern auto check_icu_error(UErrorCode error_code, json_object *return_json, - string message_to_add_if_error); + string message_to_add_if_error) -> const bool; -UDateRelativeDateTimeFormatterStyle StringToStyleEnum(string style_string) { - if (style_string == "long") return UDAT_STYLE_LONG; - if (style_string == "short") return UDAT_STYLE_SHORT; - if (style_string == "narrow") return UDAT_STYLE_NARROW; +auto StringToStyleEnum(string style_string) -> UDateRelativeDateTimeFormatterStyle { + if (style_string == "long") { return UDAT_STYLE_LONG; +} + if (style_string == "short") { return UDAT_STYLE_SHORT; +} + if (style_string == "narrow") { return UDAT_STYLE_NARROW; +} return UDAT_STYLE_LONG; // Default } -URelativeDateTimeUnit StringToRelativeUnitEnum(string unit_string) { +auto StringToRelativeUnitEnum(string unit_string) -> URelativeDateTimeUnit { URelativeDateTimeUnit rel_unit; if (unit_string == "day") { return UDAT_REL_UNIT_DAY; - } else if (unit_string == "hour") { + } if (unit_string == "hour") { return UDAT_REL_UNIT_HOUR; } else if (unit_string == "minute") { return UDAT_REL_UNIT_MINUTE; @@ -64,7 +67,7 @@ URelativeDateTimeUnit StringToRelativeUnitEnum(string unit_string) { return UDAT_REL_UNIT_DAY; } -const string TestRelativeDateTimeFmt(json_object *json_in) { +string TestRelativeDateTimeFmt(json_object *json_in) { UErrorCode status = U_ZERO_ERROR; json_object *label_obj = json_object_object_get(json_in, "label"); @@ -76,7 +79,7 @@ const string TestRelativeDateTimeFmt(json_object *json_in) { // The locale for formatted output json_object *locale_label_obj = json_object_object_get(json_in, "locale"); string locale_string; - if (locale_label_obj) { + if (locale_label_obj != nullptr) { locale_string = json_object_get_string(locale_label_obj); } else { locale_string = "und"; @@ -98,18 +101,18 @@ const string TestRelativeDateTimeFmt(json_object *json_in) { string style_string = "long"; // Default string numbering_system_string = ""; // Default string numeric_option = ""; - if (options_obj) { + if (options_obj != nullptr) { json_object *style_obj = json_object_object_get(options_obj, "style"); - if (style_obj) { + if (style_obj != nullptr) { style_string = json_object_get_string(style_obj); } json_object *ns_obj = json_object_object_get(options_obj, "numberingSystem"); - if (ns_obj) { + if (ns_obj != nullptr) { numbering_system_string = json_object_get_string(ns_obj); } json_object *numeric_obj = json_object_object_get(options_obj, "numeric"); - if (numeric_obj) { + if (numeric_obj != nullptr) { numeric_option = json_object_get_string(numeric_obj); } } diff --git a/executors/cpp/util.cpp b/executors/cpp/util.cpp index 05523403..6863fe86 100644 --- a/executors/cpp/util.cpp +++ b/executors/cpp/util.cpp @@ -18,12 +18,12 @@ using std::string; If there's an error, add an error field and the given message to the return_json object and return true. */ -const bool check_icu_error(UErrorCode error_code, +auto check_icu_error(UErrorCode error_code, json_object *return_json, - string message_to_add_if_error) { + string message_to_add_if_error) -> const bool { bool is_error = false; - if (!U_FAILURE(error_code)) { + if (U_FAILURE(error_code) == 0) { return is_error; } From c79666cdbf35235f5c1a51c14d29284b83b82a95 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Tue, 5 Nov 2024 15:47:01 -0800 Subject: [PATCH 05/20] Added Clang Tidy to CI --- .github/workflows/e2e.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 507b85e3..c6dad123 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -38,6 +38,15 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: 1.73 + - name: Run Clang Tidy Review + uses: ZedThree/clang-tidy-review@v0.14.0 + id: review + - name: Clang Tidy Review Artifact Upload + uses: ZedThree/clang-tidy-review/upload@v0.14.0 + id: upload-review + - name: Clang Tidy Fail If Errors Found + if: steps.review.outputs.total_comments > 0 + run: exit 1 - name: Run End-to-end script run: bash generateDataAndRun.sh - name: Setup Pages From 2c6e6540a62bd9534a1574c5ec028df1b2da881f Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Tue, 5 Nov 2024 16:09:18 -0800 Subject: [PATCH 06/20] Apply changes from clang-tidy --- executors/cpp/relativedatetime_fmt.cpp | 23 +++++++++++++++-------- executors/cpp/util.h | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/executors/cpp/relativedatetime_fmt.cpp b/executors/cpp/relativedatetime_fmt.cpp index 5977ac27..43447a53 100644 --- a/executors/cpp/relativedatetime_fmt.cpp +++ b/executors/cpp/relativedatetime_fmt.cpp @@ -48,19 +48,26 @@ auto StringToRelativeUnitEnum(string unit_string) -> URelativeDateTimeUnit { URelativeDateTimeUnit rel_unit; if (unit_string == "day") { return UDAT_REL_UNIT_DAY; - } if (unit_string == "hour") { + } + if (unit_string == "hour") { return UDAT_REL_UNIT_HOUR; - } else if (unit_string == "minute") { + } + if (unit_string == "minute") { return UDAT_REL_UNIT_MINUTE; - } else if (unit_string == "month") { + } + if (unit_string == "month") { return UDAT_REL_UNIT_MONTH; - } else if (unit_string == "second") { + } + if (unit_string == "second") { return UDAT_REL_UNIT_SECOND; - } else if (unit_string == "week") { + } + if (unit_string == "week") { return UDAT_REL_UNIT_WEEK; - } else if (unit_string == "quarter") { - return UDAT_REL_UNIT_QUARTER; - } else if (unit_string == "year") { + } + if (unit_string == "quarter") { + UDAT_REL_UNIT_QUARTER; + } + if (unit_string == "year") { return UDAT_REL_UNIT_YEAR; } // A default diff --git a/executors/cpp/util.h b/executors/cpp/util.h index 0e488041..c3ebac69 100644 --- a/executors/cpp/util.h +++ b/executors/cpp/util.h @@ -8,7 +8,7 @@ using std::string; -extern const bool check_icu_error(UErrorCode error_code, +extern auto check_icu_error(UErrorCode error_code, json_object *return_json, - string message_to_add_if_error); + string message_to_add_if_error) -> const bool; From 3cf0b62569421ec97a94bbb7fc585eabbdb79ce3 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Tue, 5 Nov 2024 16:09:34 -0800 Subject: [PATCH 07/20] Make icu4c setup script more robust --- executors/cpp/set_icu4c_binary.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executors/cpp/set_icu4c_binary.sh b/executors/cpp/set_icu4c_binary.sh index 29fb4d43..448f3ff7 100755 --- a/executors/cpp/set_icu4c_binary.sh +++ b/executors/cpp/set_icu4c_binary.sh @@ -34,8 +34,8 @@ popd pushd ../executors/cpp make clean -LD_LIBRARY_PATH=/tmp/icu/icu/usr/local/lib -PATH=/tmp/icu/icu/usr/local/bin:$PATH +export LD_LIBRARY_PATH=/tmp/icu/icu/usr/local/lib:$LD_LIBRARY_PATH +export PATH=/tmp/icu/icu/usr/local/bin:$PATH make From acb1cca6c2de66e4559f810a1bf4d4007ceb2251 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Tue, 5 Nov 2024 16:29:03 -0800 Subject: [PATCH 08/20] Add a clang `compile_commands.txt` to assist compilation output msgs --- .github/workflows/e2e.yml | 4 ++++ executors/cpp/compile_flags.txt | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 executors/cpp/compile_flags.txt diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c6dad123..c9aa74ad 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -40,9 +40,13 @@ jobs: toolchain: 1.73 - name: Run Clang Tidy Review uses: ZedThree/clang-tidy-review@v0.14.0 + with: + build_dir: './executors/cpp' id: review - name: Clang Tidy Review Artifact Upload uses: ZedThree/clang-tidy-review/upload@v0.14.0 + with: + build_dir: './executors/cpp' id: upload-review - name: Clang Tidy Fail If Errors Found if: steps.review.outputs.total_comments > 0 diff --git a/executors/cpp/compile_flags.txt b/executors/cpp/compile_flags.txt new file mode 100644 index 00000000..b5077db7 --- /dev/null +++ b/executors/cpp/compile_flags.txt @@ -0,0 +1,9 @@ +-L/tmp/icu/icu/usr/local/lib +-I/usr/include/c++/13 +-I/usr/include/x86_64-linux-gnu/c++/13 +-I/usr/include/c++/13/backward +-I/usr/lib/gcc/x86_64-linux-gnu/13/include +-I/usr/local/include +-I/usr/include/x86_64-linux-gnu +-I/usr/include + From af0ea0338858cb29cdeed6e3e591a6b45ee1178c Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Tue, 5 Nov 2024 16:40:35 -0800 Subject: [PATCH 09/20] Apply clang-tidy change --- executors/cpp/relativedatetime_fmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executors/cpp/relativedatetime_fmt.cpp b/executors/cpp/relativedatetime_fmt.cpp index 43447a53..1fc93c40 100644 --- a/executors/cpp/relativedatetime_fmt.cpp +++ b/executors/cpp/relativedatetime_fmt.cpp @@ -65,7 +65,7 @@ auto StringToRelativeUnitEnum(string unit_string) -> URelativeDateTimeUnit { return UDAT_REL_UNIT_WEEK; } if (unit_string == "quarter") { - UDAT_REL_UNIT_QUARTER; + return UDAT_REL_UNIT_QUARTER; } if (unit_string == "year") { return UDAT_REL_UNIT_YEAR; From 89908ac9c26d26fdc11ee2e7dc458bd8c42d6334 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 10:45:37 -0800 Subject: [PATCH 10/20] Add clang-tidy config file --- .github/workflows/e2e.yml | 1 + executors/cpp/clang-tidy-config.yml | 1 + 2 files changed, 2 insertions(+) create mode 100644 executors/cpp/clang-tidy-config.yml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c9aa74ad..13d69873 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -42,6 +42,7 @@ jobs: uses: ZedThree/clang-tidy-review@v0.14.0 with: build_dir: './executors/cpp' + config_file: './executors/cpp/clang-tidy-config.yml' id: review - name: Clang Tidy Review Artifact Upload uses: ZedThree/clang-tidy-review/upload@v0.14.0 diff --git a/executors/cpp/clang-tidy-config.yml b/executors/cpp/clang-tidy-config.yml new file mode 100644 index 00000000..b01c7c3d --- /dev/null +++ b/executors/cpp/clang-tidy-config.yml @@ -0,0 +1 @@ +HeaderFilterRegex: '.*' \ No newline at end of file From 96b43263b61f3f674fb299264d74af35af832754 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 10:55:32 -0800 Subject: [PATCH 11/20] Test clang-tidy run on CI to sidestep CI upload step permissions --- .github/workflows/e2e.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 13d69873..ff599e46 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -44,11 +44,11 @@ jobs: build_dir: './executors/cpp' config_file: './executors/cpp/clang-tidy-config.yml' id: review - - name: Clang Tidy Review Artifact Upload - uses: ZedThree/clang-tidy-review/upload@v0.14.0 - with: - build_dir: './executors/cpp' - id: upload-review + # - name: Clang Tidy Review Artifact Upload + # uses: ZedThree/clang-tidy-review/upload@v0.14.0 + # with: + # build_dir: './executors/cpp' + # id: upload-review - name: Clang Tidy Fail If Errors Found if: steps.review.outputs.total_comments > 0 run: exit 1 From 0e6409601f52d39ffd35e3cb5977f01aa2b4df2e Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 10:59:31 -0800 Subject: [PATCH 12/20] Mod to workaround GHA permissions --- .github/workflows/e2e.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ff599e46..92942635 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -41,14 +41,18 @@ jobs: - name: Run Clang Tidy Review uses: ZedThree/clang-tidy-review@v0.14.0 with: + # clang-tidy specific configs build_dir: './executors/cpp' config_file: './executors/cpp/clang-tidy-config.yml' + # Action-specific config + split_workflow: true id: review # - name: Clang Tidy Review Artifact Upload # uses: ZedThree/clang-tidy-review/upload@v0.14.0 # with: # build_dir: './executors/cpp' # id: upload-review + - uses: ZedThree/clang-tidy-review/upload@v0.14.0 - name: Clang Tidy Fail If Errors Found if: steps.review.outputs.total_comments > 0 run: exit 1 From c2a608715e3643849b06bde718924c1feb3a0d74 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 14:24:46 -0800 Subject: [PATCH 13/20] Try to include json-c dependency in clang-tidy CI action --- .github/workflows/e2e.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 92942635..ad8c4a77 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -46,6 +46,7 @@ jobs: config_file: './executors/cpp/clang-tidy-config.yml' # Action-specific config split_workflow: true + apt_packages: "libjson-c-dev" id: review # - name: Clang Tidy Review Artifact Upload # uses: ZedThree/clang-tidy-review/upload@v0.14.0 From d6b1d99f6a3d3a5608fd4896a250886e78b4f6b3 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 14:43:00 -0800 Subject: [PATCH 14/20] Refactor clang-tidy CI jobs into a separate workflow --- .github/workflows/clang-tidy-post.yml | 21 +++++++++++++++++++++ .github/workflows/clang-tidy-review.yml | 24 ++++++++++++++++++++++++ .github/workflows/e2e.yml | 19 ------------------- 3 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/clang-tidy-post.yml create mode 100644 .github/workflows/clang-tidy-review.yml diff --git a/.github/workflows/clang-tidy-post.yml b/.github/workflows/clang-tidy-post.yml new file mode 100644 index 00000000..87534c99 --- /dev/null +++ b/.github/workflows/clang-tidy-post.yml @@ -0,0 +1,21 @@ +name: Post clang-tidy review comments + +on: + workflow_run: + # The name field of the lint action + workflows: ["clang-tidy-review"] + types: + - completed + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: ZedThree/clang-tidy-review/post@v0.14.0 + # lgtm_comment_body, max_comments, and annotations need to be set on the posting workflow in a split setup + with: + # adjust options as necessary + lgtm_comment_body: '' + annotations: false + max_comments: 10 \ No newline at end of file diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml new file mode 100644 index 00000000..e305eb3c --- /dev/null +++ b/.github/workflows/clang-tidy-review.yml @@ -0,0 +1,24 @@ +name: clang-tidy-review + +# You can be more specific, but it currently only works on pull requests +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + # Optionally generate compile_commands.json + + - uses: ZedThree/clang-tidy-review@v0.14.0 + with: + # clang-tidy specific configs + build_dir: './executors/cpp' + config_file: './executors/cpp/clang-tidy-config.yml' + # Action-specific config + split_workflow: true + apt_packages: "libjson-c-dev,libicu-dev" + + - uses: ZedThree/clang-tidy-review/upload@v0.14.0 \ No newline at end of file diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ad8c4a77..507b85e3 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -38,25 +38,6 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: 1.73 - - name: Run Clang Tidy Review - uses: ZedThree/clang-tidy-review@v0.14.0 - with: - # clang-tidy specific configs - build_dir: './executors/cpp' - config_file: './executors/cpp/clang-tidy-config.yml' - # Action-specific config - split_workflow: true - apt_packages: "libjson-c-dev" - id: review - # - name: Clang Tidy Review Artifact Upload - # uses: ZedThree/clang-tidy-review/upload@v0.14.0 - # with: - # build_dir: './executors/cpp' - # id: upload-review - - uses: ZedThree/clang-tidy-review/upload@v0.14.0 - - name: Clang Tidy Fail If Errors Found - if: steps.review.outputs.total_comments > 0 - run: exit 1 - name: Run End-to-end script run: bash generateDataAndRun.sh - name: Setup Pages From 4b39c356f11c760a5de1b0f258ab3977d8ebcb79 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 14:45:54 -0800 Subject: [PATCH 15/20] Update CI job names --- .github/workflows/clang-tidy-review.yml | 1 + .github/workflows/e2e.yml | 2 +- .github/workflows/run-rust.yml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml index e305eb3c..e9f4935e 100644 --- a/.github/workflows/clang-tidy-review.yml +++ b/.github/workflows/clang-tidy-review.yml @@ -5,6 +5,7 @@ on: [pull_request] jobs: build: + name: Lint ICU4C C++ executor runs-on: ubuntu-latest steps: diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 507b85e3..719736d1 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -16,7 +16,7 @@ permissions: jobs: run_all: - name: End-to-end (Gen data, run tests, gen GH Pages) + name: End-to-end runs-on: ubuntu-latest steps: - name: Checkout repo diff --git a/.github/workflows/run-rust.yml b/.github/workflows/run-rust.yml index ce420289..508fa99a 100644 --- a/.github/workflows/run-rust.yml +++ b/.github/workflows/run-rust.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: icu4x-version: [ '1.3', '1.4' ] - name: Lint the executor code for ICU4X + name: Lint ICU4X Rust executor runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 697d455d06c3b24b510cd2f0f377afbad3db48f9 Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 15:04:37 -0800 Subject: [PATCH 16/20] Change workflow name to trigger the 2nd workflow --- .github/workflows/clang-tidy-post.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-tidy-post.yml b/.github/workflows/clang-tidy-post.yml index 87534c99..035c4cbb 100644 --- a/.github/workflows/clang-tidy-post.yml +++ b/.github/workflows/clang-tidy-post.yml @@ -3,7 +3,7 @@ name: Post clang-tidy review comments on: workflow_run: # The name field of the lint action - workflows: ["clang-tidy-review"] + workflows: [clang-tidy-review] types: - completed From 2053069f7e9dc68b4855b1e990b17eaca053305f Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 15:14:00 -0800 Subject: [PATCH 17/20] Remove second workflow b/c it won't trigger without user PAT tokens on a PR branch --- .github/workflows/clang-tidy-post.yml | 21 --------------------- .github/workflows/clang-tidy-review.yml | 7 ++++++- 2 files changed, 6 insertions(+), 22 deletions(-) delete mode 100644 .github/workflows/clang-tidy-post.yml diff --git a/.github/workflows/clang-tidy-post.yml b/.github/workflows/clang-tidy-post.yml deleted file mode 100644 index 035c4cbb..00000000 --- a/.github/workflows/clang-tidy-post.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Post clang-tidy review comments - -on: - workflow_run: - # The name field of the lint action - workflows: [clang-tidy-review] - types: - - completed - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: ZedThree/clang-tidy-review/post@v0.14.0 - # lgtm_comment_body, max_comments, and annotations need to be set on the posting workflow in a split setup - with: - # adjust options as necessary - lgtm_comment_body: '' - annotations: false - max_comments: 10 \ No newline at end of file diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml index e9f4935e..5f20832b 100644 --- a/.github/workflows/clang-tidy-review.yml +++ b/.github/workflows/clang-tidy-review.yml @@ -21,5 +21,10 @@ jobs: # Action-specific config split_workflow: true apt_packages: "libjson-c-dev,libicu-dev" + id: review - - uses: ZedThree/clang-tidy-review/upload@v0.14.0 \ No newline at end of file + - uses: ZedThree/clang-tidy-review/upload@v0.14.0 + + # If there are any comments, fail the check + - if: steps.review.outputs.total_comments > 0 + run: exit 1 \ No newline at end of file From d7a90ffdf0d5e7e7e8e2ef86c23ed7fc3a567eee Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 15:21:36 -0800 Subject: [PATCH 18/20] test CI by inducing a known error --- executors/cpp/relativedatetime_fmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executors/cpp/relativedatetime_fmt.cpp b/executors/cpp/relativedatetime_fmt.cpp index 1fc93c40..43447a53 100644 --- a/executors/cpp/relativedatetime_fmt.cpp +++ b/executors/cpp/relativedatetime_fmt.cpp @@ -65,7 +65,7 @@ auto StringToRelativeUnitEnum(string unit_string) -> URelativeDateTimeUnit { return UDAT_REL_UNIT_WEEK; } if (unit_string == "quarter") { - return UDAT_REL_UNIT_QUARTER; + UDAT_REL_UNIT_QUARTER; } if (unit_string == "year") { return UDAT_REL_UNIT_YEAR; From 072cdfaa276d895807fa093ebe7bc7cc669fdd6c Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 15:35:28 -0800 Subject: [PATCH 19/20] Revert "test CI by inducing a known error" This reverts commit d7a90ffdf0d5e7e7e8e2ef86c23ed7fc3a567eee. --- executors/cpp/relativedatetime_fmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executors/cpp/relativedatetime_fmt.cpp b/executors/cpp/relativedatetime_fmt.cpp index 43447a53..1fc93c40 100644 --- a/executors/cpp/relativedatetime_fmt.cpp +++ b/executors/cpp/relativedatetime_fmt.cpp @@ -65,7 +65,7 @@ auto StringToRelativeUnitEnum(string unit_string) -> URelativeDateTimeUnit { return UDAT_REL_UNIT_WEEK; } if (unit_string == "quarter") { - UDAT_REL_UNIT_QUARTER; + return UDAT_REL_UNIT_QUARTER; } if (unit_string == "year") { return UDAT_REL_UNIT_YEAR; From 6fccc83372fa3dc20736c1a23b190a9e24d14c3d Mon Sep 17 00:00:00 2001 From: Elango Cheran Date: Wed, 6 Nov 2024 15:43:00 -0800 Subject: [PATCH 20/20] Add CLI usage for clang-tidy locally --- .github/workflows/clang-tidy-review.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml index 5f20832b..b0920521 100644 --- a/.github/workflows/clang-tidy-review.yml +++ b/.github/workflows/clang-tidy-review.yml @@ -13,6 +13,12 @@ jobs: # Optionally generate compile_commands.json + # Run clang-tidy + # Note: when running locally at the command line, use the equivalent + # command when in the directory `executors/cpp`: + # clang-tidy *.cpp --fix-errors --config-file="clang-tidy-config.yml" -p . + # Note: you must run setup.sh and also run install_icu4c_binary.sh (for a given ICU4C version) first + # before running the above clang-tidy command - uses: ZedThree/clang-tidy-review@v0.14.0 with: # clang-tidy specific configs