Spool native cargo build and test streams to persistent world logs
This commit is contained in:
@@ -73,8 +73,28 @@ async fn build(world: &TestWorld, name: &str) -> Result<Value, Value> {
|
||||
.register(&host);
|
||||
let result = host.call("cargo.build", json!({"plugin":name})).await;
|
||||
host.stop().await;
|
||||
let logs = match &result {
|
||||
Ok(output) => &output["logs"],
|
||||
Err(error) => &error["data"]["logs"],
|
||||
};
|
||||
check_logs(world, logs);
|
||||
result
|
||||
}
|
||||
/// RPC paths point at full raw streams, outside pruned build folders.
|
||||
fn check_logs(world: &TestWorld, logs: &Value) {
|
||||
let mut total = 0;
|
||||
for stream in ["stdout", "stderr"] {
|
||||
let path = logs[stream]["path"].as_str().expect("log path");
|
||||
assert!(path.starts_with("/logs/cargo/"));
|
||||
assert!(path.ends_with(&format!(".{stream}.log")));
|
||||
let bytes = std::fs::metadata(world.0.join(path.trim_start_matches('/')))
|
||||
.unwrap()
|
||||
.len();
|
||||
assert_eq!(logs[stream]["bytes"], bytes);
|
||||
total += bytes;
|
||||
}
|
||||
assert_eq!(logs["total_bytes"], total);
|
||||
}
|
||||
struct Valid {
|
||||
world: TestWorld,
|
||||
result: Value,
|
||||
@@ -206,6 +226,20 @@ async fn build_output_and_warnings() {
|
||||
.unwrap()
|
||||
.contains("fixture build warning")
|
||||
);
|
||||
let logs = &valid.result["logs"];
|
||||
let raw = |stream: &str| {
|
||||
std::fs::read_to_string(
|
||||
valid.world.0.join(
|
||||
logs[stream]["path"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.trim_start_matches('/'),
|
||||
),
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
assert!(raw("stdout").contains("\"reason\":\"compiler-artifact\""));
|
||||
assert!(raw("stderr").contains("Finished "));
|
||||
let output = valid.result["tests"]["output"].as_str().unwrap();
|
||||
assert!(output.contains("INTEGRATION_CASE"));
|
||||
assert!(!output.contains("Compiling "));
|
||||
@@ -277,6 +311,7 @@ async fn native_discovery_and_error_paths() {
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(error["code"], -32004);
|
||||
check_logs(&world, &error["data"]["logs"]);
|
||||
assert!(
|
||||
error["data"]["output"]
|
||||
.as_str()
|
||||
@@ -721,6 +756,7 @@ async fn build_timeout_and_queued_build() {
|
||||
assert_eq!(error["code"], -32004);
|
||||
assert_eq!(error["message"], "timeout");
|
||||
assert_eq!(error["data"]["reason"], "timeout");
|
||||
check_logs(&world, &error["data"]["logs"]);
|
||||
assert_eq!(error["data"]["step"], "tests");
|
||||
assert!(error["data"]["elapsed_secs"].as_f64().unwrap() >= 5.0);
|
||||
assert!(!error["data"]["output"].as_str().unwrap().is_empty());
|
||||
@@ -776,6 +812,7 @@ fn main() {
|
||||
.unwrap_err();
|
||||
assert_eq!(error["code"], -32004);
|
||||
assert_eq!(error["data"]["reason"], "timeout");
|
||||
check_logs(&world, &error["data"]["logs"]);
|
||||
assert_eq!(error["data"]["step"], "release build");
|
||||
assert_eq!(error["data"]["tests"]["passed"], 1);
|
||||
assert!(error["data"]["elapsed_secs"].as_f64().unwrap() >= 5.0);
|
||||
|
||||
Reference in New Issue
Block a user