Skip to content

Commit

Permalink
fix cargo-test-support doc test
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed May 4, 2023
1 parent 796f9ac commit 30f4b17
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
7 changes: 5 additions & 2 deletions crates/cargo-test-support/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(path: P, name: &'static str) {
assert!(check_has_installed_exe(path, name));
Expand Down
6 changes: 4 additions & 2 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 41 additions & 36 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,39 +451,44 @@ 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;
///
/// // 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();
/// 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 {
Expand Down Expand Up @@ -1240,7 +1245,7 @@ impl Package {
}

/// Adds a normal dependency. Example:
/// ```
/// ```toml
/// [dependencies]
/// foo = {version = "1.0"}
/// ```
Expand All @@ -1249,7 +1254,7 @@ impl Package {
}

/// Adds a dependency with the given feature. Example:
/// ```
/// ```toml
/// [dependencies]
/// foo = {version = "1.0", "features": ["feat1", "feat2"]}
/// ```
Expand All @@ -1272,7 +1277,7 @@ impl Package {
}

/// Adds a dev-dependency. Example:
/// ```
/// ```toml
/// [dev-dependencies]
/// foo = {version = "1.0"}
/// ```
Expand All @@ -1281,7 +1286,7 @@ impl Package {
}

/// Adds a build-dependency. Example:
/// ```
/// ```toml
/// [build-dependencies]
/// foo = {version = "1.0"}
/// ```
Expand Down

0 comments on commit 30f4b17

Please sign in to comment.