MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / discover_test_binaries

Function discover_test_binaries

scripts/coverage.rs:67–125  ·  view source on GitHub ↗
(
    root: &Path,
    args: &[String],
    rustflags: &str,
    profraw_pattern: &Path,
)

Source from the content-addressed store, hash-verified

65}
66
67fn discover_test_binaries(
68 root: &Path,
69 args: &[String],
70 rustflags: &str,
71 profraw_pattern: &Path,
72) -> Vec<String> {
73 // We need `--no-run --message-format=json` to be cargo flags, not test
74 // binary flags. Split at `--` so they're inserted before it.
75 eprintln!("=== Discovering test binaries ===");
76 let cargo_args: Vec<_> = args.iter().take_while(|a| *a != "--").collect();
77 let output = Command::new("cargo")
78 .arg("test")
79 .args(&cargo_args)
80 .arg("--no-run")
81 .arg("--message-format=json")
82 .env("RUSTFLAGS", rustflags)
83 .env("LLVM_PROFILE_FILE", profraw_pattern)
84 .current_dir(root)
85 .stderr(Stdio::inherit())
86 .output()
87 .expect("failed to run cargo test --no-run");
88 if !output.status.success() {
89 eprintln!("cargo test --no-run failed with {}", output.status);
90 std::process::exit(output.status.code().unwrap_or(1));
91 }
92
93 let jq_output = Command::new("jq")
94 .arg("-r")
95 .arg(r#"select(.profile.test == true) | .filenames[]"#)
96 .stdin(Stdio::piped())
97 .stdout(Stdio::piped())
98 .stderr(Stdio::inherit())
99 .spawn()
100 .and_then(|mut child| {
101 use std::io::Write;
102 child.stdin.take().unwrap().write_all(&output.stdout)?;
103 child.wait_with_output()
104 })
105 .expect("failed to run jq — is it installed?");
106 if !jq_output.status.success() {
107 eprintln!("jq failed with {}", jq_output.status);
108 std::process::exit(1);
109 }
110
111 let binaries: Vec<_> = String::from_utf8_lossy(&jq_output.stdout)
112 .lines()
113 .filter(|f| !f.contains("dSYM"))
114 .map(|s| s.to_string())
115 .collect();
116
117 if binaries.is_empty() {
118 eprintln!("error: no test binaries found");
119 std::process::exit(1);
120 }
121 for b in &binaries {
122 eprintln!(" found binary: {b}");
123 }
124 binaries

Callers 1

mainFunction · 0.85

Calls 15

collectMethod · 0.80
outputMethod · 0.80
write_allMethod · 0.80
newFunction · 0.50
iterMethod · 0.45
expectMethod · 0.45
stderrMethod · 0.45
envMethod · 0.45
argMethod · 0.45
argsMethod · 0.45
successMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected