mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-23 06:02:23 -05:00
Fix tests
This commit is contained in:
parent
65a8f6bb4b
commit
3fc462f90f
4 changed files with 27 additions and 35 deletions
|
@ -25,10 +25,13 @@ fn forbidden_char(input: &str) -> Option<char> {
|
||||||
// Check that the Cargo.toml file is up-to-date.
|
// Check that the Cargo.toml file is up-to-date.
|
||||||
fn check_cargo_toml(
|
fn check_cargo_toml(
|
||||||
exercise_infos: &[ExerciseInfo],
|
exercise_infos: &[ExerciseInfo],
|
||||||
current_cargo_toml: &str,
|
cargo_toml_path: &str,
|
||||||
exercise_path_prefix: &[u8],
|
exercise_path_prefix: &[u8],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (bins_start_ind, bins_end_ind) = bins_start_end_ind(current_cargo_toml)?;
|
let current_cargo_toml = fs::read_to_string(cargo_toml_path)
|
||||||
|
.with_context(|| format!("Failed to read the file `{cargo_toml_path}`"))?;
|
||||||
|
|
||||||
|
let (bins_start_ind, bins_end_ind) = bins_start_end_ind(¤t_cargo_toml)?;
|
||||||
|
|
||||||
let old_bins = ¤t_cargo_toml.as_bytes()[bins_start_ind..bins_end_ind];
|
let old_bins = ¤t_cargo_toml.as_bytes()[bins_start_ind..bins_end_ind];
|
||||||
let mut new_bins = Vec::with_capacity(BINS_BUFFER_CAPACITY);
|
let mut new_bins = Vec::with_capacity(BINS_BUFFER_CAPACITY);
|
||||||
|
@ -305,15 +308,9 @@ pub fn check(require_solutions: bool) -> Result<()> {
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
// A hack to make `cargo run -- dev check` work when developing Rustlings.
|
// A hack to make `cargo run -- dev check` work when developing Rustlings.
|
||||||
check_cargo_toml(
|
check_cargo_toml(&info_file.exercises, "dev/Cargo.toml", b"../")?;
|
||||||
&info_file.exercises,
|
|
||||||
include_str!("../../dev-Cargo.toml"),
|
|
||||||
b"../",
|
|
||||||
)?;
|
|
||||||
} else {
|
} else {
|
||||||
let current_cargo_toml =
|
check_cargo_toml(&info_file.exercises, "Cargo.toml", b"")?;
|
||||||
fs::read_to_string("Cargo.toml").context("Failed to read the file `Cargo.toml`")?;
|
|
||||||
check_cargo_toml(&info_file.exercises, ¤t_cargo_toml, b"")?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmd_runner = CmdRunner::build()?;
|
let cmd_runner = CmdRunner::build()?;
|
||||||
|
|
|
@ -9,12 +9,14 @@ use crate::{
|
||||||
// Update the `Cargo.toml` file.
|
// Update the `Cargo.toml` file.
|
||||||
fn update_cargo_toml(
|
fn update_cargo_toml(
|
||||||
exercise_infos: &[ExerciseInfo],
|
exercise_infos: &[ExerciseInfo],
|
||||||
current_cargo_toml: &str,
|
|
||||||
exercise_path_prefix: &[u8],
|
|
||||||
cargo_toml_path: &str,
|
cargo_toml_path: &str,
|
||||||
|
exercise_path_prefix: &[u8],
|
||||||
) -> Result<()> {
|
) -> 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 =
|
let updated_cargo_toml =
|
||||||
updated_cargo_toml(exercise_infos, current_cargo_toml, exercise_path_prefix)?;
|
updated_cargo_toml(exercise_infos, ¤t_cargo_toml, exercise_path_prefix)?;
|
||||||
|
|
||||||
fs::write(cargo_toml_path, updated_cargo_toml)
|
fs::write(cargo_toml_path, updated_cargo_toml)
|
||||||
.context("Failed to write the `Cargo.toml` file")?;
|
.context("Failed to write the `Cargo.toml` file")?;
|
||||||
|
@ -25,21 +27,14 @@ fn update_cargo_toml(
|
||||||
pub fn update() -> Result<()> {
|
pub fn update() -> Result<()> {
|
||||||
let info_file = InfoFile::parse()?;
|
let info_file = InfoFile::parse()?;
|
||||||
|
|
||||||
// A hack to make `cargo run -- dev update` work when developing Rustlings.
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
update_cargo_toml(
|
// A hack to make `cargo run -- dev update` work when developing Rustlings.
|
||||||
&info_file.exercises,
|
update_cargo_toml(&info_file.exercises, "dev/Cargo.toml", b"../")
|
||||||
include_str!("../../dev-Cargo.toml"),
|
|
||||||
b"../",
|
|
||||||
"dev/Cargo.toml",
|
|
||||||
)
|
|
||||||
.context("Failed to update the file `dev/Cargo.toml`")?;
|
.context("Failed to update the file `dev/Cargo.toml`")?;
|
||||||
|
|
||||||
println!("Updated `dev/Cargo.toml`");
|
println!("Updated `dev/Cargo.toml`");
|
||||||
} else {
|
} else {
|
||||||
let current_cargo_toml =
|
update_cargo_toml(&info_file.exercises, "Cargo.toml", &[])
|
||||||
fs::read_to_string("Cargo.toml").context("Failed to read the file `Cargo.toml`")?;
|
|
||||||
update_cargo_toml(&info_file.exercises, ¤t_cargo_toml, b"", "Cargo.toml")
|
|
||||||
.context("Failed to update the file `Cargo.toml`")?;
|
.context("Failed to update the file `Cargo.toml`")?;
|
||||||
|
|
||||||
println!("Updated `Cargo.toml`");
|
println!("Updated `Cargo.toml`");
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
bin = [
|
|
||||||
{ name = "compilation_success", path = "exercises/compilation_success.rs" },
|
|
||||||
{ name = "compilation_failure", path = "exercises/compilation_failure.rs" },
|
|
||||||
{ name = "test_success", path = "exercises/test_success.rs" },
|
|
||||||
{ name = "test_failure", path = "exercises/test_failure.rs" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[package]
|
|
||||||
name = "test_exercises"
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
11
tests/test_exercises/dev/Cargo.toml
Normal file
11
tests/test_exercises/dev/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
bin = [
|
||||||
|
{ name = "compilation_success", path = "../exercises/compilation_success.rs" },
|
||||||
|
{ name = "compilation_failure", path = "../exercises/compilation_failure.rs" },
|
||||||
|
{ name = "test_success", path = "../exercises/test_success.rs" },
|
||||||
|
{ name = "test_failure", path = "../exercises/test_failure.rs" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "test_exercises"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
Loading…
Reference in a new issue