Auto merge of #141 - cjpearce:fix/run-panics-on-compile-fail, r=komaeda

Stop run from panicking when compile fails

Currently if you use the `rustlings run` command and your program fails to compile, rustlings will panic while trying to exit.

First I've added a couple of integration tests to cover this case, which also meant moving a few tests so that the new fixtures didn't cause `verify_all_success` to fail.

Then I noticed that the existing integration tests that test for failure pass even when rustlings panics, preventing the new tests from failing. I've updated the integration tests to distinguish between when rustlings has failed in the way that we want (exit code 1) rather than a panic (exit code 101).

Finally I fixed the actual panic, which was just caused by unwrapping when rustlings should probably be exiting cleanly.
This commit is contained in:
bors 2019-04-07 20:11:22 +00:00
commit 78552ebd7a
9 changed files with 53 additions and 12 deletions

View File

@ -57,14 +57,11 @@ fn main() {
}
if let Some(matches) = matches.subcommand_matches("run") {
run(matches.clone()).unwrap();
run(matches.clone()).unwrap_or_else(|_| std::process::exit(1));
}
if matches.subcommand_matches("verify").is_some() {
match verify(None) {
Ok(_) => {}
Err(_) => std::process::exit(1),
}
verify(None).unwrap_or_else(|_| std::process::exit(1));
}
if matches.subcommand_matches("watch").is_some() {

View File

@ -0,0 +1,3 @@
fn main() {
let
}

View File

@ -0,0 +1,7 @@
[[exercises]]
path = "compFailure.rs"
mode = "compile"
[[exercises]]
path = "testFailure.rs"
mode = "test"

View File

@ -0,0 +1,4 @@
#[test]
fn passing() {
asset!(true);
}

View File

@ -13,7 +13,7 @@ fn fails_when_in_wrong_dir() {
.unwrap()
.current_dir("tests/")
.assert()
.failure();
.code(1);
}
#[test]
@ -21,31 +21,61 @@ fn verify_all_success() {
Command::cargo_bin("rustlings")
.unwrap()
.arg("v")
.current_dir("tests/fixture/")
.current_dir("tests/fixture/success")
.assert()
.success();
}
#[test]
fn verify_all_failure() {
Command::cargo_bin("rustlings")
.unwrap()
.arg("v")
.current_dir("tests/fixture/failure")
.assert()
.code(1);
}
#[test]
fn run_single_compile_success() {
Command::cargo_bin("rustlings")
.unwrap()
.args(&["r", "compSuccess.rs"])
.current_dir("tests/fixture/")
.current_dir("tests/fixture/success/")
.assert()
.success();
}
#[test]
fn run_single_compile_failure() {
Command::cargo_bin("rustlings")
.unwrap()
.args(&["r", "compFailure.rs"])
.current_dir("tests/fixture/failure/")
.assert()
.code(1);
}
#[test]
fn run_single_test_success() {
Command::cargo_bin("rustlings")
.unwrap()
.args(&["r", "testSuccess.rs"])
.current_dir("tests/fixture/")
.current_dir("tests/fixture/success/")
.assert()
.success();
}
#[test]
fn run_single_test_failure() {
Command::cargo_bin("rustlings")
.unwrap()
.args(&["r", "testFailure.rs"])
.current_dir("tests/fixture/failure/")
.assert()
.code(1);
}
#[test]
fn run_single_test_no_filename() {
Command::cargo_bin("rustlings")
@ -53,7 +83,7 @@ fn run_single_test_no_filename() {
.arg("r")
.current_dir("tests/fixture/")
.assert()
.failure();
.code(1);
}
#[test]
@ -61,7 +91,7 @@ fn run_single_test_no_exercise() {
Command::cargo_bin("rustlings")
.unwrap()
.args(&["r", "compNoExercise.rs"])
.current_dir("tests/fixture/")
.current_dir("tests/fixture/failure")
.assert()
.failure();
.code(1);
}