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:
commit
78552ebd7a
|
@ -57,14 +57,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(matches) = matches.subcommand_matches("run") {
|
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() {
|
if matches.subcommand_matches("verify").is_some() {
|
||||||
match verify(None) {
|
verify(None).unwrap_or_else(|_| std::process::exit(1));
|
||||||
Ok(_) => {}
|
|
||||||
Err(_) => std::process::exit(1),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.subcommand_matches("watch").is_some() {
|
if matches.subcommand_matches("watch").is_some() {
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
let
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
[[exercises]]
|
||||||
|
path = "compFailure.rs"
|
||||||
|
mode = "compile"
|
||||||
|
|
||||||
|
[[exercises]]
|
||||||
|
path = "testFailure.rs"
|
||||||
|
mode = "test"
|
|
@ -0,0 +1,4 @@
|
||||||
|
#[test]
|
||||||
|
fn passing() {
|
||||||
|
asset!(true);
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ fn fails_when_in_wrong_dir() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.current_dir("tests/")
|
.current_dir("tests/")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -21,31 +21,61 @@ fn verify_all_success() {
|
||||||
Command::cargo_bin("rustlings")
|
Command::cargo_bin("rustlings")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.arg("v")
|
.arg("v")
|
||||||
.current_dir("tests/fixture/")
|
.current_dir("tests/fixture/success")
|
||||||
.assert()
|
.assert()
|
||||||
.success();
|
.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn verify_all_failure() {
|
||||||
|
Command::cargo_bin("rustlings")
|
||||||
|
.unwrap()
|
||||||
|
.arg("v")
|
||||||
|
.current_dir("tests/fixture/failure")
|
||||||
|
.assert()
|
||||||
|
.code(1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_single_compile_success() {
|
fn run_single_compile_success() {
|
||||||
Command::cargo_bin("rustlings")
|
Command::cargo_bin("rustlings")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.args(&["r", "compSuccess.rs"])
|
.args(&["r", "compSuccess.rs"])
|
||||||
.current_dir("tests/fixture/")
|
.current_dir("tests/fixture/success/")
|
||||||
.assert()
|
.assert()
|
||||||
.success();
|
.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]
|
#[test]
|
||||||
fn run_single_test_success() {
|
fn run_single_test_success() {
|
||||||
Command::cargo_bin("rustlings")
|
Command::cargo_bin("rustlings")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.args(&["r", "testSuccess.rs"])
|
.args(&["r", "testSuccess.rs"])
|
||||||
.current_dir("tests/fixture/")
|
.current_dir("tests/fixture/success/")
|
||||||
.assert()
|
.assert()
|
||||||
.success();
|
.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]
|
#[test]
|
||||||
fn run_single_test_no_filename() {
|
fn run_single_test_no_filename() {
|
||||||
Command::cargo_bin("rustlings")
|
Command::cargo_bin("rustlings")
|
||||||
|
@ -53,7 +83,7 @@ fn run_single_test_no_filename() {
|
||||||
.arg("r")
|
.arg("r")
|
||||||
.current_dir("tests/fixture/")
|
.current_dir("tests/fixture/")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -61,7 +91,7 @@ fn run_single_test_no_exercise() {
|
||||||
Command::cargo_bin("rustlings")
|
Command::cargo_bin("rustlings")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.args(&["r", "compNoExercise.rs"])
|
.args(&["r", "compNoExercise.rs"])
|
||||||
.current_dir("tests/fixture/")
|
.current_dir("tests/fixture/failure")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.code(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue