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

Run cargo check on more feature combinations #470

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ name: test
on:
push:
branches: [main, master]
paths: '**.rs'
paths:
- '**.rs'
- .github/**
pull_request:
branches: [main, master]
paths: '**.rs'
paths:
- '**.rs'
- .github/**

jobs:
test:
strategy:
matrix:
os: [ubuntu-16.04, ubuntu-latest, macos-latest, windows-latest]
rust_version: [stable]
exhaustive_tz: [onetz]
check_combinatoric: [no_combinatoric]
include:
# check all tzs on most-recent OS's
- os: ubuntu-latest
Expand All @@ -25,6 +31,10 @@ jobs:
- os: macos-latest
rust_version: stable
exhaustive_tz: all_tzs
# compilation check
- os: ubuntu-latest
rust_version: stable
check_combinatoric: 'combinatoric'
# test other rust versions
- os: ubuntu-latest
rust_version: beta
Expand Down Expand Up @@ -52,6 +62,7 @@ jobs:
env:
RUST_VERSION: ${{ matrix.rust_version }}
EXHAUSTIVE_TZ: ${{ matrix.exhaustive_tz }}
CHECK_COMBINATORIC: ${{ matrix.check_combinatoric }}

no_std:
strategy:
Expand Down
12 changes: 12 additions & 0 deletions ci/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source "${BASH_SOURCE[0]%/*}/_shlib.sh"

TEST_TZS=(ACST-9:30 EST4 UTC0 Asia/Katmandu)
FEATURES=(std serde clock "alloc serde" unstable-locales)
CHECK_FEATURES=(alloc "std unstable-locales" "serde clock" "clock unstable-locales")
RUST_113_FEATURES=(rustc-serialize serde)

main() {
Expand All @@ -21,6 +22,7 @@ meaningful in the github actions feature matrix UI.
WASM Empty or 'yes_wasm'
CORE 'std' or 'no_std'
EXHAUSTIVE_TZ Emptly or 'all_tzs'
CHECK_COMBINATORIC Combine various features and verify that we compile
"
exit
fi
Expand All @@ -36,6 +38,8 @@ meaningful in the github actions feature matrix UI.
test_core
elif [[ ${EXHAUSTIVE_TZ:-} == all_tzs ]]; then
test_all_tzs
elif [[ ${CHECK_COMBINATORIC:-} == combinatoric ]]; then
check_combinatoric
else
test_regular UTC0
fi
Expand All @@ -62,6 +66,14 @@ test_regular() {
done
}

check_combinatoric() {
runt cargo check --no-default-features
runt cargo check --all-features
for feature in "${CHECK_FEATURES[@]}"; do
runt cargo check --no-default-features --features "$feature" --lib --color=always
done
}

test_113() {
runv cargo build --color=always
for feature in "${RUST_113_FEATURES[@]}"; do
Expand Down
88 changes: 43 additions & 45 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,47 +410,42 @@ fn format_inner<'a>(
_locale: Option<Locale>,
) -> fmt::Result {
#[cfg(feature = "unstable-locales")]
let locale = _locale.unwrap_or(Locale::POSIX);

#[cfg(feature = "unstable-locales")]
let short_months = locales::short_months(locale);
#[cfg(feature = "unstable-locales")]
let long_months = locales::long_months(locale);
#[cfg(feature = "unstable-locales")]
let short_weekdays = locales::short_weekdays(locale);
#[cfg(feature = "unstable-locales")]
let long_weekdays = locales::long_weekdays(locale);
#[cfg(feature = "unstable-locales")]
let am_pm = locales::am_pm(locale);

#[cfg(not(feature = "unstable-locales"))]
let short_months =
&["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
#[cfg(not(feature = "unstable-locales"))]
let long_months = &[
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
#[cfg(not(feature = "unstable-locales"))]
let short_weekdays = &["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
#[cfg(not(feature = "unstable-locales"))]
let long_weekdays =
&["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let (short_months, long_months, short_weekdays, long_weekdays, am_pm, am_pm_lowercase) = {
let locale = _locale.unwrap_or(Locale::POSIX);
let am_pm = locales::am_pm(locale);
(
locales::short_months(locale),
locales::long_months(locale),
locales::short_weekdays(locale),
locales::long_weekdays(locale),
am_pm,
&[am_pm[0].to_lowercase(), am_pm[1].to_lowercase()],
)
};
#[cfg(not(feature = "unstable-locales"))]
let am_pm = &["AM", "PM"];

let am_pm_lowercase: Vec<_> = am_pm.iter().map(|x| x.to_lowercase()).collect();
let am_pm_lowercase = &[am_pm_lowercase[0].as_str(), am_pm_lowercase[1].as_str()];
let (short_months, long_months, short_weekdays, long_weekdays, am_pm, am_pm_lowercase) = {
(
&["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
&[
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
],
&["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
&["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
&["AM", "PM"],
&["am", "pm"],
)
};

use core::fmt::Write;
use div::{div_floor, mod_floor};
Expand Down Expand Up @@ -570,11 +565,14 @@ fn format_inner<'a>(
Ok(())
}),
LowerAmPm => time.map(|t| {
result.push_str(if t.hour12().0 {
am_pm_lowercase[1]
} else {
am_pm_lowercase[0]
});
#[cfg_attr(feature = "cargo-clippy", allow(useless_asref))]
{
result.push_str(if t.hour12().0 {
am_pm_lowercase[1].as_ref()
} else {
am_pm_lowercase[0].as_ref()
});
}
Ok(())
}),
UpperAmPm => time.map(|t| {
Expand Down