Support Cargo scaffolding and human output, and find boolean expressions

This commit is contained in:
2026-11-11 21:57:37 +00:00
parent c7606b8ae9
commit 652ea7960f
7 changed files with 267 additions and 116 deletions
+75
View File
@@ -54,6 +54,81 @@ async fn cargo_at(
.await?;
Ok((code, String::from_utf8_lossy(&bytes).into_owned()))
}
#[tokio::test(flavor = "multi_thread")]
async fn cargo_scaffold_and_human_output() -> anyhow::Result<()> {
let binaries = programs();
let temp = tempfile::tempdir()?;
let world = World::open(temp.path())?;
let bin = temp.path().join("world/bin");
std::fs::create_dir_all(&bin)?;
std::fs::copy(binaries.join("cargo.wasm"), bin.join("cargo.wasm"))?;
std::fs::copy(binaries.join("brush.wasm"), bin.join("sh.wasm"))?;
let runtime = Runtime::new(world)?;
for (script, cwd, expected, success) in [
(
"cargo new hello && cd hello && cargo run",
"/",
"Hello, world!\n",
true,
),
("cargo build", "/hello", "", true),
(
"cargo new library --lib --name named_lib --edition 2021",
"/",
"",
true,
),
("cargo check", "/library", "", true),
(
"cargo init --lib --name initialized --edition 2024",
"/empty",
"",
true,
),
("cargo check", "/empty", "", true),
("cargo new broken --edition 1900", "/", "", false),
] {
std::fs::create_dir_all(temp.path().join("world/empty"))?;
let mut stdout = Vec::new();
let mut stderr = Vec::new();
let code = runtime
.exec(
Command::Argv(vec!["/bin/sh.wasm".into(), "-c".into(), script.into()]),
Options {
cwd: cwd.into(),
timeout: Some(Duration::from_secs(120)),
..Default::default()
},
&mut |stream, bytes| match stream {
sausage::exec::Stream::Stdout => stdout.extend_from_slice(bytes),
sausage::exec::Stream::Stderr => stderr.extend_from_slice(bytes),
},
)
.await?;
let stderr = String::from_utf8_lossy(&stderr);
assert_eq!(code == 0, success, "{script}: {stderr}");
assert_eq!(
String::from_utf8_lossy(&stdout),
expected,
"{script}: {stderr}"
);
assert!(
!stderr.contains("\"reason\":\"compiler-artifact\""),
"{stderr}"
);
if script == "cargo build" {
assert!(stderr.contains("Finished"), "{stderr}");
}
}
let root = temp.path().join("world");
let manifest: toml::Value =
toml::from_str(&std::fs::read_to_string(root.join("library/Cargo.toml"))?)?;
assert_eq!(manifest["package"]["name"].as_str(), Some("named_lib"));
assert_eq!(manifest["package"]["edition"].as_str(), Some("2021"));
assert!(root.join("library/src/lib.rs").is_file());
assert!(root.join("empty/src/lib.rs").is_file());
Ok(())
}
fn cache_hits(base: &Path) -> anyhow::Result<u64> {
let stats = std::process::Command::new("kache")
.arg("stats")