diff --git a/crates/cargo-test-support/src/install.rs b/crates/cargo-test-support/src/install.rs index 478b482d2b59..569e6c9dc6ce 100644 --- a/crates/cargo-test-support/src/install.rs +++ b/crates/cargo-test-support/src/install.rs @@ -4,8 +4,11 @@ use std::path::{Path, PathBuf}; /// Used by `cargo install` tests to assert an executable binary /// has been installed. Example usage: -/// -/// assert_has_installed_exe(cargo_home(), "foo"); +/// +/// use cargo_test_support::install::assert_has_installed_exe; +/// use cargo_test_support::install::cargo_home; +/// +/// assert_has_installed_exe(cargo_home(), "foo"); #[track_caller] pub fn assert_has_installed_exe>(path: P, name: &'static str) { assert!(check_has_installed_exe(path, name)); diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 7003dd06aa67..fc30c9096e6a 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -700,13 +700,15 @@ impl Execs { /// The substrings are matched as `contains`. Example: /// /// ```no_run - /// execs.with_stderr_line_without( + /// use cargo_test_support::execs; + /// + /// execs().with_stderr_line_without( /// &[ /// "[RUNNING] `rustc --crate-name build_script_build", /// "-C opt-level=3", /// ], /// &["-C debuginfo", "-C incremental"], - /// ) + /// ); /// ``` /// /// This will check that a build line includes `-C opt-level=3` but does diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 5faf23540455..c5534e053f79 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -451,39 +451,46 @@ impl RegistryBuilder { /// /// # Example /// ``` -/// // Publish package "a" depending on "b". -/// Package::new("a", "1.0.0") -/// .dep("b", "1.0.0") -/// .file("src/lib.rs", r#" -/// extern crate b; -/// pub fn f() -> i32 { b::f() * 2 } -/// "#) -/// .publish(); +/// use cargo_test_support::registry::Package; +/// use cargo_test_support::project; +/// use cargo_test_support::cargo_test; /// -/// // Publish package "b". -/// Package::new("b", "1.0.0") -/// .file("src/lib.rs", r#" -/// pub fn f() -> i32 { 12 } -/// "#) -/// .publish(); -/// -/// // Create a project that uses package "a". -/// let p = project() -/// .file("Cargo.toml", r#" -/// [package] -/// name = "foo" -/// version = "0.0.1" -/// -/// [dependencies] -/// a = "1.0" -/// "#) -/// .file("src/main.rs", r#" -/// extern crate a; -/// fn main() { println!("{}", a::f()); } -/// "#) -/// .build(); -/// -/// p.cargo("run").with_stdout("24").run(); +/// #[cargo_test] +/// fn crate_package_test() { +/// // Publish package "a" depending on "b". +/// Package::new("a", "1.0.0") +/// .dep("b", "1.0.0") +/// .file("src/lib.rs", r#" +/// extern crate b; +/// pub fn f() -> i32 { b::f() * 2 } +/// "#) +/// .publish(); +/// +/// // Publish package "b". +/// Package::new("b", "1.0.0") +/// .file("src/lib.rs", r#" +/// pub fn f() -> i32 { 12 } +/// "#) +/// .publish(); +/// +/// // Create a project that uses package "a". +/// let p = project() +/// .file("Cargo.toml", r#" +/// [package] +/// name = "foo" +/// version = "0.0.1" +/// +/// [dependencies] +/// a = "1.0" +/// "#) +/// .file("src/main.rs", r#" +/// extern crate a; +/// fn main() { println!("{}", a::f()); } +/// "#) +/// .build(); +/// +/// p.cargo("run").with_stdout("24").run(); +/// } /// ``` #[must_use] pub struct Package { @@ -1240,7 +1247,7 @@ impl Package { } /// Adds a normal dependency. Example: - /// ``` + /// ```toml /// [dependencies] /// foo = {version = "1.0"} /// ``` @@ -1249,7 +1256,7 @@ impl Package { } /// Adds a dependency with the given feature. Example: - /// ``` + /// ```toml /// [dependencies] /// foo = {version = "1.0", "features": ["feat1", "feat2"]} /// ``` @@ -1272,7 +1279,7 @@ impl Package { } /// Adds a dev-dependency. Example: - /// ``` + /// ```toml /// [dev-dependencies] /// foo = {version = "1.0"} /// ``` @@ -1281,7 +1288,7 @@ impl Package { } /// Adds a build-dependency. Example: - /// ``` + /// ```toml /// [build-dependencies] /// foo = {version = "1.0"} /// ```