diff options
| author | bors <bors@rust-lang.org> | 2019-04-07 20:11:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-07 20:11:22 +0000 |
| commit | 78552ebd7a7181c6c402fb1522f42b40e5edd4c2 (patch) | |
| tree | 00adc81b919f9a90f529a35590a9ade7c49533ab | |
| parent | fbd0ccbd5b7c86846e2488bf4d8dce0b1b90b04e (diff) | |
| parent | 0c7bd12372a8d154341f64b7587a7dafe07f5720 (diff) | |
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.
| -rw-r--r-- | src/main.rs | 7 | ||||
| -rw-r--r-- | tests/fixture/failure/compFailure.rs | 3 | ||||
| -rw-r--r-- | tests/fixture/failure/compNoExercise.rs (renamed from tests/fixture/compNoExercise.rs) | 0 | ||||
| -rw-r--r-- | tests/fixture/failure/info.toml | 7 | ||||
| -rw-r--r-- | tests/fixture/failure/testFailure.rs | 4 | ||||
| -rw-r--r-- | tests/fixture/success/compSuccess.rs (renamed from tests/fixture/compSuccess.rs) | 0 | ||||
| -rw-r--r-- | tests/fixture/success/info.toml (renamed from tests/fixture/info.toml) | 0 | ||||
| -rw-r--r-- | tests/fixture/success/testSuccess.rs (renamed from tests/fixture/testSuccess.rs) | 0 | ||||
| -rw-r--r-- | tests/integration_tests.rs | 44 |
9 files changed, 53 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index eca1a03..d4bb64c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() { diff --git a/tests/fixture/failure/compFailure.rs b/tests/fixture/failure/compFailure.rs new file mode 100644 index 0000000..566856a --- /dev/null +++ b/tests/fixture/failure/compFailure.rs @@ -0,0 +1,3 @@ +fn main() { + let +}
\ No newline at end of file diff --git a/tests/fixture/compNoExercise.rs b/tests/fixture/failure/compNoExercise.rs index f79c691..f79c691 100644 --- a/tests/fixture/compNoExercise.rs +++ b/tests/fixture/failure/compNoExercise.rs diff --git a/tests/fixture/failure/info.toml b/tests/fixture/failure/info.toml new file mode 100644 index 0000000..f4e7c0c --- /dev/null +++ b/tests/fixture/failure/info.toml @@ -0,0 +1,7 @@ +[[exercises]] +path = "compFailure.rs" +mode = "compile" + +[[exercises]] +path = "testFailure.rs" +mode = "test"
\ No newline at end of file diff --git a/tests/fixture/failure/testFailure.rs b/tests/fixture/failure/testFailure.rs new file mode 100644 index 0000000..b33a5d2 --- /dev/null +++ b/tests/fixture/failure/testFailure.rs @@ -0,0 +1,4 @@ +#[test] +fn passing() { + asset!(true); +} diff --git a/tests/fixture/compSuccess.rs b/tests/fixture/success/compSuccess.rs index f79c691..f79c691 100644 --- a/tests/fixture/compSuccess.rs +++ b/tests/fixture/success/compSuccess.rs diff --git a/tests/fixture/info.toml b/tests/fixture/success/info.toml index e255db9..e255db9 100644 --- a/tests/fixture/info.toml +++ b/tests/fixture/success/info.toml diff --git a/tests/fixture/testSuccess.rs b/tests/fixture/success/testSuccess.rs index 589057c..589057c 100644 --- a/tests/fixture/testSuccess.rs +++ b/tests/fixture/success/testSuccess.rs diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 01c4744..a077918 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -13,7 +13,7 @@ fn fails_when_in_wrong_dir() { .unwrap() .current_dir("tests/") .assert() - .failure(); + .code(1); } #[test] @@ -21,39 +21,69 @@ 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") .unwrap() .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); } |
