|
| 1 | +//! Tests that `-m` is a valid shorthand for `--manifest-path` across relevant commands |
| 2 | +
|
| 3 | +use crate::prelude::cargo_test; |
| 4 | + |
| 5 | +#[cargo_test] |
| 6 | +fn add() { |
| 7 | + command("add some-package").with_dependency().run(); |
| 8 | +} |
| 9 | + |
| 10 | +#[cargo_test] |
| 11 | +fn build() { |
| 12 | + command("build").run(); |
| 13 | +} |
| 14 | + |
| 15 | +#[cargo_test] |
| 16 | +fn check() { |
| 17 | + command("check").run(); |
| 18 | +} |
| 19 | + |
| 20 | +#[cargo_test] |
| 21 | +fn clean() { |
| 22 | + command("clean").run(); |
| 23 | +} |
| 24 | + |
| 25 | +#[cargo_test] |
| 26 | +fn remove() { |
| 27 | + command("remove some-package").with_dependency().run(); |
| 28 | +} |
| 29 | + |
| 30 | +#[cargo_test] |
| 31 | +fn run() { |
| 32 | + command("run").run(); |
| 33 | +} |
| 34 | + |
| 35 | +fn command(command: &str) -> TestBuilder<'_> { |
| 36 | + TestBuilder { |
| 37 | + command, |
| 38 | + include_dependency: false, |
| 39 | + include_lockfile: false, |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +struct TestBuilder<'a> { |
| 44 | + command: &'a str, |
| 45 | + include_dependency: bool, |
| 46 | + include_lockfile: bool, |
| 47 | +} |
| 48 | + |
| 49 | +impl TestBuilder<'_> { |
| 50 | + fn with_dependency(self) -> Self { |
| 51 | + Self { |
| 52 | + include_dependency: true, |
| 53 | + ..self |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + #[track_caller] |
| 58 | + fn run(self) { |
| 59 | + use crate::utils::ext::CargoProjectExt as _; |
| 60 | + |
| 61 | + if self.include_dependency { |
| 62 | + cargo_test_support::registry::init(); |
| 63 | + cargo_test_support::registry::Package::new("some-package", "0.0.1+some-package") |
| 64 | + .publish(); |
| 65 | + } |
| 66 | + |
| 67 | + let p = cargo_test_support::project() |
| 68 | + .file("Cargo.toml", &dummy_manifest(self.include_dependency)) |
| 69 | + .file( |
| 70 | + "src/foo.rs", |
| 71 | + &cargo_test_support::main_file(r#""i am foo""#, &[]), |
| 72 | + ); |
| 73 | + |
| 74 | + let p = if self.include_lockfile { |
| 75 | + p.file("Cargo.lock", "") |
| 76 | + } else { |
| 77 | + p |
| 78 | + }; |
| 79 | + |
| 80 | + let p = p.build(); |
| 81 | + |
| 82 | + p.cargo(self.command) |
| 83 | + .arg("-m") |
| 84 | + .arg("foo/Cargo.toml") |
| 85 | + .cwd(p.root().parent().unwrap()) |
| 86 | + .run(); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +fn dummy_manifest(include_dependency: bool) -> String { |
| 91 | + let name = "foo"; |
| 92 | + let dependencies = if include_dependency { |
| 93 | + r#" |
| 94 | + [dependencies] |
| 95 | + some-package = "0.0.1+some-package" |
| 96 | + "# |
| 97 | + } else { |
| 98 | + "" |
| 99 | + }; |
| 100 | + |
| 101 | + format!( |
| 102 | + r#" |
| 103 | + [package] |
| 104 | +
|
| 105 | + name = "{name}" |
| 106 | + version = "0.5.0" |
| 107 | + authors = ["wycats@example.com"] |
| 108 | + edition = "2015" |
| 109 | +
|
| 110 | + [[bin]] |
| 111 | +
|
| 112 | + name = "{name}" |
| 113 | +
|
| 114 | + {dependencies} |
| 115 | + "# |
| 116 | + ) |
| 117 | +} |
0 commit comments