Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply --all if workspace is virtual #4025

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, CliError, Human, Config, human};
Expand Down Expand Up @@ -84,19 +86,24 @@ Compilation can be customized with the `bench` profile in the manifest.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
debug!("executing; cmd=cargo-bench; args={:?}",
env::args().collect::<Vec<_>>());

config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;

let spec = if options.flag_all {
let spec = if options.flag_all || ws.is_virtual() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, won't this break a use case when you are in the root of the workspace, but want to exercise a particular package?

I am thinking about something like this:

ws_root/
  Cargo.toml
  foo/
    Cargo.toml
  bar/
    Cargo.toml
$ pwd
~/projects/ws_root/
$ cargo test --pkg foo

If I am right, and the tests are green, this also means that some test is missing :)

Packages::All
} else {
Packages::Packages(&options.flag_package)
};

config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;
let ops = ops::TestOptions {
no_run: options.flag_no_run,
no_fail_fast: false,
Expand All @@ -122,7 +129,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
},
};

let ws = Workspace::new(&root, config)?;
let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
match err {
None => Ok(()),
Expand Down
4 changes: 2 additions & 2 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
options.flag_locked)?;

let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;

let spec = if options.flag_all {
let spec = if options.flag_all || ws.is_virtual() {
Packages::All
} else {
Packages::Packages(&options.flag_package)
Expand All @@ -116,7 +117,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
target_rustc_args: None,
};

let ws = Workspace::new(&root, config)?;
ops::compile(&ws, &opts)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/bin/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;

let spec = if options.flag_all {
let spec = if options.flag_all || ws.is_virtual() {
Packages::All
} else {
Packages::Packages(&options.flag_package)
Expand Down
9 changes: 7 additions & 2 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, Config};
Expand Down Expand Up @@ -69,15 +71,19 @@ the `cargo help pkgid` command.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());

config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;

let spec = if options.flag_all {
let spec = if options.flag_all || ws.is_virtual() {
Packages::All
} else {
Packages::Packages(&options.flag_package)
Expand Down Expand Up @@ -109,7 +115,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
},
};

let ws = Workspace::new(&root, config)?;
ops::doc(&ws, &doc_opts)?;
Ok(())
}
9 changes: 7 additions & 2 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, CliError, Human, human, Config};
Expand Down Expand Up @@ -107,13 +109,17 @@ To get the list of all options available for the test binaries use this:
";

pub fn execute(options: Options, config: &Config) -> CliResult {
debug!("executing; cmd=cargo-test; args={:?}",
env::args().collect::<Vec<_>>());

config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;

let empty = Vec::new();
let (mode, filter);
Expand All @@ -130,7 +136,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
&options.flag_bench, options.flag_benches);
}

let spec = if options.flag_all {
let spec = if options.flag_all || ws.is_virtual() {
Packages::All
} else {
Packages::Packages(&options.flag_package)
Expand All @@ -157,7 +163,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
},
};

let ws = Workspace::new(&root, config)?;
let err = ops::run_tests(&ws, &ops, &options.arg_args)?;
match err {
None => Ok(()),
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ impl<'cfg> Workspace<'cfg> {
}
}

pub fn is_virtual(&self) -> bool {
match *self.packages.get(&self.current_manifest) {
MaybePackage::Package(..) => false,
MaybePackage::Virtual(..) => true
}
}

/// Returns the `Config` this workspace is associated with.
pub fn config(&self) -> &'cfg Config {
self.config
Expand Down
65 changes: 65 additions & 0 deletions tests/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,3 +1067,68 @@ fn bench_all_virtual_manifest() {
.with_stdout_contains("test bench_foo ... bench: [..]"));
}

#[test]
fn bench_virtual_manifest_all_implied() {
if !is_nightly() { return }

let p = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["foo", "bar"]
"#)
.file("foo/Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
"#)
.file("foo/src/lib.rs", r#"
pub fn foo() {}
"#)
.file("foo/benches/foo.rs", r#"
#![feature(test)]
extern crate test;

use test::Bencher;

#[bench]
fn bench_foo(_: &mut Bencher) -> () { () }
"#)
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
"#)
.file("bar/src/lib.rs", r#"
pub fn bar() {}
"#)
.file("bar/benches/bar.rs", r#"
#![feature(test)]
extern crate test;

use test::Bencher;

#[bench]
fn bench_bar(_: &mut Bencher) -> () { () }
"#);

// The order in which foo and bar are built is not guaranteed
assert_that(p.cargo_process("bench"),
execs().with_status(0)
.with_stderr_contains("\
[RUNNING] target[/]release[/]deps[/]bar-[..][EXE]")
.with_stdout_contains("
running 1 test
test bench_bar ... bench: 0 ns/iter (+/- 0)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
")
.with_stderr_contains("\
[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]")
.with_stdout_contains("
running 1 test
test bench_foo ... bench: 0 ns/iter (+/- 0)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
}

34 changes: 34 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2883,6 +2883,40 @@ fn build_all_virtual_manifest() {
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n"));
}

#[test]
fn build_virtual_manifest_all_implied() {
let p = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["foo", "bar"]
"#)
.file("foo/Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
"#)
.file("foo/src/lib.rs", r#"
pub fn foo() {}
"#)
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
"#)
.file("bar/src/lib.rs", r#"
pub fn bar() {}
"#);

// The order in which foo and bar are built is not guaranteed
assert_that(p.cargo_process("build"),
execs().with_status(0)
.with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
.with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\
[..] Compiling [..] v0.1.0 ([..])\n\
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n"));
}

#[test]
fn build_all_virtual_manifest_implicit_examples() {
let p = project("foo")
Expand Down
31 changes: 31 additions & 0 deletions tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,34 @@ fn check_all() {
.with_stderr_contains("[..] --crate-name b b[/]src[/]main.rs [..]")
);
}

#[test]
fn check_virtual_all_implied() {
let p = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["foo", "bar"]
"#)
.file("foo/Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
"#)
.file("foo/src/lib.rs", r#"
pub fn foo() {}
"#)
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
"#)
.file("bar/src/lib.rs", r#"
pub fn bar() {}
"#);

assert_that(p.cargo_process("check").arg("-v"),
execs().with_status(0)
.with_stderr_contains("[..] --crate-name foo foo[/]src[/]lib.rs [..]")
.with_stderr_contains("[..] --crate-name bar bar[/]src[/]lib.rs [..]")
);
}
31 changes: 31 additions & 0 deletions tests/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,37 @@ fn doc_all_virtual_manifest() {
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])"));
}

#[test]
fn doc_virtual_manifest_all_implied() {
let p = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["foo", "bar"]
"#)
.file("foo/Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
"#)
.file("foo/src/lib.rs", r#"
pub fn foo() {}
"#)
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
"#)
.file("bar/src/lib.rs", r#"
pub fn bar() {}
"#);

// The order in which foo and bar are documented is not guaranteed
assert_that(p.cargo_process("doc"),
execs().with_status(0)
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])"));
}

#[test]
fn doc_all_member_dependency_same_name() {
let p = project("workspace")
Expand Down
43 changes: 43 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,49 @@ fn test_all_virtual_manifest() {
.with_stdout_contains("test b ... ok"));
}

#[test]
fn test_virtual_manifest_all_implied() {
let p = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["a", "b"]
"#)
.file("a/Cargo.toml", r#"
[project]
name = "a"
version = "0.1.0"
"#)
.file("a/src/lib.rs", r#"
#[test]
fn a() {}
"#)
.file("b/Cargo.toml", r#"
[project]
name = "b"
version = "0.1.0"
"#)
.file("b/src/lib.rs", r#"
#[test]
fn b() {}
"#);

assert_that(p.cargo_process("test"),
execs().with_status(0).with_stdout_contains("\
running 1 test
test b ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

")
.with_stdout_contains("\
running 1 test
test b ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

"));
}

#[test]
fn test_all_member_dependency_same_name() {
let p = project("workspace")
Expand Down
Loading