summaryrefslogtreecommitdiff
path: root/src/dev/update.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-08-01 19:17:40 +0200
committermo8it <mo8it@proton.me>2024-08-01 19:17:40 +0200
commit3fc462f90fec10cfacd3d81e944b11bb776a2941 (patch)
tree28eddbb8a9ddf05d505bd52d46eeac5a87ac020f /src/dev/update.rs
parent65a8f6bb4b542a24bf80265cf5080b5c8f51fb7e (diff)
Fix tests
Diffstat (limited to 'src/dev/update.rs')
-rw-r--r--src/dev/update.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/dev/update.rs b/src/dev/update.rs
index 680d302..6de3c8f 100644
--- a/src/dev/update.rs
+++ b/src/dev/update.rs
@@ -9,12 +9,14 @@ use crate::{
// Update the `Cargo.toml` file.
fn update_cargo_toml(
exercise_infos: &[ExerciseInfo],
- current_cargo_toml: &str,
- exercise_path_prefix: &[u8],
cargo_toml_path: &str,
+ exercise_path_prefix: &[u8],
) -> Result<()> {
+ let current_cargo_toml = fs::read_to_string(cargo_toml_path)
+ .with_context(|| format!("Failed to read the file `{cargo_toml_path}`"))?;
+
let updated_cargo_toml =
- updated_cargo_toml(exercise_infos, current_cargo_toml, exercise_path_prefix)?;
+ updated_cargo_toml(exercise_infos, &current_cargo_toml, exercise_path_prefix)?;
fs::write(cargo_toml_path, updated_cargo_toml)
.context("Failed to write the `Cargo.toml` file")?;
@@ -25,21 +27,14 @@ fn update_cargo_toml(
pub fn update() -> Result<()> {
let info_file = InfoFile::parse()?;
- // A hack to make `cargo run -- dev update` work when developing Rustlings.
if cfg!(debug_assertions) {
- update_cargo_toml(
- &info_file.exercises,
- include_str!("../../dev-Cargo.toml"),
- b"../",
- "dev/Cargo.toml",
- )
- .context("Failed to update the file `dev/Cargo.toml`")?;
+ // A hack to make `cargo run -- dev update` work when developing Rustlings.
+ update_cargo_toml(&info_file.exercises, "dev/Cargo.toml", b"../")
+ .context("Failed to update the file `dev/Cargo.toml`")?;
println!("Updated `dev/Cargo.toml`");
} else {
- let current_cargo_toml =
- fs::read_to_string("Cargo.toml").context("Failed to read the file `Cargo.toml`")?;
- update_cargo_toml(&info_file.exercises, &current_cargo_toml, b"", "Cargo.toml")
+ update_cargo_toml(&info_file.exercises, "Cargo.toml", &[])
.context("Failed to update the file `Cargo.toml`")?;
println!("Updated `Cargo.toml`");