This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "cargo-test-fail"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[workspace]
|
||||
@@ -0,0 +1,9 @@
|
||||
fn main() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn deliberate_unit_test_failure() {
|
||||
assert_eq!(2 + 2, 5);
|
||||
}
|
||||
}
|
||||
@@ -1 +1,9 @@
|
||||
fn main() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn unit_tests_run_on_the_host_target() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
|
||||
+38
-11
@@ -619,9 +619,10 @@ async fn unknown_broker_request_lists_the_known_ones() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cargo_actor_builds_valid_crates_and_reports_compiler_errors() {
|
||||
async fn cargo_actor_runs_unit_tests_by_default_and_can_skip_them() {
|
||||
let world = create_world("cargo-actor");
|
||||
let (host, mut mailbox) = start(&world).await;
|
||||
|
||||
let valid_source = cargo_source("cargo-valid");
|
||||
let valid_id = host.broker.send(
|
||||
"console",
|
||||
@@ -630,12 +631,42 @@ async fn cargo_actor_builds_valid_crates_and_reports_compiler_errors() {
|
||||
None,
|
||||
json!({"type": "build", "source": valid_source.display().to_string()}),
|
||||
);
|
||||
let built = receive_reply(&mut mailbox, &valid_id, Duration::from_secs(120)).await;
|
||||
assert_eq!(built.body["type"], "built");
|
||||
let built = receive_reply(&mut mailbox, &valid_id, Duration::from_secs(180)).await;
|
||||
assert_eq!(built.body["type"], "built", "{built:?}");
|
||||
assert_eq!(built.body["tests"]["passed"], 1);
|
||||
assert_eq!(built.body["tests"]["failed"], 0);
|
||||
assert!(built.body["tests"]["output"].as_str().unwrap().contains("unit_tests_run_on_the_host_target"));
|
||||
let wasm = built.body["wasm"].as_str().unwrap();
|
||||
assert!(wasm.ends_with(".wasm"));
|
||||
assert!(host.world.resolve("console", wasm).unwrap().is_file());
|
||||
|
||||
let failing_test_source = cargo_source("cargo-test-fail");
|
||||
let failed_test_id = host.broker.send(
|
||||
"console",
|
||||
Some("cargo"),
|
||||
None,
|
||||
None,
|
||||
json!({"type": "build", "source": failing_test_source.display().to_string()}),
|
||||
);
|
||||
let failed_test = receive_reply(&mut mailbox, &failed_test_id, Duration::from_secs(120)).await;
|
||||
assert_eq!(failed_test.body["type"], "build_failed", "{failed_test:?}");
|
||||
assert_eq!(failed_test.body["tests"]["passed"], 0);
|
||||
assert_eq!(failed_test.body["tests"]["failed"], 1);
|
||||
assert!(failed_test.body["tests"]["output"].as_str().unwrap().contains("deliberate_unit_test_failure"));
|
||||
|
||||
let skipped_id = host.broker.send(
|
||||
"console",
|
||||
Some("cargo"),
|
||||
None,
|
||||
None,
|
||||
json!({"type": "build", "source": failing_test_source.display().to_string(), "skip_tests": true}),
|
||||
);
|
||||
let skipped = receive_reply(&mut mailbox, &skipped_id, Duration::from_secs(120)).await;
|
||||
assert_eq!(skipped.body["type"], "built", "{skipped:?}");
|
||||
assert_eq!(skipped.body["tests"]["passed"], 0);
|
||||
assert_eq!(skipped.body["tests"]["failed"], 0);
|
||||
assert_eq!(skipped.body["tests"]["output"], "skipped (skip_tests=true)");
|
||||
|
||||
let invalid_source = cargo_source("cargo-fail");
|
||||
let invalid_id = host.broker.send(
|
||||
"console",
|
||||
@@ -644,14 +675,10 @@ async fn cargo_actor_builds_valid_crates_and_reports_compiler_errors() {
|
||||
None,
|
||||
json!({"type": "build", "source": invalid_source.display().to_string()}),
|
||||
);
|
||||
let failed = receive_reply(&mut mailbox, &invalid_id, Duration::from_secs(120)).await;
|
||||
assert_eq!(failed.body["type"], "build_failed");
|
||||
assert!(
|
||||
failed.body["errors"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.contains("missing_function")
|
||||
);
|
||||
let invalid = receive_reply(&mut mailbox, &invalid_id, Duration::from_secs(120)).await;
|
||||
assert_eq!(invalid.body["type"], "build_failed", "{invalid:?}");
|
||||
assert_eq!(invalid.body["tests"]["failed"], 1);
|
||||
assert!(invalid.body["tests"]["output"].as_str().unwrap().contains("missing_function"));
|
||||
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user