1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-07-15 01:24:27 +02:00

Split lines after newline

This commit is contained in:
mo8it
2025-07-04 23:17:25 +02:00
parent 9fecdba101
commit 1a633e2757
4 changed files with 33 additions and 11 deletions

View File

@ -134,7 +134,14 @@ mod tests {
); );
assert_eq!( assert_eq!(
updated_cargo_toml(&exercise_infos, "abc\nbin = [xxx]\n123", b"../").unwrap(), updated_cargo_toml(
&exercise_infos,
"abc\n\
bin = [xxx]\n\
123",
b"../"
)
.unwrap(),
br#"abc br#"abc
bin = [ bin = [
{ name = "1", path = "../exercises/1.rs" }, { name = "1", path = "../exercises/1.rs" },

View File

@ -106,13 +106,15 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {
if !file_buf.contains("fn main()") { if !file_buf.contains("fn main()") {
bail!( bail!(
"The `main` function is missing in the file `{path}`.\nCreate at least an empty `main` function to avoid language server errors" "The `main` function is missing in the file `{path}`.\n\
Create at least an empty `main` function to avoid language server errors"
); );
} }
if !file_buf.contains("// TODO") { if !file_buf.contains("// TODO") {
bail!( bail!(
"Didn't find any `// TODO` comment in the file `{path}`.\nYou need to have at least one such comment to guide the user." "Didn't find any `// TODO` comment in the file `{path}`.\n\
You need to have at least one such comment to guide the user."
); );
} }
@ -227,7 +229,10 @@ fn check_exercises_unsolved(
match result { match result {
Ok(true) => { Ok(true) => {
bail!("The exercise {exercise_name} is already solved.\n{SKIP_CHECK_UNSOLVED_HINT}",) bail!(
"The exercise {exercise_name} is already solved.\n\
{SKIP_CHECK_UNSOLVED_HINT}",
)
} }
Ok(false) => (), Ok(false) => (),
Err(e) => return Err(e), Err(e) => return Err(e),
@ -242,10 +247,12 @@ fn check_exercises_unsolved(
fn check_exercises(info_file: &'static InfoFile, cmd_runner: &'static CmdRunner) -> Result<()> { fn check_exercises(info_file: &'static InfoFile, cmd_runner: &'static CmdRunner) -> Result<()> {
match info_file.format_version.cmp(&CURRENT_FORMAT_VERSION) { match info_file.format_version.cmp(&CURRENT_FORMAT_VERSION) {
Ordering::Less => bail!( Ordering::Less => bail!(
"`format_version` < {CURRENT_FORMAT_VERSION} (supported version)\nPlease migrate to the latest format version" "`format_version` < {CURRENT_FORMAT_VERSION} (supported version)\n\
Please migrate to the latest format version"
), ),
Ordering::Greater => bail!( Ordering::Greater => bail!(
"`format_version` > {CURRENT_FORMAT_VERSION} (supported version)\nTry updating the Rustlings program" "`format_version` > {CURRENT_FORMAT_VERSION} (supported version)\n\
Try updating the Rustlings program"
), ),
Ordering::Equal => (), Ordering::Equal => (),
} }

View File

@ -58,11 +58,13 @@ pub fn init() -> Result<()> {
&& !workspace_manifest_content.contains("workspace.") && !workspace_manifest_content.contains("workspace.")
{ {
bail!( bail!(
"The current directory is already part of a Cargo project.\nPlease initialize Rustlings in a different directory" "The current directory is already part of a Cargo project.\n\
Please initialize Rustlings in a different directory"
); );
} }
stdout.write_all(b"This command will create the directory `rustlings/` as a member of this Cargo workspace.\nPress ENTER to continue ")?; stdout.write_all(b"This command will create the directory `rustlings/` as a member of this Cargo workspace.\n\
Press ENTER to continue ")?;
press_enter_prompt(&mut stdout)?; press_enter_prompt(&mut stdout)?;
// Make sure "rustlings" is added to `workspace.members` by making // Make sure "rustlings" is added to `workspace.members` by making
@ -78,7 +80,8 @@ pub fn init() -> Result<()> {
.status()?; .status()?;
if !status.success() { if !status.success() {
bail!( bail!(
"Failed to initialize a new Cargo workspace member.\nPlease initialize Rustlings in a different directory" "Failed to initialize a new Cargo workspace member.\n\
Please initialize Rustlings in a different directory"
); );
} }
@ -87,7 +90,8 @@ pub fn init() -> Result<()> {
.context("Failed to remove the temporary directory `rustlings/`")?; .context("Failed to remove the temporary directory `rustlings/`")?;
init_git = false; init_git = false;
} else { } else {
stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\nPress ENTER to continue ")?; stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\n\
Press ENTER to continue ")?;
press_enter_prompt(&mut stdout)?; press_enter_prompt(&mut stdout)?;
} }

View File

@ -104,7 +104,11 @@ fn main() -> Result<ExitCode> {
clear_terminal(&mut stdout)?; clear_terminal(&mut stdout)?;
let welcome_message = welcome_message.trim_ascii(); let welcome_message = welcome_message.trim_ascii();
write!(stdout, "{welcome_message}\n\nPress ENTER to continue ")?; write!(
stdout,
"{welcome_message}\n\n\
Press ENTER to continue "
)?;
press_enter_prompt(&mut stdout)?; press_enter_prompt(&mut stdout)?;
clear_terminal(&mut stdout)?; clear_terminal(&mut stdout)?;
// Flush to be able to show errors occurring before printing a newline to stdout. // Flush to be able to show errors occurring before printing a newline to stdout.