Skip to content

Commit 5a56cf2

Browse files
committed
Refactor echo cargo subcommand test helper into cargo-test-support
1 parent ddf9adb commit 5a56cf2

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

crates/cargo-test-support/src/tools.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Common executables that can be reused by various tests.
22
3-
use crate::{basic_manifest, paths, project};
3+
use crate::{basic_manifest, paths, project, Project};
44
use lazy_static::lazy_static;
55
use std::path::PathBuf;
66
use std::sync::Mutex;
@@ -38,3 +38,22 @@ pub fn echo_wrapper() -> PathBuf {
3838
*lock = Some(path.clone());
3939
path
4040
}
41+
42+
/// Returns a project which builds a cargo-echo simple subcommand
43+
pub fn echo_subcommand() -> Project {
44+
let p = project()
45+
.at("cargo-echo")
46+
.file("Cargo.toml", &basic_manifest("cargo-echo", "0.0.1"))
47+
.file(
48+
"src/main.rs",
49+
r#"
50+
fn main() {
51+
let args: Vec<_> = ::std::env::args().skip(1).collect();
52+
println!("{}", args.join(" "));
53+
}
54+
"#,
55+
)
56+
.build();
57+
p.cargo("build").run();
58+
p
59+
}

tests/testsuite/cargo_command.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use std::path::{Path, PathBuf};
77
use std::process::Stdio;
88
use std::str;
99

10-
use cargo_test_support::cargo_process;
11-
use cargo_test_support::paths;
1210
use cargo_test_support::registry::Package;
13-
use cargo_test_support::{basic_bin_manifest, basic_manifest, cargo_exe, project, project_in_home};
11+
use cargo_test_support::tools::echo_subcommand;
12+
use cargo_test_support::{
13+
basic_bin_manifest, cargo_exe, cargo_process, paths, project, project_in_home,
14+
};
1415

1516
fn path() -> Vec<PathBuf> {
1617
env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect()
@@ -283,31 +284,17 @@ fn cargo_subcommand_env() {
283284

284285
#[cargo_test]
285286
fn cargo_subcommand_args() {
286-
let p = project()
287-
.at("cargo-foo")
288-
.file("Cargo.toml", &basic_manifest("cargo-foo", "0.0.1"))
289-
.file(
290-
"src/main.rs",
291-
r#"
292-
fn main() {
293-
let args: Vec<_> = ::std::env::args().collect();
294-
println!("{}", args.join(" "));
295-
}
296-
"#,
297-
)
298-
.build();
299-
300-
p.cargo("build").run();
301-
let cargo_foo_bin = p.bin("cargo-foo");
287+
let p = echo_subcommand();
288+
let cargo_foo_bin = p.bin("cargo-echo");
302289
assert!(cargo_foo_bin.is_file());
303290

304291
let mut path = path();
305292
path.push(p.target_debug_dir());
306293
let path = env::join_paths(path.iter()).unwrap();
307294

308-
cargo_process("foo bar -v --help")
295+
cargo_process("echo bar -v --help")
309296
.env("PATH", &path)
310-
.with_stdout("[CWD]/cargo-foo/target/debug/cargo-foo[EXE] foo bar -v --help")
297+
.with_stdout("echo bar -v --help")
311298
.run();
312299
}
313300

0 commit comments

Comments
 (0)