From 63819ada24864614f9db9228bc7006ca15892a1a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 13 Mar 2025 12:09:16 +0100 Subject: [PATCH] github/test: use `iter::repeat_n` to build example strings A recent change to Rust[1] started using `u16` as the size for width formatting internally. This ended up tripping the test code which uses width formatting to make a just-too-long string right at the `u16::MAX` threshold. Replace with iterator construction instead. Update the minimum to 1.82 where `iter::repeat_n` was stabilized. [1] https://github.com/rust-lang/rust/pull/136932 --- .gitlab-ci.yml | 2 +- ghostflow-github/src/ghostflow.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b73add5..70a75e6a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,7 +13,7 @@ stages: - test .rust_minimum: - image: "rust:1.81" + image: "rust:1.82" variables: CARGO_UPDATE_POLICY: newest diff --git a/ghostflow-github/src/ghostflow.rs b/ghostflow-github/src/ghostflow.rs index 8a801551..7b81d982 100644 --- a/ghostflow-github/src/ghostflow.rs +++ b/ghostflow-github/src/ghostflow.rs @@ -1395,6 +1395,8 @@ impl Debug for GithubService { #[cfg(test)] mod tests { + use std::iter; + use ghostflow::host::User; use crate::authorization::CurrentUser; @@ -1446,9 +1448,13 @@ mod tests { trim_to_check_run_limit, GITHUB_CHECK_RUN_MESSAGE_LIMIT, GITHUB_OVERFLOW_INDICATOR, }; - let just_short_enough = format!("{:width$}", 0, width = GITHUB_CHECK_RUN_MESSAGE_LIMIT); + let just_short_enough: String = iter::repeat_n(' ', GITHUB_CHECK_RUN_MESSAGE_LIMIT - 1) + .chain(iter::once('0')) + .collect(); assert_eq!(just_short_enough.len(), GITHUB_CHECK_RUN_MESSAGE_LIMIT); - let long_text = format!("{:width$}", 0, width = GITHUB_CHECK_RUN_MESSAGE_LIMIT + 1); + let long_text: String = iter::repeat_n(' ', GITHUB_CHECK_RUN_MESSAGE_LIMIT) + .chain(iter::once('0')) + .collect(); assert!(long_text.len() > GITHUB_CHECK_RUN_MESSAGE_LIMIT); let long_text_trimmed = format!( "{}{:width$}", -- GitLab