Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve the accuracy of the coverage report. #296

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions build/showprogress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for header_basename in ${C_API_HEADER_NAMES[@]}; do
# rust docs of the form "/// Implements `utext_close` ... ". This is
# simplistic but quite enough with a little bit of care.
find . -path "*rust_icu_${header_basename}/src/*.rs" | \
xargs grep "/// Implements \`" | sed -e 's/.*`\(.*\)`.*$/\1/' | \
xargs grep "/// Implements \`" | sed -e 's/.*`\(.*\)`.*$/\1/' | sed -e 's/\(.*\)()$/\1/' | \
sort | uniq > "${TOP_DIR}/coverage/${header_basename}_implemented.txt"
done

Expand Down Expand Up @@ -71,7 +71,9 @@ for header_basename in ${C_API_HEADER_NAMES[@]}; do
| Unimplemented | Implemented |
| ------------- | ----------- |
EOF
for fun in $(cat "${TOP_DIR}/coverage/${header_basename}_implemented.txt" | sort -fs); do
all=`cat ${TOP_DIR}/coverage/${header_basename}_all.txt | sort -fs`
implemented=`cat "${TOP_DIR}/coverage/${header_basename}_implemented.txt" | sort -fs`
for fun in ${implemented}; do
echo "| | \`${fun}\` |" >>"${REPORT_FILE}"
done

Expand All @@ -82,6 +84,30 @@ EOF
echo "| \`${fun}\` | |" >>"${REPORT_FILE}"
done

total_cnt=`echo ${all} | wc -w`
implemented_cnt=`echo ${implemented} | wc -w`
unimplemented_cnt=`echo ${unimplemented} | wc -w`
computed_total_cnt=`expr ${unimplemented_cnt} + ${implemented_cnt}`
if [ ${computed_total_cnt} -ne ${total_cnt} ]
then
printf "Warning: Implemented + Unimplemented != Total\n" >> ${REPORT_FILE}
printf "Total: %s Implemented: %s Unimplemented: %s\n" ${total_cnt} ${implemented_cnt} ${unimplemented_cnt} >> "${REPORT_FILE}"
for impl_fn in ${implemented}; do
found="false"
for all_fn in ${all}; do
if [ ${impl_fn} = ${all_fn} ]
then
found="true"
break
fi
done
if [ "false" = ${found} ]
then
printf "Function %s was designated as implemented but not found in the API\n" ${impl_fn} >> "${REPORT_FILE}"
fi
done
fi

sort -fs -o "${TOP_DIR}/coverage/${header_basename}_all.txt" "${TOP_DIR}/coverage/${header_basename}_all.txt"
sort -fs -o "${TOP_DIR}/coverage/${header_basename}_implemented.txt" "${TOP_DIR}/coverage/${header_basename}_implemented.txt"
done
Expand Down
45 changes: 36 additions & 9 deletions coverage/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
| `ucol.h` | 8 / 51 |
| `udat.h` | 10 / 38 |
| `udata.h` | 4 / 8 |
| `uenum.h` | 8 / 8 |
| `uenum.h` | 7 / 8 |
| `uformattable.h` | 6 / 13 |
| `ulistformatter.h` | 2 / 8 |
| `uloc.h` | 30 / 42 |
| `uloc.h` | 28 / 42 |
| `umsg.h` | 6 / 20 |
| `unum.h` | 14 / 32 |
| `unumberformatter.h` | 7 / 6 |
Expand Down Expand Up @@ -205,6 +205,13 @@
| `udat_toPatternRelativeDate` | |
| `udat_toPatternRelativeTime` | |
| `udat_unregisterOpener` | |
Warning: Implemented + Unimplemented != Total
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the question about the clarity of the message or the existence of the message? If it is about clarity, would something like "Warning: Count of total C API functions is not equal to the sum of the counts of implemented and non-implemented functions" be clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to add a screen to the '*_implemented.txt' file creation to ignore functions that aren't in the C API for the given header file.

Total: 38 Implemented: 10 Unimplemented: 33
Function UDateFormat was designated as implemented but not found in the API
Function UDateTimePatternGenerator was designated as implemented but not found in the API
Function udatpg_clone was designated as implemented but not found in the API
Function udatpg_getBestPattern was designated as implemented but not found in the API
Function udatpg_open was designated as implemented but not found in the API

# Header: `udata.h`

Expand All @@ -220,6 +227,10 @@
| `udata_openChoice` | |
| `udata_setAppData` | |
| `udata_setFileAccess` | |
Warning: Implemented + Unimplemented != Total
Total: 8 Implemented: 4 Unimplemented: 6
Function UDataMemory was designated as implemented but not found in the API
Function u_setDataDirectory was designated as implemented but not found in the API

# Header: `uenum.h`

Expand All @@ -232,12 +243,17 @@
| | `uenum_close` |
| | `uenum_next` |
| | `uenum_openCharStringsEnumeration` |
| | `uloc_openKeywords` |
| `uenum_count` | |
| `uenum_openFromStringEnumeration` | |
| `uenum_openUCharStringsEnumeration` | |
| `uenum_reset` | |
| `uenum_unext` | |
Warning: Implemented + Unimplemented != Total
Total: 8 Implemented: 7 Unimplemented: 5
Function ucal_openCountryTimeZones was designated as implemented but not found in the API
Function ucal_openTimeZoneIDEnumeration was designated as implemented but not found in the API
Function ucal_openTimeZones was designated as implemented but not found in the API
Function UEnumeration was designated as implemented but not found in the API

# Header: `uformattable.h`

Expand Down Expand Up @@ -274,8 +290,6 @@

| Unimplemented | Implemented |
| ------------- | ----------- |
| | `icu::Locale::getUnicodeKeywords()` |
| | `icu::Locale::getUnicodeKeywordValue()` |
| | `uloc_acceptLanguage` |
| | `uloc_addLikelySubtags` |
| | `uloc_canonicalize` |
Expand All @@ -292,13 +306,13 @@
| | `uloc_getDisplayName` |
| | `uloc_getDisplayScript` |
| | `uloc_getDisplayVariant` |
| | `uloc_getKeywordValue()` |
| | `uloc_getKeywordValue` |
| | `uloc_getLanguage` |
| | `uloc_getName` |
| | `uloc_getScript` |
| | `uloc_getVariant` |
| | `uloc_minimizeSubtags` |
| | `uloc_openKeywords()` |
| | `uloc_openKeywords` |
| | `uloc_setDefault` |
| | `uloc_toLanguageTag` |
| | `uloc_toLegacyKey` |
Expand All @@ -310,14 +324,12 @@
| `uloc_getISO3Language` | |
| `uloc_getISOCountries` | |
| `uloc_getISOLanguages` | |
| `uloc_getKeywordValue` | |
| `uloc_getLCID` | |
| `uloc_getLineOrientation` | |
| `uloc_getLocaleForLCID` | |
| `uloc_getParent` | |
| `uloc_isRightToLeft` | |
| `uloc_openAvailableByType` | |
| `uloc_openKeywords` | |
| `uloc_setKeywordValue` | |
| `uloc_toLegacyType` | |

Expand Down Expand Up @@ -346,6 +358,9 @@
| `u_vformatMessageWithError` | |
| `u_vparseMessage` | |
| `u_vparseMessageWithError` | |
Warning: Implemented + Unimplemented != Total
Total: 20 Implemented: 6 Unimplemented: 15
Function UMessageFormat was designated as implemented but not found in the API

# Header: `unum.h`

Expand Down Expand Up @@ -398,6 +413,12 @@
| `unumf_close` | |
| `unumf_formatDouble` | |
| `unumf_formatInt` | |
Warning: Implemented + Unimplemented != Total
Total: 6 Implemented: 7 Unimplemented: 3
Function unumf_openResult was designated as implemented but not found in the API
Function unumf_resultGetAllFieldPositions was designated as implemented but not found in the API
Function unumf_resultNextFieldPosition was designated as implemented but not found in the API
Function unumf_resultToString was designated as implemented but not found in the API

# Header: `upluralrules.h`

Expand Down Expand Up @@ -478,6 +499,9 @@
| `u_uastrncpy` | |
| `u_unescape` | |
| `u_unescapeAt` | |
Warning: Implemented + Unimplemented != Total
Total: 61 Implemented: 3 Unimplemented: 59
Function UChar* was designated as implemented but not found in the API

# Header: `utext.h`

Expand Down Expand Up @@ -512,6 +536,9 @@
| `utext_replace` | |
| `utext_setNativeIndex` | |
| `utext_setup` | |
Warning: Implemented + Unimplemented != Total
Total: 28 Implemented: 3 Unimplemented: 26
Function utext_open was designated as implemented but not found in the API

# Header: `utrans.h`

Expand Down
1 change: 0 additions & 1 deletion coverage/uenum_implemented.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ UEnumeration
uenum_close
uenum_next
uenum_openCharStringsEnumeration
uloc_openKeywords
6 changes: 2 additions & 4 deletions coverage/uloc_implemented.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
icu::Locale::getUnicodeKeywords()
icu::Locale::getUnicodeKeywordValue()
uloc_acceptLanguage
uloc_addLikelySubtags
uloc_canonicalize
Expand All @@ -16,13 +14,13 @@ uloc_getDisplayLanguage
uloc_getDisplayName
uloc_getDisplayScript
uloc_getDisplayVariant
uloc_getKeywordValue()
uloc_getKeywordValue
uloc_getLanguage
uloc_getName
uloc_getScript
uloc_getVariant
uloc_minimizeSubtags
uloc_openKeywords()
uloc_openKeywords
uloc_setDefault
uloc_toLanguageTag
uloc_toLegacyKey
Expand Down
22 changes: 19 additions & 3 deletions rust_icu_uenum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ pub fn open_time_zones() -> Result<Enumeration, common::Error> {
}

#[doc(hidden)]
/// Implements `uloc_openKeywords`.
// This should be in the `uloc` crate, but this is not possible because of the raw enum
// initialization. Tested in `uloc`.
// This has been moved to the `uloc` crate
#[deprecated(since="4.2.4", note="please use `ULoc::open_keywords` instead")]
pub fn uloc_open_keywords(locale: &str) -> Result<Enumeration, common::Error> {
let mut status = common::Error::OK_CODE;
let asciiz_locale = ffi::CString::new(locale)?;
Expand Down Expand Up @@ -277,4 +276,21 @@ mod tests {
let e = Enumeration::try_from(&vec!["hello", "world", "💖", invalid_utf8][..]);
assert!(e.is_err(), "was: {:?}", e);
}

#[test]
fn test_uloc_open_keywords() -> Result<(), common::Error> {
let loc = "az-Cyrl-AZ-u-ca-hebrew-fw-sunday-nu-deva-tz-usnyc";
#[allow(deprecated)]
let keywords: Vec<String> = uloc_open_keywords(loc).unwrap().map(|result| result.unwrap()).collect();
assert_eq!(
keywords,
vec![
"calendar".to_string(),
"fw".to_string(),
"numbers".to_string(),
"timezone".to_string()
]
);
Ok(())
}
}
22 changes: 19 additions & 3 deletions rust_icu_uloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,30 @@ impl ULoc {
)
}

pub fn open_keywords(&self) -> Result<Enumeration, common::Error> {
let mut status = common::Error::OK_CODE;
let asciiz_locale = self.as_c_str();
let raw_enum = unsafe {
assert!(common::Error::is_ok(status));
versioned_function!(uloc_openKeywords)(asciiz_locale.as_ptr(), &mut status)
};
common::Error::ok_or_warning(status)?;
// "No error but null" means that there are no keywords
if raw_enum.is_null() {
Ok(Enumeration::empty())
} else {
Ok(unsafe { Enumeration::from_raw_parts(None, raw_enum) })
}
}

/// Implements `uloc_openKeywords()` from ICU4C.
pub fn keywords(&self) -> impl Iterator<Item = String> {
rust_icu_uenum::uloc_open_keywords(&self.repr)
self.open_keywords()
.unwrap()
.map(|result| result.unwrap())
}

/// Implements `icu::Locale::getUnicodeKeywords()` from the C++ API.
/// Implementation of `icu::Locale::getUnicodeKeywords()` from the C++ API.
pub fn unicode_keywords(&self) -> impl Iterator<Item = String> {
self.keywords().filter_map(|s| to_unicode_locale_key(&s))
}
Expand All @@ -447,7 +463,7 @@ impl ULoc {
.map(|value| if value.is_empty() { None } else { Some(value) })
}

/// Implements `icu::Locale::getUnicodeKeywordValue()` from ICU4C.
/// Implementation of `icu::Locale::getUnicodeKeywordValue()` from the C++ API.
pub fn unicode_keyword_value(
&self,
unicode_keyword: &str,
Expand Down
Loading