From 43dc31193afddc15c78d2ceb57f7c68da90e8a46 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Thu, 20 Feb 2020 20:11:53 +0100 Subject: [PATCH 1/8] refactor: exercise evaluation Exercise evaluation (compilation + execution) now uses Results Success/failure messages are standardized --- src/exercise.rs | 76 ++++++++++++++++++++++++++++------ src/main.rs | 3 ++ src/run.rs | 54 ++++++++++++------------ src/ui.rs | 23 +++++++++++ src/verify.rs | 106 ++++++++++++++++++++++++------------------------ 5 files changed, 168 insertions(+), 94 deletions(-) create mode 100644 src/ui.rs diff --git a/src/exercise.rs b/src/exercise.rs index b6c28da4..d72eeb50 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Display, Formatter}; use std::fs::{remove_file, File}; use std::io::Read; use std::path::PathBuf; -use std::process::{self, Command, Output}; +use std::process::{self, Command}; const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE"; @@ -47,9 +47,34 @@ pub struct ContextLine { pub important: bool, } +pub struct CompiledExercise<'a> { + exercise: &'a Exercise, + _handle: FileHandle, +} + +impl<'a> CompiledExercise<'a> { + pub fn run(&self) -> Result { + self.exercise.run() + } +} + +#[derive(Debug)] +pub struct ExerciseOutput { + pub stdout: String, + pub stderr: String, +} + +struct FileHandle; + +impl Drop for FileHandle { + fn drop(&mut self) { + clean(); + } +} + impl Exercise { - pub fn compile(&self) -> Output { - match self.mode { + pub fn compile(&self) -> Result { + let cmd = match self.mode { Mode::Compile => Command::new("rustc") .args(&[self.path.to_str().unwrap(), "-o", &temp_file()]) .args(RUSTC_COLOR_ARGS) @@ -59,17 +84,37 @@ impl Exercise { .args(RUSTC_COLOR_ARGS) .output(), } - .expect("Failed to run 'compile' command.") + .expect("Failed to run 'compile' command."); + + if cmd.status.success() { + Ok(CompiledExercise { + exercise: &self, + _handle: FileHandle, + }) + } else { + clean(); + Err(ExerciseOutput { + stdout: String::from_utf8_lossy(&cmd.stdout).to_string(), + stderr: String::from_utf8_lossy(&cmd.stderr).to_string(), + }) + } } - pub fn run(&self) -> Output { - Command::new(&temp_file()) + fn run(&self) -> Result { + let cmd = Command::new(&temp_file()) .output() - .expect("Failed to run 'run' command") - } + .expect("Failed to run 'run' command"); - pub fn clean(&self) { - let _ignored = remove_file(&temp_file()); + let output = ExerciseOutput { + stdout: String::from_utf8_lossy(&cmd.stdout).to_string(), + stderr: String::from_utf8_lossy(&cmd.stderr).to_string(), + }; + + if cmd.status.success() { + Ok(output) + } else { + Err(output) + } } pub fn state(&self) -> State { @@ -121,6 +166,10 @@ impl Display for Exercise { } } +fn clean() { + let _ignored = remove_file(&temp_file()); +} + #[cfg(test)] mod test { use super::*; @@ -131,11 +180,12 @@ mod test { File::create(&temp_file()).unwrap(); let exercise = Exercise { name: String::from("example"), - path: PathBuf::from("example.rs"), - mode: Mode::Test, + path: PathBuf::from("tests/fixture/state/pending_exercise.rs"), + mode: Mode::Compile, hint: String::from(""), }; - exercise.clean(); + let compiled = exercise.compile().unwrap(); + drop(compiled); assert!(!Path::new(&temp_file()).exists()); } diff --git a/src/main.rs b/src/main.rs index dd060aca..4fd60831 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,9 @@ use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; +#[macro_use] +mod ui; + mod exercise; mod run; mod verify; diff --git a/src/run.rs b/src/run.rs index 1484351a..cfde7ab6 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,6 +1,5 @@ use crate::exercise::{Exercise, Mode}; use crate::verify::test; -use console::{style, Emoji}; use indicatif::ProgressBar; pub fn run(exercise: &Exercise) -> Result<(), ()> { @@ -11,42 +10,41 @@ pub fn run(exercise: &Exercise) -> Result<(), ()> { Ok(()) } -pub fn compile_and_run(exercise: &Exercise) -> Result<(), ()> { +fn compile_and_run(exercise: &Exercise) -> Result<(), ()> { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); - let compilecmd = exercise.compile(); + let compilation_result = exercise.compile(); + let compilation = match compilation_result { + Ok(compilation) => compilation, + Err(output) => { + progress_bar.finish_and_clear(); + warn!( + "Compilation of {} failed!, Compiler error message:\n", + exercise + ); + println!("{}", output.stderr); + return Err(()); + } + }; + progress_bar.set_message(format!("Running {}...", exercise).as_str()); - if compilecmd.status.success() { - let runcmd = exercise.run(); - progress_bar.finish_and_clear(); + let result = compilation.run(); + progress_bar.finish_and_clear(); - if runcmd.status.success() { - println!("{}", String::from_utf8_lossy(&runcmd.stdout)); - let formatstr = format!("{} Successfully ran {}", Emoji("✅", "✓"), exercise); - println!("{}", style(formatstr).green()); - exercise.clean(); + match result { + Ok(output) => { + println!("{}", output.stdout); + success!("Successfully ran {}", exercise); Ok(()) - } else { - println!("{}", String::from_utf8_lossy(&runcmd.stdout)); - println!("{}", String::from_utf8_lossy(&runcmd.stderr)); + } + Err(output) => { + println!("{}", output.stdout); + println!("{}", output.stderr); - let formatstr = format!("{} Ran {} with errors", Emoji("⚠️ ", "!"), exercise); - println!("{}", style(formatstr).red()); - exercise.clean(); + warn!("Ran {} with errors", exercise); Err(()) } - } else { - progress_bar.finish_and_clear(); - let formatstr = format!( - "{} Compilation of {} failed! Compiler error message:\n", - Emoji("⚠️ ", "!"), - exercise - ); - println!("{}", style(formatstr).red()); - println!("{}", String::from_utf8_lossy(&compilecmd.stderr)); - exercise.clean(); - Err(()) } } diff --git a/src/ui.rs b/src/ui.rs new file mode 100644 index 00000000..38cbaa40 --- /dev/null +++ b/src/ui.rs @@ -0,0 +1,23 @@ +macro_rules! warn { + ($fmt:literal, $ex:expr) => {{ + use console::{style, Emoji}; + let formatstr = format!($fmt, $ex); + println!( + "{} {}", + style(Emoji("⚠️ ", "!")).red(), + style(formatstr).red() + ); + }}; +} + +macro_rules! success { + ($fmt:literal, $ex:expr) => {{ + use console::{style, Emoji}; + let formatstr = format!($fmt, $ex); + println!( + "{} {}", + style(Emoji("✅", "✓")).green(), + style(formatstr).green() + ); + }}; +} diff --git a/src/verify.rs b/src/verify.rs index 3796bbde..3d148960 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,11 +1,11 @@ use crate::exercise::{Exercise, Mode, State}; -use console::{style, Emoji}; +use console::style; use indicatif::ProgressBar; pub fn verify<'a>(start_at: impl IntoIterator) -> Result<(), &'a Exercise> { for exercise in start_at { let compile_result = match exercise.mode { - Mode::Test => compile_and_test_interactively(&exercise), + Mode::Test => compile_and_test(&exercise, RunMode::Interactive), Mode::Compile => compile_only(&exercise), }; if !compile_result.unwrap_or(false) { @@ -15,8 +15,13 @@ pub fn verify<'a>(start_at: impl IntoIterator) -> Result<() Ok(()) } +enum RunMode { + Interactive, + NonInteractive, +} + pub fn test(exercise: &Exercise) -> Result<(), ()> { - compile_and_test(exercise, true)?; + compile_and_test(exercise, RunMode::NonInteractive)?; Ok(()) } @@ -24,69 +29,64 @@ fn compile_only(exercise: &Exercise) -> Result { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); - let compile_output = exercise.compile(); + let compilation_result = exercise.compile(); progress_bar.finish_and_clear(); - if compile_output.status.success() { - let formatstr = format!("{} Successfully compiled {}!", Emoji("✅", "✓"), exercise); - println!("{}", style(formatstr).green()); - exercise.clean(); - Ok(prompt_for_completion(&exercise)) - } else { - let formatstr = format!( - "{} Compilation of {} failed! Compiler error message:\n", - Emoji("⚠️ ", "!"), - exercise - ); - println!("{}", style(formatstr).red()); - println!("{}", String::from_utf8_lossy(&compile_output.stderr)); - exercise.clean(); - Err(()) + + match compilation_result { + Ok(_) => { + success!("Successfully compiled {}!", exercise); + Ok(prompt_for_completion(&exercise)) + } + Err(output) => { + warn!( + "Compilation of {} failed! Compiler error message:\n", + exercise + ); + println!("{}", output.stderr); + Err(()) + } } } -fn compile_and_test_interactively(exercise: &Exercise) -> Result { - compile_and_test(exercise, false) -} - -fn compile_and_test(exercise: &Exercise, skip_prompt: bool) -> Result { +fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Testing {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); - let compile_output = exercise.compile(); - if compile_output.status.success() { - progress_bar.set_message(format!("Running {}...", exercise).as_str()); + let compilation_result = exercise.compile(); - let runcmd = exercise.run(); - progress_bar.finish_and_clear(); - - if runcmd.status.success() { - let formatstr = format!("{} Successfully tested {}!", Emoji("✅", "✓"), exercise); - println!("{}", style(formatstr).green()); - exercise.clean(); - Ok(skip_prompt || prompt_for_completion(exercise)) - } else { - let formatstr = format!( - "{} Testing of {} failed! Please try again. Here's the output:", - Emoji("⚠️ ", "!"), + let compilation = match compilation_result { + Ok(compilation) => compilation, + Err(output) => { + progress_bar.finish_and_clear(); + warn!( + "Compiling of {} failed! Please try again. Here's the output:", exercise ); - println!("{}", style(formatstr).red()); - println!("{}", String::from_utf8_lossy(&runcmd.stdout)); - exercise.clean(); + println!("{}", output.stderr); + return Err(()); + } + }; + + let result = compilation.run(); + progress_bar.finish_and_clear(); + + match result { + Ok(_) => { + if let RunMode::Interactive = run_mode { + Ok(prompt_for_completion(&exercise)) + } else { + Ok(true) + } + } + Err(output) => { + warn!( + "Testing of {} failed! Please try again. Here's the output:", + exercise + ); + println!("{}", output.stdout); Err(()) } - } else { - progress_bar.finish_and_clear(); - let formatstr = format!( - "{} Compiling of {} failed! Please try again. Here's the output:", - Emoji("⚠️ ", "!"), - exercise - ); - println!("{}", style(formatstr).red()); - println!("{}", String::from_utf8_lossy(&compile_output.stderr)); - exercise.clean(); - Err(()) } } From 8b971ffab6079a706ac925f5917f987932b55c07 Mon Sep 17 00:00:00 2001 From: Stig Johan Berggren Date: Tue, 25 Feb 2020 14:13:10 +0100 Subject: [PATCH 2/8] Enable test for exercise test4 --- exercises/test4.rs | 11 ++++++++--- info.toml | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/exercises/test4.rs b/exercises/test4.rs index c543a648..f3875cfb 100644 --- a/exercises/test4.rs +++ b/exercises/test4.rs @@ -7,8 +7,13 @@ // I AM NOT DONE -fn main() { - if my_macro!("world!") != "Hello world!" { - panic!("Oh no! Wrong output!"); +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_my_macro() { + assert_eq!(my_macro!("world!"), "Hello world!"); } } + diff --git a/info.toml b/info.toml index 2e6b0b41..4b89029c 100644 --- a/info.toml +++ b/info.toml @@ -369,7 +369,7 @@ The way macros are written, it wants to see something between each [[exercises]] name = "test4" path = "exercises/test4.rs" -mode = "compile" +mode = "test" hint = "No hints this time ;)" # MOVE SEMANTICS From a45486f2d05ce1081fab5709f629ae765368509b Mon Sep 17 00:00:00 2001 From: Stig Johan Berggren Date: Tue, 25 Feb 2020 14:18:31 +0100 Subject: [PATCH 3/8] Add a second test case --- exercises/test4.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exercises/test4.rs b/exercises/test4.rs index f3875cfb..ad1f6ac5 100644 --- a/exercises/test4.rs +++ b/exercises/test4.rs @@ -12,8 +12,12 @@ mod tests { use super::*; #[test] - fn test_my_macro() { + fn test_my_macro_world() { assert_eq!(my_macro!("world!"), "Hello world!"); } -} + #[test] + fn test_my_macro_goodbye() { + assert_eq!(my_macro!("goodbye!"), "Hello goodbye!"); + } +} From 6eb62fa2cef6fecebbcb5bc5ac3bd1676fe04fe1 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 25 Feb 2020 23:00:19 +0100 Subject: [PATCH 4/8] 2.2.0 --- CHANGELOG.md | 30 ++++++++++ Cargo.lock | 153 +++++++++++++++++++-------------------------------- Cargo.toml | 2 +- README.md | 2 +- 4 files changed, 88 insertions(+), 99 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d54cbdf..6c20aede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ + +## 2.2.0 (2020-02-25) + + +#### Bug Fixes + +* Update deps to version compatable with aarch64-pc-windows (#263) ([19a93428](https://github.com/rust-lang/rustlings/commit/19a93428b3c73d994292671f829bdc8e5b7b3401)) +* **docs:** + * Added a necessary step to Windows installation process (#242) ([3906efcd](https://github.com/rust-lang/rustlings/commit/3906efcd52a004047b460ed548037093de3f523f)) + * Fixed mangled sentence from book; edited for clarity (#266) ([ade52ff](https://github.com/rust-lang/rustlings/commit/ade52ffb739987287ddd5705944c8777705faed9)) + * Updated iterators readme to account for iterators4 exercise (#273) ([bec8e3a](https://github.com/rust-lang/rustlings/commit/bec8e3a644cbd88db1c73ea5f1d8a364f4a34016)) +* **installation:** make fatal errors more obvious (#272) ([17d0951e](https://github.com/rust-lang/rustlings/commit/17d0951e66fda8e11b204d5c4c41a0d5e22e78f7)) +* **iterators2:** + * Remove reference to missing iterators2.rs (#245) ([419f7797](https://github.com/rust-lang/rustlings/commit/419f7797f294e4ce6a2b883199731b5bde77d262)) +* **as_ref_mut:** Enable a test and improve per clippy's suggestion (#256) ([dfdf809](https://github.com/rust-lang/rustlings/commit/dfdf8093ebbd4145864995627b812780de52f902)) +* **tests1:** + * Change test command ([fe10e06c](https://github.com/rust-lang/rustlings/commit/fe10e06c3733ddb4a21e90d09bf79bfe618e97ce) + * Correct test command in tests1.rs comment (#263) ([39fa7ae](https://github.com/rust-lang/rustlings/commit/39fa7ae8b70ad468da49b06f11b2383135a63bcf)) + +#### Features + +* Add variables5.rs exercise (#264) ([0c73609e](https://github.com/rust-lang/rustlings/commit/0c73609e6f2311295e95d6f96f8c747cfc4cba03)) +* Show a completion message when watching (#253) ([d25ee55a](https://github.com/rust-lang/rustlings/commit/d25ee55a3205882d35782e370af855051b39c58c)) +* Add type conversion and parsing exercises (#249) ([0c85dc11](https://github.com/rust-lang/rustlings/commit/0c85dc1193978b5165491b99cc4922caf8d14a65)) +* Created consistent money unit (#258) ([fd57f8f](https://github.com/rust-lang/rustlings/commit/fd57f8f2c1da2af8ddbebbccec214e6f40f4dbab)) +* Enable test for exercise test4 (#276) ([8b971ff](https://github.com/rust-lang/rustlings/commit/8b971ffab6079a706ac925f5917f987932b55c07)) +* Added traits exercises (#274 but specifically #216, which originally added + this :heart:) ([b559cdd](https://github.com/rust-lang/rustlings/commit/b559cdd73f32c0d0cfc1feda39f82b3e3583df17)) + + ## 2.1.0 (2019-11-27) diff --git a/Cargo.lock b/Cargo.lock index af159a82..9cbe5a1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,13 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "aho-corasick" -version = "0.6.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "aho-corasick" version = "0.7.3" @@ -21,7 +13,7 @@ name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -42,7 +34,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -74,17 +66,6 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clicolors-control" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "clicolors-control" version = "1.0.0" @@ -93,7 +74,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -106,23 +87,7 @@ dependencies = [ [[package]] name = "console" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "clicolors-control 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "console" -version = "0.7.5" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -134,7 +99,22 @@ dependencies = [ "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "console" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -219,18 +199,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "indicatif" -version = "0.9.0" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "console 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "inotify" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -269,11 +250,6 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "lazy_static" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "lazy_static" version = "1.3.0" @@ -356,7 +332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -366,20 +342,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "notify" -version = "4.0.12" +version = "4.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -390,6 +365,14 @@ dependencies = [ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "number_prefix" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "numtoa" version = "0.1.0" @@ -417,7 +400,7 @@ dependencies = [ "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -477,7 +460,7 @@ dependencies = [ "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -525,7 +508,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -538,7 +521,7 @@ dependencies = [ "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -579,18 +562,6 @@ dependencies = [ "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex" version = "1.1.6" @@ -603,14 +574,6 @@ dependencies = [ "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex-syntax" version = "0.6.6" @@ -629,14 +592,14 @@ dependencies = [ [[package]] name = "rustlings" -version = "2.1.0" +version = "2.2.0" dependencies = [ "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "notify 4.0.12 (registry+https://github.com/rust-lang/crates.io-index)", + "indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", @@ -806,7 +769,7 @@ version = "2.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -817,7 +780,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -839,7 +802,7 @@ name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -857,7 +820,6 @@ dependencies = [ ] [metadata] -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" "checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2dc477793bd82ec39799b6f6b3df64938532fdf2ab0d49ef817eac65856a5a1e" @@ -866,11 +828,10 @@ dependencies = [ "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum clicolors-control 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f84dec9bc083ce2503908cd305af98bd363da6f54bf8d4bf0ac14ee749ad5d1" "checksum clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd48adf136733979b49e15bc3b4c43cc0d3c85ece7bd08e6daa414c6fcb13e6" -"checksum console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2bf3720d3f3fc30b721ef1ae54e13af3264af4af39dc476a8de56a6ee1e2184b" +"checksum console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628" +"checksum console 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b147390a412132d75d10dd3b7b175a69cf5fd95032f7503c7091b8831ba10242" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" "checksum escargot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ceb9adbf9874d5d028b5e4c5739d22b71988252b25c9c98fe7cf9738bee84597" @@ -882,13 +843,12 @@ dependencies = [ "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -"checksum indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a29b2fa6f00010c268bface64c18bb0310aaa70d46a195d5382d288c477fb016" -"checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718" +"checksum indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" +"checksum inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8" "checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" @@ -900,8 +860,9 @@ dependencies = [ "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" -"checksum notify 4.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "3572d71f13ea8ed41867accd971fd564aa75934cf7a1fae03ddb8c74a8a49943" +"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" +"checksum number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" "checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" @@ -923,9 +884,7 @@ dependencies = [ "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" "checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" -"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" @@ -953,7 +912,7 @@ dependencies = [ "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" diff --git a/Cargo.toml b/Cargo.toml index 33a17a38..f9f6073d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "2.1.0" +version = "2.2.0" authors = ["Marisa ", "Carol (Nichols || Goulding) Date: Wed, 26 Feb 2020 10:43:13 +0000 Subject: [PATCH 5/8] chore: update gitignore to ignore pdb files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 52fe4a79..4cf87f2f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target/ **/*.rs.bk .DS_Store +*.pdb \ No newline at end of file From 1e2fd9c92f8cd6e389525ca1a999fca4c90b5921 Mon Sep 17 00:00:00 2001 From: Mario Reder Date: Fri, 14 Feb 2020 15:25:03 +0100 Subject: [PATCH 6/8] feat: Add clippy lints - adds a new 'clippy' category for exercises - clippy exercises should throw no warnings - install script now also installs clippy is related to https://github.com/rust-lang/rust-clippy/issues/2604 --- .gitignore | 4 +++- exercises/clippy/README.md | 8 ++++++++ exercises/clippy/clippy1.rs | 15 +++++++++++++++ exercises/clippy/clippy2.rs | 13 +++++++++++++ info.toml | 16 ++++++++++++++++ install.ps1 | 13 +++++++++---- install.sh | 21 ++++++++++++--------- src/exercise.rs | 32 +++++++++++++++++++++++++++++++- src/run.rs | 1 + src/verify.rs | 2 ++ 10 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 exercises/clippy/README.md create mode 100644 exercises/clippy/clippy1.rs create mode 100644 exercises/clippy/clippy2.rs diff --git a/.gitignore b/.gitignore index 4cf87f2f..de87c1e7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ target/ **/*.rs.bk .DS_Store -*.pdb \ No newline at end of file +*.pdb +exercises/clippy/Cargo.toml +exercises/clippy/Cargo.lock diff --git a/exercises/clippy/README.md b/exercises/clippy/README.md new file mode 100644 index 00000000..60a12fe5 --- /dev/null +++ b/exercises/clippy/README.md @@ -0,0 +1,8 @@ +### Clippy + +The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code. + +If you used the installation script for Rustlings, Clippy should be already installed. +If not you can install it manually via `rustup component add clippy`. + +For more information about Clippy lints, please see [their documentation page](https://rust-lang.github.io/rust-clippy/master/). diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs new file mode 100644 index 00000000..2b4c6354 --- /dev/null +++ b/exercises/clippy/clippy1.rs @@ -0,0 +1,15 @@ +// clippy1.rs +// The Clippy tool is a collection of lints to analyze your code +// so you can catch common mistakes and improve your Rust code. +// +// Execute `rustlings hint clippy1` for hints :) + +// I AM NOT DONE + +fn main() { + let x = 1.2331f64; + let y = 1.2332f64; + if y != x { + println!("Success!"); + } +} diff --git a/exercises/clippy/clippy2.rs b/exercises/clippy/clippy2.rs new file mode 100644 index 00000000..37af9ed0 --- /dev/null +++ b/exercises/clippy/clippy2.rs @@ -0,0 +1,13 @@ +// clippy2.rs +// Make me compile! Execute `rustlings hint clippy2` for hints :) + +// I AM NOT DONE + +fn main() { + let mut res = 42; + let option = Some(12); + for x in option { + res += x; + } + println!("{}", res); +} diff --git a/info.toml b/info.toml index b1c6db53..82c22b7a 100644 --- a/info.toml +++ b/info.toml @@ -529,6 +529,22 @@ hint = """ It should be doing some checking, returning an `Err` result if those checks fail, and only returning an `Ok` result if those checks determine that everything is... okay :)""" +# CLIPPY + +[[exercises]] +name = "clippy1" +path = "exercises/clippy/clippy1.rs" +mode = "clippy" +hint = """ +Floating point calculations are usually imprecise, so asking if two values are exactly equal is asking for trouble""" + +[[exercises]] +name = "clippy2" +path = "exercises/clippy/clippy2.rs" +mode = "clippy" +hint = """ +`for` loops over Option values are more clearly expressed as an `if let`""" + # STANDARD LIBRARY TYPES [[exercises]] diff --git a/install.ps1 b/install.ps1 index f6446100..04ea4a08 100644 --- a/install.ps1 +++ b/install.ps1 @@ -72,14 +72,19 @@ if (!($LASTEXITCODE -eq 0)) { # but anyone running pwsh 5 will have to pass the argument. $version = Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/rust-lang/rustlings/releases/latest ` | ConvertFrom-Json | Select-Object -ExpandProperty tag_name -Write-Host "Checking out version $version..." -Set-Location $path -git checkout -q tags/$version Write-Host "Installing the 'rustlings' executable..." -cargo install --force --path . +cargo install --force --git https://github.com/rust-lang/rustlings --tag $version if (!(Get-Command rustlings -ErrorAction SilentlyContinue)) { Write-Host "WARNING: Please check that you have '~/.cargo/bin' in your PATH environment variable!" } +# Checking whether Clippy is installed. +# Due to a bug in Cargo, this must be done with Rustup: https://github.com/rust-lang/rustup/issues/1514 +$clippy = (rustup component list | Select-String "clippy" | Select-String "installed") | Out-String +if (!$clippy) { + Write-Host "Installing the 'cargo-clippy' executable..." + rustup component add clippy +} + Write-Host "All done! Run 'rustlings' to get started." diff --git a/install.sh b/install.sh index 85bdad79..10750617 100755 --- a/install.sh +++ b/install.sh @@ -82,21 +82,24 @@ else echo "SUCCESS: Rust is up to date" fi -Path=${1:-rustlings/} -echo "Cloning Rustlings at $Path..." -git clone -q https://github.com/rust-lang/rustlings $Path - Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);") -echo "Checking out version $Version..." -cd $Path -git checkout -q tags/$Version +CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin" echo "Installing the 'rustlings' executable..." -cargo install --force --path . +cargo install --force --git https://github.com/rust-lang/rustlings --tag $Version if ! [ -x "$(command -v rustlings)" ] then - echo "WARNING: Please check that you have '~/.cargo/bin' in your PATH environment variable!" + echo "WARNING: Please check that you have '$CargoBin' in your PATH environment variable!" +fi + +# Checking whether Clippy is installed. +# Due to a bug in Cargo, this must be done with Rustup: https://github.com/rust-lang/rustup/issues/1514 +Clippy=$(rustup component list | grep "clippy" | grep "installed") +if [ -z "$Clippy" ] +then + echo "Installing the 'cargo-clippy' executable..." + rustup component add clippy fi echo "All done! Run 'rustlings' to get started." diff --git a/src/exercise.rs b/src/exercise.rs index d72eeb50..30b18643 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -1,7 +1,7 @@ use regex::Regex; use serde::Deserialize; use std::fmt::{self, Display, Formatter}; -use std::fs::{remove_file, File}; +use std::fs::{self, remove_file, File}; use std::io::Read; use std::path::PathBuf; use std::process::{self, Command}; @@ -9,6 +9,7 @@ use std::process::{self, Command}; const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE"; const CONTEXT: usize = 2; +const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml"; fn temp_file() -> String { format!("./temp_{}", process::id()) @@ -19,6 +20,7 @@ fn temp_file() -> String { pub enum Mode { Compile, Test, + Clippy, } #[derive(Deserialize)] @@ -83,6 +85,34 @@ impl Exercise { .args(&["--test", self.path.to_str().unwrap(), "-o", &temp_file()]) .args(RUSTC_COLOR_ARGS) .output(), + Mode::Clippy => { + let cargo_toml = format!( + r#"[package] +name = "{}" +version = "0.0.1" +edition = "2018" +[[bin]] +name = "{}" +path = "{}.rs""#, + self.name, self.name, self.name + ); + fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml) + .expect("Failed to write 📎 Clippy 📎 Cargo.toml file."); + // Due to an issue with Clippy, a cargo clean is required to catch all lints. + // See https://github.com/rust-lang/rust-clippy/issues/2604 + // This is already fixed on master branch. See this issue to track merging into Cargo: + // https://github.com/rust-lang/rust-clippy/issues/3837 + Command::new("cargo") + .args(&["clean", "--manifest-path", CLIPPY_CARGO_TOML_PATH]) + .args(RUSTC_COLOR_ARGS) + .output() + .expect("Failed to run 'cargo clean'"); + Command::new("cargo") + .args(&["clippy", "--manifest-path", CLIPPY_CARGO_TOML_PATH]) + .args(RUSTC_COLOR_ARGS) + .args(&["--", "-D", "warnings"]) + .output() + } } .expect("Failed to run 'compile' command."); diff --git a/src/run.rs b/src/run.rs index cfde7ab6..ebb0ae64 100644 --- a/src/run.rs +++ b/src/run.rs @@ -6,6 +6,7 @@ pub fn run(exercise: &Exercise) -> Result<(), ()> { match exercise.mode { Mode::Test => test(exercise)?, Mode::Compile => compile_and_run(exercise)?, + Mode::Clippy => compile_and_run(exercise)?, } Ok(()) } diff --git a/src/verify.rs b/src/verify.rs index 3d148960..229aa6d9 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -7,6 +7,7 @@ pub fn verify<'a>(start_at: impl IntoIterator) -> Result<() let compile_result = match exercise.mode { Mode::Test => compile_and_test(&exercise, RunMode::Interactive), Mode::Compile => compile_only(&exercise), + Mode::Clippy => compile_only(&exercise), }; if !compile_result.unwrap_or(false) { return Err(exercise); @@ -99,6 +100,7 @@ fn prompt_for_completion(exercise: &Exercise) -> bool { let success_msg = match exercise.mode { Mode::Compile => "The code is compiling!", Mode::Test => "The code is compiling, and the tests pass!", + Mode::Clippy => "The code is compiling, and 📎 Clippy 📎 is happy!", }; println!(""); From 3d9b03c52b8dc51b140757f6fd25ad87b5782ef5 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 27 Feb 2020 19:19:31 +0100 Subject: [PATCH 7/8] fix: Re-add cloning the repo to install scripts --- install.ps1 | 6 +++++- install.sh | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/install.ps1 b/install.ps1 index 04ea4a08..6504e69e 100644 --- a/install.ps1 +++ b/install.ps1 @@ -73,8 +73,12 @@ if (!($LASTEXITCODE -eq 0)) { $version = Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/rust-lang/rustlings/releases/latest ` | ConvertFrom-Json | Select-Object -ExpandProperty tag_name +Write-Host "Checking out version $version..." +Set-Location $path +git checkout -q tags/$version + Write-Host "Installing the 'rustlings' executable..." -cargo install --force --git https://github.com/rust-lang/rustlings --tag $version +cargo install --force --path . if (!(Get-Command rustlings -ErrorAction SilentlyContinue)) { Write-Host "WARNING: Please check that you have '~/.cargo/bin' in your PATH environment variable!" } diff --git a/install.sh b/install.sh index 10750617..7abb4064 100755 --- a/install.sh +++ b/install.sh @@ -82,11 +82,19 @@ else echo "SUCCESS: Rust is up to date" fi +Path=${1:-rustlings/} +echo "Cloning Rustlings at $Path..." +git clone -q https://github.com/rust-lang/rustlings $Path + Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);") CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin" +echo "Checking out version $Version..." +cd $Path +git checkout -q tags/$Version + echo "Installing the 'rustlings' executable..." -cargo install --force --git https://github.com/rust-lang/rustlings --tag $Version +cargo install --force --path . if ! [ -x "$(command -v rustlings)" ] then From 8b9479071c0ac4f5dc1318358d7d7e3a19ce98e2 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 27 Feb 2020 19:22:55 +0100 Subject: [PATCH 8/8] 2.2.1 --- CHANGELOG.md | 11 +++++++++++ Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c20aede..af5b41c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ + +### 2.2.1 (2020-02-27) + +#### Bug Fixes + +* Re-add cloning the repo to install scripts ([3d9b03c5](https://github.com/rust-lang/rustlings/commit/3d9b03c52b8dc51b140757f6fd25ad87b5782ef5)) + +#### Features + +* Add clippy lints (#269) ([1e2fd9c9](https://github.com/rust-lang/rustlings/commit/1e2fd9c92f8cd6e389525ca1a999fca4c90b5921)) + ## 2.2.0 (2020-02-25) diff --git a/Cargo.toml b/Cargo.toml index f9f6073d..4e6ea2ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "2.2.0" +version = "2.2.1" authors = ["Marisa ", "Carol (Nichols || Goulding)