mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 14:57:32 -05:00
fix test command execution
seems like i forgot that you actually need to run executables created with `rustc --test`! this also reworks the "test1" exercise a bit closes #108
This commit is contained in:
parent
17fa037a16
commit
02ceb0ba8c
2 changed files with 33 additions and 15 deletions
|
@ -5,16 +5,17 @@
|
|||
|
||||
// Mary is buying apples. One apple usually costs 2 dollars, but if you buy
|
||||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||
// the price of an order of apples given the order amount.
|
||||
// the price of an order of apples given the order amount. No hints this time!
|
||||
|
||||
fn main() {
|
||||
// Put your function here!
|
||||
// fn ..... {
|
||||
|
||||
// Don't modify this function!
|
||||
#[test]
|
||||
fn verify_test() {
|
||||
let price1 = calculateprice(55);
|
||||
let price2 = calculateprice(40);
|
||||
|
||||
// Don't modify this!
|
||||
if price1 == 55 && price2 == 80 {
|
||||
println!("Good job!");
|
||||
} else {
|
||||
panic!("Uh oh! Wrong price!");
|
||||
}
|
||||
assert_eq!(price1, 55);
|
||||
assert_eq!(price2, 80);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn verify() -> Result<(), ()> {
|
|||
compile_only("exercises/functions/functions3.rs")?;
|
||||
compile_only("exercises/functions/functions4.rs")?;
|
||||
compile_only("exercises/functions/functions5.rs")?;
|
||||
compile_only("exercises/test1.rs")?;
|
||||
test("exercises/test1.rs")?;
|
||||
compile_only("exercises/primitive_types/primitive_types1.rs")?;
|
||||
compile_only("exercises/primitive_types/primitive_types2.rs")?;
|
||||
compile_only("exercises/primitive_types/primitive_types3.rs")?;
|
||||
|
@ -87,19 +87,36 @@ pub fn test(filename: &str) -> Result<(), ()> {
|
|||
.args(&["--test", filename, "-o", "temp", "--color", "always"])
|
||||
.output()
|
||||
.expect("fail");
|
||||
bar.finish_and_clear();
|
||||
if testcmd.status.success() {
|
||||
bar.set_message(format!("Running {}...", filename).as_str());
|
||||
let runcmd = Command::new("./temp").output().expect("fail");
|
||||
bar.finish_and_clear();
|
||||
|
||||
if runcmd.status.success() {
|
||||
let formatstr = format!("{} Successfully tested {}!", Emoji("✅", "✓"), filename);
|
||||
println!("{}", style(formatstr).green());
|
||||
clean();
|
||||
Ok(())
|
||||
} else {
|
||||
let formatstr = format!(
|
||||
"{} Testing of {} failed! Please try again.",
|
||||
"{} Testing of {} failed! Please try again. Here's the output:",
|
||||
Emoji("⚠️ ", "!"),
|
||||
filename
|
||||
);
|
||||
println!("{}", style(formatstr).red());
|
||||
println!("{}", String::from_utf8_lossy(&runcmd.stdout));
|
||||
clean();
|
||||
Err(())
|
||||
}
|
||||
} else {
|
||||
bar.finish_and_clear();
|
||||
let formatstr = format!(
|
||||
"{} Compiling of {} failed! Please try again. Here's the output:",
|
||||
Emoji("⚠️ ", "!"),
|
||||
filename
|
||||
);
|
||||
println!("{}", style(formatstr).red());
|
||||
println!("{}", String::from_utf8_lossy(&testcmd.stderr));
|
||||
clean();
|
||||
Err(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue