requirements.test-coverage.failures.prerequisites
Requirements index · View definition
Requirement
When required nextest or LLVM coverage tooling is unavailable or has an unsupported version, the coverage workflow MUST identify the prerequisite and explain how to obtain a supported version.
Rationale
I found no gap. src/execution_coverage/runner.rs#fn[tools] carries the {impl} reference. fn[run] calls it before any other coverage work, and it is the only code that checks these prerequisites.
Obligations, each mapped to its code and test:
- nextest unavailable.
toolsrunscargo nextest --version. If that fails, it returns “cargo nextest >= 0.9.116 is required; install withcargo install cargo-nextest --locked”. This names the prerequisite and says how to get it. The testtests/execution_coverage.rs#fn[unavailable_and_unsupported_tools_explain_installation]runshabeas coveragewith an emptyPATH. It asserts failure and that stderr containscargo install cargo-nextest --locked. - nextest version unsupported.
toolsparses the version and compares it with[0, 9, 116]. An older or unparseable version returns “cargo nextest >= 0.9.116 is required; update withcargo install cargo-nextest --locked”. The same test fakescargo-nextest 0.9.115and asserts that stderr contains “>= 0.9.116”. - LLVM tools unavailable.
toolslocatesllvm-cov,llvm-profdata,llvm-objcopyandllvm-readobjin the rustc sysroot and runs each with--version. A failure returns “matching Rust LLVM coverage tooling is required; runrustup component add llvm-tools-preview”. The test fakes a rustc whose host directory has no LLVM tools. It asserts failure and that stderr containsrustup component add llvm-tools-preview. - LLVM version unsupported.
toolscompares the major version in each tool’s--versionoutput with rustc’sLLVM version:. A mismatch returns “{path} must match rustc’s LLVM {llvm}; runrustup component add llvm-tools-preview…”. The test installs fake tools reporting LLVM 21 against rustc’s 22.1.6. It asserts that the diagnostic contains both “must match rustc’s LLVM 22.1.6” and the rustup command. It also asserts that no coverage output directory was created.
The failure from tools propagates out of run with ?, and the test confirms the message reaches stderr with an unsuccessful exit status.
Unspecified behavior: I found none beyond the requirement. The errors for rustc not reporting its host and for a missing rustc binary concern the compiler, not nextest or LLVM tooling. The requirement does not cover them.
Inputs
Implementation
Input 2: outline src/execution_coverage/runner.rs fn[tools]
- File:
src/execution_coverage/runner.rs - Selector:
fn[tools] - Kind:
fn src/execution_coverage/runner.rs:186–233
// {impl}`requirements.test-coverage.failures.prerequisites`
fn tools(compiler: &str) -> io::Result<(PathBuf, PathBuf, String)> {
let version = output(Command::new("cargo").args(["nextest", "--version"]))
.map_err(|error| io::Error::other(format!("cargo nextest >= 0.9.116 is required; install with `cargo install cargo-nextest --locked`: {error}")))?;
let numbers = version
.split_whitespace()
.nth(1)
.unwrap_or("")
.split('.')
.map(|number| number.parse::<u32>().unwrap_or(0))
.collect::<Vec<_>>();
if numbers.as_slice() < [0, 9, 116].as_slice() {
return Err(io::Error::other(
"cargo nextest >= 0.9.116 is required; update with `cargo install cargo-nextest --locked`",
));
}
let rustc = output(Command::new(compiler).arg("-vV"))?;
let host = rustc
.lines()
.find_map(|line| line.strip_prefix("host: "))
.ok_or_else(|| io::Error::other("rustc did not report its host"))?;
let sysroot = output(Command::new(compiler).args(["--print", "sysroot"]))?;
let bin = PathBuf::from(sysroot)
.join("lib/rustlib")
.join(host)
.join("bin");
let cov = bin.join(format!("llvm-cov{}", std::env::consts::EXE_SUFFIX));
let profdata = bin.join(format!("llvm-profdata{}", std::env::consts::EXE_SUFFIX));
let objcopy = bin.join(format!("llvm-objcopy{}", std::env::consts::EXE_SUFFIX));
let readobj = bin.join(format!("llvm-readobj{}", std::env::consts::EXE_SUFFIX));
for path in [&cov, &profdata, &objcopy, &readobj] {
let version = output(Command::new(path).arg("--version")).map_err(|error| {
io::Error::other(format!("matching Rust LLVM coverage tooling is required; run `rustup component add llvm-tools-preview`: {error}"))
})?;
let llvm = rustc
.lines()
.find_map(|line| line.strip_prefix("LLVM version: "))
.unwrap_or("");
let major = llvm.split('.').next().unwrap_or("");
if major.is_empty() || !version.contains(&format!("version {major}.")) {
return Err(io::Error::other(format!(
"{} must match rustc's LLVM {llvm}; run `rustup component add llvm-tools-preview` for the active toolchain",
path.display()
)));
}
}
Ok((cov, profdata, rustc))
}
Tests
Input 3: outline tests/execution_coverage.rs fn[unavailable_and_unsupported_tools_explain_installation]
- File:
tests/execution_coverage.rs - Selector:
fn[unavailable_and_unsupported_tools_explain_installation] - Kind:
fn tests/execution_coverage.rs:1444–1508
// {test}`requirements.test-coverage.failures.prerequisites`
#[cfg(unix)]
#[test]
fn unavailable_and_unsupported_tools_explain_installation() {
use std::os::unix::fs::PermissionsExt;
let temp = fixture();
let root = temp.path();
let bin = root.join("fake-tools");
fs::create_dir(&bin).unwrap();
let invoke = || {
Command::new(env!("CARGO_BIN_EXE_habeas"))
.arg("coverage")
.current_dir(root)
.env("PATH", &bin)
.env_remove("RUSTC")
.env_remove("CARGO_BUILD_RUSTC")
.output()
.unwrap()
};
let missing = invoke();
assert!(!missing.status.success());
assert!(
String::from_utf8_lossy(&missing.stderr).contains("cargo install cargo-nextest --locked")
);
fs::write(
bin.join("cargo"),
"#!/bin/sh\nprintf 'cargo-nextest 0.9.115\\n'\n",
)
.unwrap();
fs::set_permissions(bin.join("cargo"), fs::Permissions::from_mode(0o755)).unwrap();
let old = invoke();
assert!(!old.status.success());
assert!(String::from_utf8_lossy(&old.stderr).contains(">= 0.9.116"));
fs::write(
bin.join("cargo"),
"#!/bin/sh\nprintf 'cargo-nextest 0.9.116\\n'\n",
)
.unwrap();
fs::write(bin.join("rustc"), format!("#!/bin/sh\nif [ \"$1\" = '-vV' ]; then\nprintf 'host: missing-host\\nLLVM version: 22.1.6\\n'\nelse\nprintf '{}\\n'\nfi\n", root.display())).unwrap();
fs::set_permissions(bin.join("rustc"), fs::Permissions::from_mode(0o755)).unwrap();
let llvm = invoke();
assert!(!llvm.status.success());
assert!(
String::from_utf8_lossy(&llvm.stderr).contains("rustup component add llvm-tools-preview")
);
let llvm_bin = root.join("lib/rustlib/missing-host/bin");
fs::create_dir_all(&llvm_bin).unwrap();
for tool in ["llvm-cov", "llvm-profdata", "llvm-objcopy", "llvm-readobj"] {
fs::write(
llvm_bin.join(tool),
"#!/bin/sh\nprintf 'LLVM version 21.0.0\\n'\n",
)
.unwrap();
fs::set_permissions(llvm_bin.join(tool), fs::Permissions::from_mode(0o755)).unwrap();
}
let mismatched = invoke();
assert!(!mismatched.status.success());
let diagnostic = String::from_utf8_lossy(&mismatched.stderr);
assert!(
diagnostic.contains("must match rustc's LLVM 22.1.6")
&& diagnostic.contains("rustup component add llvm-tools-preview"),
"{diagnostic}"
);
assert!(!root.join("target/habeas/coverage").exists());
}
Other sources
Input 1: requirements selection requirements.test-coverage.failures.prerequisites
requirements.test-coverage.failures.prerequisites:md/requirements/test-coverage.md:152–156
:::{req} failures.prerequisites
When required nextest or LLVM coverage tooling is unavailable or has an
unsupported version, the coverage workflow MUST identify the prerequisite and
explain how to obtain a supported version.
:::