1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
use std::{
io::{BufRead, BufReader, Read},
path::{Path, PathBuf},
process::{Command, Stdio},
thread,
};
pub(crate) use cargo_metadata::Metadata;
use snafu::{OptionExt, ResultExt};
use tracing::debug;
use crate::{
Result,
builder::{BuildOptions, BuildTarget},
config::{Config, Verbosity},
error,
messages::{BuildMessage, MessageReporter},
target::TargetTriple,
};
/// Options for controlling cargo metadata invocation.
#[derive(Clone, Debug, Default)]
pub(crate) struct CargoMetadataOptions {
/// Exclude dependency information from metadata output.
/// Corresponds to `--no-deps` flag.
/// Default: false (dependencies are included by default)
pub no_deps: bool,
/// Only include dependencies for the specified target platform.
/// Corresponds to `--filter-platform TARGET` flag.
pub filter_platform: Option<TargetTriple>,
/// Space or comma separated list of features to activate.
/// Corresponds to `--features` flag.
pub features: Vec<String>,
/// Activate all available features.
/// Corresponds to `--all-features` flag.
pub all_features: bool,
/// Do not activate the `default` feature.
/// Corresponds to `--no-default-features` flag.
pub no_default_features: bool,
/// Run without accessing the network.
/// Corresponds to `--offline` flag.
pub offline: bool,
/// Require Cargo.lock is up to date.
/// Corresponds to `--locked` flag.
pub locked: bool,
/// Rust toolchain override to query metadata with (e.g., "nightly", "1.70.0", "stable").
/// When set, `cargo metadata` is run using the specified toolchain.
pub toolchain: Option<String>,
}
impl From<&BuildOptions> for CargoMetadataOptions {
fn from(opts: &BuildOptions) -> Self {
Self {
no_deps: false,
filter_platform: opts.target.clone(),
features: opts.features.clone(),
all_features: opts.all_features,
no_default_features: opts.no_default_features,
offline: opts.offline,
locked: opts.locked,
toolchain: opts.toolchain.clone(),
}
}
}
/// Rust wrapper around shelling out to `cargo` for building and running Rust projects.
///
/// Much as it pains me, sometimes we must shell out to `cargo` to do things. That's ugly,
/// error-prone, and worst of all inelegant. But it's also the only way to get certain things
/// done.
///
/// This type is mainly concerned with the surprisingly complex task of figuring out where `cargo`
/// is and how to invoke it, and secondarily with constructing its command lines and parsing the
/// resulting output.
pub(crate) trait CargoRunner: std::fmt::Debug + Send + Sync + 'static {
/// Get cargo metadata for a source directory.
///
/// Executes `cargo metadata` on the specified directory and returns the
/// parsed metadata including workspace members, packages, and targets.
///
/// # Arguments
///
/// * `source_dir` - Path to directory containing Cargo.toml
/// * `options` - Options controlling metadata invocation (deps, features, platform, etc.)
fn metadata(&self, source_dir: &Path, options: &CargoMetadataOptions) -> Result<Metadata>;
/// Build a binary from source.
///
/// Executes cargo build with specified options and returns the absolute path
/// to the compiled binary, determined by parsing `--message-format=json` output.
///
/// It is assumed that either the only crate in the workspace is a binary, or that the crate
/// `package` has a binary or example matching `options.build_target`.
///
/// # Arguments
///
/// * `source_dir` - Directory containing Cargo.toml
/// * `package` - Package name for `-p` flag (required for multi-package workspaces)
/// * `options` - Build configuration
///
/// # Toolchain Handling
///
/// If `options.toolchain` is specified:
/// - Requires rustup (errors if unavailable)
/// - Invokes via `rustup run {toolchain} cargo build ...`
/// - This works regardless of whether cargo is a rustup proxy
///
/// # Binary Location
///
/// Uses `--message-format=json` to parse compiler artifacts and find the
/// executable path from "compiler-artifact" messages. This handles:
/// - Cross-compilation: target/{triple}/{profile}/...
/// - Examples: target/{profile}/examples/...
/// - Platform extensions: .exe on Windows
///
/// # Errors
///
/// - Cargo.toml not found in `source_dir`
/// - Toolchain specified but rustup not found
/// - Cargo build command fails
/// - Expected binary not found in cargo's JSON output
fn build(&self, source_dir: &Path, package: Option<&str>, options: &BuildOptions) -> Result<PathBuf>;
}
/// Locate cargo and construct a runner instance that will use it.
pub(crate) fn create_cargo_runner(config: Config, reporter: MessageReporter) -> Result<impl CargoRunner> {
// Locate cargo and rustup executables.
//
// Searches for cargo in priority order:
// 1. `CARGO` environment variable (cargo's own convention)
// 2. `cargo` in PATH (via `which` crate)
// 3. `$CARGO_HOME/bin/cargo` where CARGO_HOME defaults to ~/.cargo
//
// Also searches for rustup (needed for `rustup run {toolchain}`).
// Rustup not found is non-fatal - only errors when toolchain specified.
let cargo_path = find_executable("cargo", "CARGO")?;
let rustup_path = find_executable("rustup", "RUSTUP").ok();
Ok(RealCargoRunner {
cargo_path,
rustup_path,
reporter,
verbosity: config.verbosity,
})
}
#[derive(Debug, Clone)]
struct RealCargoRunner {
cargo_path: PathBuf,
rustup_path: Option<PathBuf>,
reporter: MessageReporter,
verbosity: Verbosity,
}
impl RealCargoRunner {
/// Construct the complete `cargo metadata` command for the given options.
///
/// When [`CargoMetadataOptions::toolchain`] is set, the command is routed through
/// `rustup run <toolchain> cargo`. This is the same technique used for `cargo build`
/// elsewhere in this module.
fn metadata_command(&self, source_dir: &Path, options: &CargoMetadataOptions) -> Result<Command> {
let mut cmd = cargo_metadata::MetadataCommand::new();
cmd.cargo_path(&self.cargo_path).current_dir(source_dir);
// Only exclude deps if explicitly requested
if options.no_deps {
cmd.no_deps();
}
// Handle feature flags
if options.all_features {
cmd.features(cargo_metadata::CargoOpt::AllFeatures);
} else {
if options.no_default_features {
cmd.features(cargo_metadata::CargoOpt::NoDefaultFeatures);
}
if !options.features.is_empty() {
cmd.features(cargo_metadata::CargoOpt::SomeFeatures(options.features.clone()));
}
}
// Build other_options for flags that don't have dedicated MetadataCommand methods
let mut other_args = Vec::new();
// Always filter by platform when resolving dependencies to avoid getting
// deps for all platforms mixed together. Default to current platform if not specified.
let platform: Option<&str> = if options.no_deps {
// When not resolving deps, platform filtering doesn't matter
options.filter_platform.as_ref().map(TargetTriple::as_str)
} else {
// When resolving deps, MUST filter by platform
// Default to current platform if not specified
Some(
options
.filter_platform
.as_ref()
.map_or_else(|| TargetTriple::host().as_str(), TargetTriple::as_str),
)
};
if let Some(platform_str) = platform {
other_args.push("--filter-platform".to_string());
other_args.push(platform_str.to_string());
}
if options.offline {
other_args.push("--offline".to_string());
}
if options.locked {
other_args.push("--locked".to_string());
}
if !other_args.is_empty() {
cmd.other_options(other_args);
}
// If no toolchain is specified then we're done, otherwise we need to construct a `rustup`
// invocation to set the toolchain.
let inner = cmd.cargo_command();
let Some(toolchain) = &options.toolchain else {
return Ok(inner);
};
let rustup_path = self
.rustup_path
.as_ref()
.with_context(|| error::RustupNotFoundSnafu {
toolchain: toolchain.clone(),
})?;
// The rendered cargo command's working directory does not transfer to the wrapping
// command, so set it again.
let mut wrapped = Command::new(rustup_path);
wrapped.args(["run", toolchain, "cargo"]);
wrapped.args(inner.get_args());
wrapped.current_dir(source_dir);
Ok(wrapped)
}
/// Run a fully constructed `cargo metadata` command and parse its output.
///
/// Mirrors [`cargo_metadata::MetadataCommand::exec`], which cannot be used directly because the
/// command may be wrapped in `rustup run`.
fn run_metadata_command(cmd: &mut Command) -> std::result::Result<Metadata, cargo_metadata::Error> {
let output = cmd.output()?;
if !output.status.success() {
return Err(cargo_metadata::Error::CargoMetadata {
stderr: String::from_utf8(output.stderr)?,
});
}
let stdout = std::str::from_utf8(&output.stdout)?
.lines()
.find(|line| line.starts_with('{'))
.ok_or(cargo_metadata::Error::NoJson)?;
cargo_metadata::MetadataCommand::parse(stdout)
}
}
impl CargoRunner for RealCargoRunner {
fn metadata(&self, source_dir: &Path, options: &CargoMetadataOptions) -> Result<Metadata> {
let mut cmd = self.metadata_command(source_dir, options)?;
let program = PathBuf::from(cmd.get_program());
Self::run_metadata_command(&mut cmd).with_context(|_| error::CargoMetadataSnafu {
cargo_path: program,
source_dir: source_dir.to_path_buf(),
})
}
fn build(&self, source_dir: &Path, package: Option<&str>, options: &BuildOptions) -> Result<PathBuf> {
// Verify Cargo.toml exists
if !source_dir.join("Cargo.toml").exists() {
return error::CargoTomlNotFoundSnafu {
source_dir: source_dir.to_path_buf(),
}
.fail();
}
self.reporter.report(|| BuildMessage::started(options));
// Build the command
let mut cmd = if let Some(toolchain) = &options.toolchain {
// If toolchain is specified, we need rustup
let rustup_path = self
.rustup_path
.as_ref()
.with_context(|| error::RustupNotFoundSnafu {
toolchain: toolchain.clone(),
})?;
let mut cmd = Command::new(rustup_path);
cmd.args(["run", toolchain, "cargo"]);
cmd
} else {
Command::new(&self.cargo_path)
};
// Add cargo build command and flags
cmd.arg("build");
cmd.current_dir(source_dir);
cmd.arg("--message-format=json");
// Profile (default to release)
if let Some(profile) = &options.profile {
cmd.args(["--profile", profile]);
} else {
cmd.arg("--release");
}
// Package selection for workspaces
if let Some(pkg) = package {
cmd.args(["-p", pkg]);
}
// Features
if options.all_features {
cmd.arg("--all-features");
} else {
if options.no_default_features {
cmd.arg("--no-default-features");
}
if !options.features.is_empty() {
cmd.arg("--features");
cmd.arg(options.features.join(","));
}
}
// Target triple for cross-compilation
if let Some(target) = &options.target {
cmd.args(["--target", target.as_str()]);
}
// Build target (bin/example)
match &options.build_target {
BuildTarget::DefaultBin => {
// No specific flag needed, cargo will build the default binary
}
BuildTarget::Bin(name) => {
cmd.args(["--bin", name]);
}
BuildTarget::Example(name) => {
cmd.args(["--example", name]);
}
}
// Other flags
if options.offline {
cmd.arg("--offline");
}
if let Some(jobs) = options.jobs {
cmd.args(["-j", &jobs.to_string()]);
}
if options.ignore_rust_version {
cmd.arg("--ignore-rust-version");
}
if options.locked {
cmd.arg("--locked");
}
// Translate the verbosity level to cargo's repeated `-v` flag.
match self.verbosity {
Verbosity::Normal => {}
Verbosity::Verbose => {
cmd.arg("-v");
}
Verbosity::VeryVerbose => {
cmd.arg("-vv");
}
Verbosity::ExtremelyVerbose => {
cmd.arg("-vvv");
}
}
// Configure pipes for streaming
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());
// Spawn the process
let mut child = cmd.spawn().context(error::CommandExecutionSnafu)?;
// Take ownership of stdout and stderr pipes
let stdout = child
.stdout
.take()
.with_context(|| error::BinaryNotFoundInOutputSnafu)?;
let stderr = child
.stderr
.take()
.with_context(|| error::BinaryNotFoundInOutputSnafu)?;
// Clone reporter for threads
let stdout_reporter = self.reporter.clone();
let stderr_reporter = self.reporter.clone();
// Clone build target for stdout thread
let build_target = options.build_target.clone();
// Spawn stdout parsing thread
let stdout_handle = thread::spawn(move || {
debug!("stdout parser thread starting");
let reader = BufReader::new(stdout);
let mut binary_path = None;
for line_result in reader.lines() {
let line = match line_result {
Ok(l) => l,
Err(_) => break,
};
if let Ok(cargo_msg) = serde_json::from_str::<cargo_metadata::Message>(&line) {
stdout_reporter.report(|| BuildMessage::cargo_message(cargo_msg.clone()));
if let cargo_metadata::Message::CompilerArtifact(artifact) = &cargo_msg {
let kinds = &artifact.target.kind;
let name = &artifact.target.name;
let matches = match &build_target {
BuildTarget::DefaultBin => {
kinds.iter().any(|k| *k == cargo_metadata::TargetKind::Bin)
}
BuildTarget::Bin(bin_name) => {
kinds.iter().any(|k| *k == cargo_metadata::TargetKind::Bin)
&& name == bin_name
}
BuildTarget::Example(ex_name) => {
kinds.iter().any(|k| *k == cargo_metadata::TargetKind::Example)
&& name == ex_name
}
};
if matches {
if let Some(exe) = &artifact.executable {
binary_path = Some(exe.clone().into_std_path_buf());
}
}
}
}
}
debug!("stdout parser thread exiting");
binary_path
});
// Spawn stderr chunk reading thread
let stderr_handle = thread::spawn(move || {
debug!("stderr reader thread starting");
let mut reader = BufReader::new(stderr);
let mut buffer = [0u8; 4096];
loop {
match reader.read(&mut buffer) {
Ok(0) | Err(_) => break,
Ok(n) => {
let chunk = buffer[..n].to_vec();
stderr_reporter.report(|| BuildMessage::cargo_stderr(chunk));
}
}
}
debug!("stderr reader thread exiting");
});
// Wait for process completion
let status = child.wait().context(error::CommandExecutionSnafu)?;
// Join both threads after wait() returns
let binary_path = stdout_handle.join().expect("BUG: stdout thread panicked");
stderr_handle.join().expect("BUG: stderr thread panicked");
if !status.success() {
return error::CargoBuildFailedSnafu {
exit_code: status.code(),
}
.fail();
}
match binary_path {
Some(path) => {
self.reporter.report(|| BuildMessage::completed(&path));
Ok(path)
}
None => error::BinaryNotFoundInOutputSnafu.fail(),
}
}
}
/// Find an executable by name, checking environment variable, PATH, and default locations.
fn find_executable(name: &str, env_var: &str) -> Result<PathBuf> {
// Check environment variable
if let Ok(path) = std::env::var(env_var) {
let path = PathBuf::from(path);
if path.exists() {
return Ok(path);
}
}
// Check PATH using `which` crate
if let Ok(path) = which::which(name) {
return Ok(path);
}
// Check $CARGO_HOME/bin/{name}
let cargo_home = std::env::var("CARGO_HOME")
.ok()
.map(PathBuf::from)
.or_else(|| home::cargo_home().ok());
if let Some(cargo_home) = cargo_home {
let path = cargo_home.join("bin").join(name);
if path.exists() {
return Ok(path);
}
}
error::ExecutableNotFoundSnafu {
name: name.to_string(),
}
.fail()
}
/// Testing a wrapper around `cargo` thoroughly is out of the scope of simple unit tests, however
/// we at least need to verify basic functionality and correctness.
///
/// By definition, if these tests are running, `cargo` must be present, so we've made some tests
/// that operate on this project itself as test data. Of course this isn't adequate coverage for
/// all various scenarios, but it's better than nothing.
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use super::*;
use crate::{builder::BuildTarget, testdata::CrateTestCase};
/// Get the path to the cgx workspace root directory.
fn cgx_project_root() -> PathBuf {
// CARGO_MANIFEST_DIR points to cgx-core, we need the workspace root (parent directory)
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("cgx-core should have a parent directory (workspace root)")
.to_path_buf()
}
#[test]
fn create_cargo_runner_succeeds() {
crate::logging::init_test_logging();
// This test verifies that we can locate cargo on the system.
// This should always succeed since cargo is required to run the tests.
let _cargo = create_cargo_runner(Config::default(), MessageReporter::null()).unwrap();
}
#[test]
fn metadata_reads_cgx_crate() {
crate::logging::init_test_logging();
let cargo = create_cargo_runner(Config::default(), MessageReporter::null()).unwrap();
let cgx_root = cgx_project_root();
let metadata = cargo
.metadata(
&cgx_root,
&CargoMetadataOptions {
no_deps: true,
..Default::default()
},
)
.unwrap();
// Verify we found the cgx package
let cgx_pkg = metadata
.packages
.iter()
.find(|p| p.name.as_str() == "cgx")
.unwrap();
assert_eq!(cgx_pkg.name.as_str(), "cgx");
// Verify version is valid semver
assert!(!cgx_pkg.version.to_string().is_empty());
// Verify we have at least one binary target
let has_bin = cgx_pkg
.targets
.iter()
.any(|t| t.kind.iter().any(|k| k.to_string() == "bin"));
assert!(has_bin, "cgx should have a binary target");
}
#[test]
fn build_compiles_cgx_in_tempdir() {
crate::logging::init_test_logging();
let cargo = create_cargo_runner(Config::default(), MessageReporter::null()).unwrap();
let cgx_root = cgx_project_root();
let temp_dir = tempfile::tempdir().unwrap();
// Copy source to temp directory
crate::helpers::copy_source_tree(&cgx_root, temp_dir.path()).unwrap();
// Verify Cargo.toml was copied
assert!(
temp_dir.path().join("Cargo.toml").exists(),
"Cargo.toml should be copied"
);
// Build in dev mode (faster than release)
let options = BuildOptions {
profile: Some("dev".to_string()),
build_target: BuildTarget::DefaultBin,
..Default::default()
};
let binary_path = cargo.build(temp_dir.path(), Some("cgx"), &options).unwrap();
// Verify binary exists and is a file
assert!(binary_path.exists(), "Binary should exist at {:?}", binary_path);
assert!(binary_path.is_file(), "Binary should be a file");
// Verify it's named correctly (cgx or cgx.exe on Windows)
let file_name = binary_path.file_name().and_then(|n| n.to_str()).unwrap();
assert!(
file_name == "cgx" || file_name == "cgx.exe",
"Binary should be named cgx or cgx.exe, got {}",
file_name
);
}
#[test]
fn metadata_command_uses_cargo_directly_without_toolchain() {
let cargo = RealCargoRunner {
cargo_path: PathBuf::from("/fake/cargo"),
rustup_path: None,
reporter: MessageReporter::null(),
verbosity: Verbosity::Normal,
};
let cmd = cargo
.metadata_command(Path::new("/src"), &CargoMetadataOptions::default())
.unwrap();
assert_eq!(cmd.get_program().to_string_lossy(), "/fake/cargo");
let args: Vec<String> = cmd
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(&args[..3], ["metadata", "--format-version", "1"]);
assert!(!args.contains(&"run".to_string()), "args: {args:?}");
}
#[test]
fn metadata_command_wraps_cargo_with_rustup_for_toolchain() {
let cargo = RealCargoRunner {
cargo_path: PathBuf::from("/fake/cargo"),
rustup_path: Some(PathBuf::from("/fake/rustup")),
reporter: MessageReporter::null(),
verbosity: Verbosity::Normal,
};
let cmd = cargo
.metadata_command(
Path::new("/src"),
&CargoMetadataOptions {
locked: true,
toolchain: Some("nightly".to_string()),
..Default::default()
},
)
.unwrap();
assert_eq!(cmd.get_program().to_string_lossy(), "/fake/rustup");
let args: Vec<String> = cmd
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(
&args[..6],
["run", "nightly", "cargo", "metadata", "--format-version", "1"]
);
assert!(args.contains(&"--locked".to_string()), "args: {args:?}");
}
#[test]
fn build_options_toolchain_carries_into_metadata_options() {
let build_options = BuildOptions {
toolchain: Some("nightly".to_string()),
..Default::default()
};
let metadata_options = CargoMetadataOptions::from(&build_options);
assert_eq!(metadata_options.toolchain.as_deref(), Some("nightly"));
}
/// Metadata queries follow the same toolchain contract as builds: a requested toolchain
/// requires rustup, rather than being silently resolved with the default cargo.
#[test]
fn metadata_with_toolchain_requires_rustup() {
crate::logging::init_test_logging();
let cargo = RealCargoRunner {
cargo_path: find_executable("cargo", "CARGO").unwrap(),
rustup_path: None,
reporter: MessageReporter::null(),
verbosity: Verbosity::Normal,
};
let result = cargo.metadata(
&cgx_project_root(),
&CargoMetadataOptions {
no_deps: true,
toolchain: Some("nightly".to_string()),
..Default::default()
},
);
assert_matches!(
result,
Err(error::Error::RustupNotFound { ref toolchain }) if toolchain == "nightly"
);
}
#[test]
fn metadata_loads_all_testcases() {
crate::logging::init_test_logging();
let cargo = create_cargo_runner(Config::default(), MessageReporter::null()).unwrap();
for testcase in CrateTestCase::all() {
let result = cargo.metadata(testcase.path(), &CargoMetadataOptions::default());
assert!(
result.is_ok(),
"Failed to load metadata for {}: {:?}",
testcase.name,
result.err()
);
}
}
}