2016-06-06 17:09:33 +00:00
|
|
|
use cargo::util::paths::dylib_path_envvar;
|
2018-03-14 15:17:44 +00:00
|
|
|
use cargotest::support::{execs, project, path2url};
|
2014-07-13 18:47:37 +00:00
|
|
|
use hamcrest::{assert_that, existing_file};
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple() {
|
2014-07-13 18:47:37 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-13 18:47:37 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-07-13 18:47:37 +00:00
|
|
|
fn main() { println!("hello"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `target[/]debug[/]foo[EXE]`",
|
|
|
|
dir = path2url(p.root())
|
|
|
|
))
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2014-07-13 18:47:37 +00:00
|
|
|
hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2014-07-17 01:44:30 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple_quiet() {
|
2014-10-21 18:48:16 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 18:48:16 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-10-21 18:48:16 +00:00
|
|
|
fn main() { println!("hello"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-21 18:48:16 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("-q"),
|
|
|
|
execs().with_status(0).with_stdout("hello"),
|
2018-03-12 20:08:49 +00:00
|
|
|
);
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--quiet"),
|
|
|
|
execs().with_status(0).with_stdout("hello"),
|
2014-10-21 18:48:16 +00:00
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-21 18:48:16 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple_quiet_and_verbose() {
|
2014-10-21 18:48:16 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-21 18:48:16 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-10-21 18:48:16 +00:00
|
|
|
fn main() { println!("hello"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-21 18:48:16 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("-q").arg("-v"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] cannot set both --verbose and --quiet
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-21 18:48:16 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn quiet_and_verbose_config() {
|
2016-04-18 05:02:44 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-04-18 05:02:44 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2016-04-18 05:02:44 +00:00
|
|
|
[term]
|
|
|
|
verbose = true
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-04-18 05:02:44 +00:00
|
|
|
fn main() { println!("hello"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-04-18 05:02:44 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("run").arg("-q"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-04-18 05:02:44 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple_with_args() {
|
2014-07-13 18:47:37 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-13 18:47:37 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-07-13 18:47:37 +00:00
|
|
|
fn main() {
|
2015-03-26 18:17:44 +00:00
|
|
|
assert_eq!(std::env::args().nth(1).unwrap(), "hello");
|
|
|
|
assert_eq!(std::env::args().nth(2).unwrap(), "world");
|
2014-07-13 18:47:37 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("hello").arg("world"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn exit_code() {
|
2014-07-13 18:47:37 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-13 18:47:37 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-06-13 00:37:19 +00:00
|
|
|
fn main() { std::process::exit(2); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
let mut output = String::from(
|
|
|
|
"\
|
2016-05-15 22:03:35 +00:00
|
|
|
[COMPILING] foo v0.0.1 (file[..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-15 22:03:35 +00:00
|
|
|
[RUNNING] `target[..]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
);
|
2016-07-01 04:31:36 +00:00
|
|
|
if !cfg!(unix) {
|
2018-03-14 15:17:44 +00:00
|
|
|
output.push_str(
|
|
|
|
"\
|
2016-09-14 18:10:30 +00:00
|
|
|
[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
);
|
2016-07-01 04:31:36 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("run"), execs().with_status(2).with_stderr(output));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn exit_code_verbose() {
|
2015-10-13 00:30:44 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-10-13 00:30:44 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-10-13 00:30:44 +00:00
|
|
|
fn main() { std::process::exit(2); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-10-13 00:30:44 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
let mut output = String::from(
|
|
|
|
"\
|
2016-05-15 22:03:35 +00:00
|
|
|
[COMPILING] foo v0.0.1 (file[..])
|
|
|
|
[RUNNING] `rustc [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-15 22:03:35 +00:00
|
|
|
[RUNNING] `target[..]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
);
|
2016-07-01 04:31:36 +00:00
|
|
|
if !cfg!(unix) {
|
2018-03-14 15:17:44 +00:00
|
|
|
output.push_str(
|
|
|
|
"\
|
2016-09-14 18:10:30 +00:00
|
|
|
[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
);
|
2016-07-01 04:31:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("-v"),
|
|
|
|
execs().with_status(2).with_stderr(output),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-13 00:30:44 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn no_main_file() {
|
2014-07-13 18:47:37 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-13 18:47:37 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2014-07-13 18:47:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"[ERROR] a bin target must be available \
|
|
|
|
for `cargo run`\n",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-22 16:53:56 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn too_many_bins() {
|
2014-08-22 16:53:56 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-22 16:53:56 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-08-22 16:53:56 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/bin/a.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin/b.rs", "")
|
|
|
|
.build();
|
2014-08-22 16:53:56 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"[ERROR] `cargo run` requires that a project only \
|
|
|
|
have one executable; use the `--bin` option \
|
|
|
|
to specify which one to run\navailable binaries: [..]\n",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn specify_name() {
|
2014-10-27 21:49:20 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-27 21:49:20 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-10-27 21:49:20 +00:00
|
|
|
extern crate foo;
|
|
|
|
fn main() { println!("hello a.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/b.rs",
|
|
|
|
r#"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-10-27 21:49:20 +00:00
|
|
|
extern crate foo;
|
|
|
|
fn main() { println!("hello b.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("a").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc [..] src[/]lib.rs [..]`
|
|
|
|
[RUNNING] `rustc [..] src[/]bin[/]a.rs [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `target[/]debug[/]a[EXE]`",
|
|
|
|
dir = path2url(p.root())
|
|
|
|
))
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2014-10-27 21:49:20 +00:00
|
|
|
hello a.rs
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("b").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc [..] src[/]bin[/]b.rs [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `target[/]debug[/]b[EXE]`",
|
|
|
|
)
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2014-10-27 21:49:20 +00:00
|
|
|
hello b.rs
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn run_example() {
|
2014-10-27 21:49:20 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-27 21:49:20 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("example"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("bin"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--example").arg("a"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `target[/]debug[/]examples[/]a[EXE]`",
|
|
|
|
dir = path2url(p.root())
|
|
|
|
))
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2017-03-24 20:20:38 +00:00
|
|
|
example
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2017-03-24 20:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-03-06 20:28:52 +00:00
|
|
|
fn run_bins() {
|
2017-03-24 20:20:38 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-03-24 20:20:38 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-03-24 20:20:38 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2017-03-24 20:20:38 +00:00
|
|
|
fn main() { println!("example"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2017-03-24 20:20:38 +00:00
|
|
|
fn main() { println!("bin"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-03-24 20:20:38 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bins"),
|
|
|
|
execs().with_status(1).with_stderr_contains(
|
|
|
|
"\
|
|
|
|
error: Found argument '--bins' which wasn't expected, or isn't valid in this context",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn run_with_filename() {
|
2016-03-14 17:22:17 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-03-14 17:22:17 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-03-14 17:22:17 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2016-03-14 17:22:17 +00:00
|
|
|
extern crate foo;
|
|
|
|
fn main() { println!("hello a.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2016-03-14 17:22:17 +00:00
|
|
|
fn main() { println!("example"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("bin.rs"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] no bin target named `bin.rs`",
|
|
|
|
),
|
|
|
|
);
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("a.rs"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] no bin target named `a.rs`
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
Did you mean `a`?",
|
|
|
|
),
|
|
|
|
);
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--example").arg("example.rs"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] no example target named `example.rs`",
|
|
|
|
),
|
|
|
|
);
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--example").arg("a.rs"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] no example target named `a.rs`
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
Did you mean `a`?",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-03-14 17:22:17 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn either_name_or_example() {
|
2014-10-27 21:49:20 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("hello a.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/b.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("hello b.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run")
|
|
|
|
.arg("--bin")
|
|
|
|
.arg("a")
|
|
|
|
.arg("--example")
|
|
|
|
.arg("b"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"[ERROR] `cargo run` can run at most one \
|
|
|
|
executable, but multiple were \
|
|
|
|
specified",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn one_bin_multiple_examples() {
|
2014-10-27 21:49:20 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-27 21:49:20 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/main.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("hello main.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("hello a.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/b.rs",
|
|
|
|
r#"
|
2014-10-27 21:49:20 +00:00
|
|
|
fn main() { println!("hello b.rs"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-10-27 21:49:20 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `target[/]debug[/]main[EXE]`",
|
|
|
|
dir = path2url(p.root())
|
|
|
|
))
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2014-10-27 21:49:20 +00:00
|
|
|
hello main.rs
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn example_with_release_flag() {
|
2015-01-03 16:33:08 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-01-03 16:33:08 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
version = "*"
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2015-01-03 16:33:08 +00:00
|
|
|
extern crate bar;
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-24 00:45:41 +00:00
|
|
|
if cfg!(debug_assertions) {
|
2015-01-03 16:33:08 +00:00
|
|
|
println!("slow1")
|
2015-03-24 00:45:41 +00:00
|
|
|
} else {
|
|
|
|
println!("fast1")
|
2015-01-03 16:33:08 +00:00
|
|
|
}
|
|
|
|
bar::baz();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2015-01-03 16:33:08 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/bar.rs",
|
|
|
|
r#"
|
2015-01-03 16:33:08 +00:00
|
|
|
pub fn baz() {
|
2015-03-24 00:45:41 +00:00
|
|
|
if cfg!(debug_assertions) {
|
2015-01-03 16:33:08 +00:00
|
|
|
println!("slow2")
|
2015-03-24 00:45:41 +00:00
|
|
|
} else {
|
|
|
|
println!("fast2")
|
2015-01-03 16:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-01-03 16:33:08 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run")
|
|
|
|
.arg("-v")
|
|
|
|
.arg("--release")
|
|
|
|
.arg("--example")
|
|
|
|
.arg("a"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.0.1 ({url}/bar)
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2015-01-03 16:33:08 +00:00
|
|
|
-C opt-level=3 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
2016-11-06 04:53:21 +00:00
|
|
|
--out-dir {dir}[/]target[/]release[/]deps \
|
|
|
|
-L dependency={dir}[/]target[/]release[/]deps`
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
2016-11-30 19:42:44 +00:00
|
|
|
[RUNNING] `rustc --crate-name a examples[/]a.rs --crate-type bin \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2015-01-03 16:33:08 +00:00
|
|
|
-C opt-level=3 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
2016-11-06 04:53:21 +00:00
|
|
|
--out-dir {dir}[/]target[/]release[/]examples \
|
|
|
|
-L dependency={dir}[/]target[/]release[/]deps \
|
2016-10-04 23:16:30 +00:00
|
|
|
--extern bar={dir}[/]target[/]release[/]deps[/]libbar-[..].rlib`
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2016-11-06 04:53:21 +00:00
|
|
|
[RUNNING] `target[/]release[/]examples[/]a[EXE]`
|
2015-01-03 16:33:08 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = path2url(p.root()),
|
|
|
|
))
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2016-05-15 21:48:11 +00:00
|
|
|
fast1
|
2018-03-14 15:17:44 +00:00
|
|
|
fast2",
|
|
|
|
),
|
|
|
|
);
|
2015-01-03 16:33:08 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("-v").arg("--example").arg("a"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.0.1 ({url}/bar)
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2017-01-12 05:35:17 +00:00
|
|
|
-C debuginfo=2 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
2016-11-06 04:53:21 +00:00
|
|
|
--out-dir {dir}[/]target[/]debug[/]deps \
|
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps`
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc --crate-name a examples[/]a.rs --crate-type bin \
|
2017-01-03 21:22:58 +00:00
|
|
|
--emit=dep-info,link \
|
2017-01-12 05:35:17 +00:00
|
|
|
-C debuginfo=2 \
|
2016-08-02 06:22:29 +00:00
|
|
|
-C metadata=[..] \
|
2016-11-06 04:53:21 +00:00
|
|
|
--out-dir {dir}[/]target[/]debug[/]examples \
|
|
|
|
-L dependency={dir}[/]target[/]debug[/]deps \
|
2016-10-04 23:16:30 +00:00
|
|
|
--extern bar={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 04:53:21 +00:00
|
|
|
[RUNNING] `target[/]debug[/]examples[/]a[EXE]`
|
2015-01-03 16:33:08 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.root().display(),
|
|
|
|
url = path2url(p.root()),
|
|
|
|
))
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2016-05-15 21:48:11 +00:00
|
|
|
slow1
|
2018-03-14 15:17:44 +00:00
|
|
|
slow2",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-03 16:33:08 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn run_dylib_dep() {
|
2014-08-07 00:50:55 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-07 00:50:55 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-08-07 00:50:55 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() { bar::bar(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-08-07 00:50:55 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-08-07 00:50:55 +00:00
|
|
|
name = "bar"
|
|
|
|
crate-type = ["dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.build();
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("hello").arg("world"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-22 16:53:56 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn release_works() {
|
2014-08-25 14:51:13 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-25 14:51:13 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-03-24 00:45:41 +00:00
|
|
|
fn main() { if cfg!(debug_assertions) { panic!() } }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-25 14:51:13 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--release"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2016-11-06 04:53:21 +00:00
|
|
|
[RUNNING] `target[/]release[/]foo[EXE]`
|
2014-08-25 14:51:13 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = path2url(p.root()),
|
|
|
|
)),
|
|
|
|
);
|
2014-08-25 14:51:13 +00:00
|
|
|
assert_that(&p.release_bin("foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-27 15:04:38 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn run_bin_different_name() {
|
2014-08-22 16:53:56 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-22 16:53:56 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bar.rs",
|
|
|
|
r#"
|
2014-08-22 16:53:56 +00:00
|
|
|
fn main() { }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-22 16:53:56 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("run"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-28 01:08:28 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dashes_are_forwarded() {
|
2015-07-28 01:08:28 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-07-28 01:08:28 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-07-28 01:08:28 +00:00
|
|
|
fn main() {
|
|
|
|
let s: Vec<String> = std::env::args().collect();
|
|
|
|
assert_eq!(s[1], "a");
|
|
|
|
assert_eq!(s[2], "--");
|
|
|
|
assert_eq!(s[3], "b");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-07-28 01:08:28 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--").arg("a").arg("--").arg("b"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-29 11:03:14 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn run_from_executable_folder() {
|
2015-08-29 11:03:14 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-08-29 11:03:14 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-08-29 11:03:14 +00:00
|
|
|
fn main() { println!("hello"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-08-29 11:03:14 +00:00
|
|
|
|
|
|
|
let cwd = p.root().join("target").join("debug");
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build").exec_with_output().unwrap();
|
2015-08-29 11:03:14 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").cwd(cwd),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n\
|
|
|
|
[RUNNING] `.[/]foo[EXE]`",
|
|
|
|
)
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
2015-08-29 11:03:14 +00:00
|
|
|
hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-06-06 17:09:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_with_library_paths() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo");
|
2017-02-07 05:13:37 +00:00
|
|
|
|
|
|
|
// Only link search directories within the target output directory are
|
|
|
|
// propagated through to dylib_path_envvar() (see #3366).
|
|
|
|
let mut dir1 = p.target_debug_dir();
|
2017-02-07 20:55:36 +00:00
|
|
|
dir1.push("foo\\backslash");
|
2017-02-07 05:13:37 +00:00
|
|
|
|
|
|
|
let mut dir2 = p.target_debug_dir();
|
|
|
|
dir2.push("dir=containing=equal=signs");
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
let p = p.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-06 17:09:33 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
).file(
|
|
|
|
"build.rs",
|
|
|
|
&format!(
|
|
|
|
r##"
|
2017-02-07 05:13:37 +00:00
|
|
|
fn main() {{
|
2017-02-07 20:55:36 +00:00
|
|
|
println!(r#"cargo:rustc-link-search=native={}"#);
|
|
|
|
println!(r#"cargo:rustc-link-search={}"#);
|
2017-02-07 05:13:37 +00:00
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"##,
|
|
|
|
dir1.display(),
|
|
|
|
dir2.display()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
&format!(
|
|
|
|
r##"
|
2016-06-06 17:09:33 +00:00
|
|
|
fn main() {{
|
|
|
|
let search_path = std::env::var_os("{}").unwrap();
|
|
|
|
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
|
2017-02-07 20:55:36 +00:00
|
|
|
assert!(paths.contains(&r#"{}"#.into()));
|
|
|
|
assert!(paths.contains(&r#"{}"#.into()));
|
2016-06-06 17:09:33 +00:00
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"##,
|
|
|
|
dylib_path_envvar(),
|
|
|
|
dir1.display(),
|
|
|
|
dir2.display()
|
|
|
|
),
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-06-06 17:09:33 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("run"), execs().with_status(0));
|
2016-06-06 17:09:33 +00:00
|
|
|
}
|
2016-06-09 11:14:41 +00:00
|
|
|
|
2018-01-20 17:57:17 +00:00
|
|
|
#[test]
|
|
|
|
fn library_paths_sorted_alphabetically() {
|
|
|
|
let p = project("foo");
|
|
|
|
|
|
|
|
let mut dir1 = p.target_debug_dir();
|
|
|
|
dir1.push("zzzzzzz");
|
|
|
|
|
|
|
|
let mut dir2 = p.target_debug_dir();
|
|
|
|
dir2.push("BBBBBBB");
|
|
|
|
|
|
|
|
let mut dir3 = p.target_debug_dir();
|
|
|
|
dir3.push("aaaaaaa");
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
let p = p.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-01-20 17:57:17 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
).file(
|
|
|
|
"build.rs",
|
|
|
|
&format!(
|
|
|
|
r##"
|
2018-01-20 17:57:17 +00:00
|
|
|
fn main() {{
|
|
|
|
println!(r#"cargo:rustc-link-search=native={}"#);
|
|
|
|
println!(r#"cargo:rustc-link-search=native={}"#);
|
|
|
|
println!(r#"cargo:rustc-link-search=native={}"#);
|
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"##,
|
|
|
|
dir1.display(),
|
|
|
|
dir2.display(),
|
|
|
|
dir3.display()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
&format!(
|
|
|
|
r##"
|
2018-01-20 17:57:17 +00:00
|
|
|
fn main() {{
|
|
|
|
let search_path = std::env::var_os("{}").unwrap();
|
|
|
|
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
|
|
|
|
// ASCII case-sensitive sort
|
|
|
|
assert_eq!("BBBBBBB", paths[0].file_name().unwrap().to_string_lossy());
|
|
|
|
assert_eq!("aaaaaaa", paths[1].file_name().unwrap().to_string_lossy());
|
|
|
|
assert_eq!("zzzzzzz", paths[2].file_name().unwrap().to_string_lossy());
|
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"##,
|
|
|
|
dylib_path_envvar()
|
|
|
|
),
|
|
|
|
)
|
2018-01-20 17:57:17 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(p.cargo("run"), execs().with_status(0));
|
|
|
|
}
|
|
|
|
|
2016-06-09 11:14:41 +00:00
|
|
|
#[test]
|
|
|
|
fn fail_no_extra_verbose() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-09 11:14:41 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-06-09 11:14:41 +00:00
|
|
|
fn main() {
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-06-09 11:14:41 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("-q"),
|
|
|
|
execs().with_status(1).with_stdout("").with_stderr(""),
|
|
|
|
);
|
2016-06-09 11:14:41 +00:00
|
|
|
}
|
2017-02-13 16:02:27 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_multiple_packages() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-02-13 16:02:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
d1 = { path = "d1" }
|
|
|
|
d2 = { path = "d2" }
|
|
|
|
d3 = { path = "../d3" } # outside of the workspace
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-13 16:02:27 +00:00
|
|
|
.file("foo/src/foo.rs", "fn main() { println!(\"foo\"); }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"foo/d1/Cargo.toml",
|
|
|
|
r#"
|
2017-02-13 16:02:27 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "d1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-13 16:02:27 +00:00
|
|
|
.file("foo/d1/src/lib.rs", "")
|
|
|
|
.file("foo/d1/src/main.rs", "fn main() { println!(\"d1\"); }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"foo/d2/Cargo.toml",
|
|
|
|
r#"
|
2017-02-13 16:02:27 +00:00
|
|
|
[package]
|
|
|
|
name = "d2"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "d2"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-13 16:02:27 +00:00
|
|
|
.file("foo/d2/src/main.rs", "fn main() { println!(\"d2\"); }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d3/Cargo.toml",
|
|
|
|
r#"
|
2017-02-13 16:02:27 +00:00
|
|
|
[package]
|
|
|
|
name = "d3"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("d3/src/main.rs", "fn main() { println!(\"d2\"); }")
|
|
|
|
.build();
|
2017-02-13 16:02:27 +00:00
|
|
|
|
|
|
|
let cargo = || {
|
|
|
|
let mut process_builder = p.cargo("run");
|
|
|
|
process_builder.cwd(p.root().join("foo"));
|
|
|
|
process_builder
|
|
|
|
};
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
cargo().arg("-p").arg("d1"),
|
|
|
|
execs().with_status(0).with_stdout("d1"),
|
|
|
|
);
|
2017-02-13 16:02:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
cargo().arg("-p").arg("d2").arg("--bin").arg("d2"),
|
|
|
|
execs().with_status(0).with_stdout("d2"),
|
|
|
|
);
|
2017-02-13 16:02:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(cargo(), execs().with_status(0).with_stdout("foo"));
|
2017-02-13 16:02:27 +00:00
|
|
|
|
|
|
|
assert_that(cargo().arg("-p").arg("d1").arg("-p").arg("d2"),
|
|
|
|
execs()
|
|
|
|
.with_status(1)
|
2018-03-10 15:30:24 +00:00
|
|
|
.with_stderr_contains("\
|
2018-03-08 18:55:12 +00:00
|
|
|
error: The argument '--package <SPEC>' was provided more than once, but cannot be used multiple times
|
2018-03-10 15:30:24 +00:00
|
|
|
"));
|
2017-02-13 16:02:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
cargo().arg("-p").arg("d3"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[ERROR] package `d3` is not a member of the workspace"),
|
|
|
|
);
|
2017-02-13 16:02:27 +00:00
|
|
|
}
|