Skip to content

Commit ea0d487

Browse files
committed
fix cargo-test-support doc test
1 parent 796f9ac commit ea0d487

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::path::{Path, PathBuf};
55
/// Used by `cargo install` tests to assert an executable binary
66
/// has been installed. Example usage:
77
///
8-
/// assert_has_installed_exe(cargo_home(), "foo");
8+
/// use cargo_test_support::install::assert_has_installed_exe;
9+
/// use cargo_test_support::install::cargo_home;
10+
///
11+
/// assert_has_installed_exe(cargo_home(), "foo");
912
#[track_caller]
1013
pub fn assert_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
1114
assert!(check_has_installed_exe(path, name));

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,15 @@ impl Execs {
700700
/// The substrings are matched as `contains`. Example:
701701
///
702702
/// ```no_run
703-
/// execs.with_stderr_line_without(
703+
/// use cargo_test_support::execs;
704+
///
705+
/// execs().with_stderr_line_without(
704706
/// &[
705707
/// "[RUNNING] `rustc --crate-name build_script_build",
706708
/// "-C opt-level=3",
707709
/// ],
708710
/// &["-C debuginfo", "-C incremental"],
709-
/// )
711+
/// );
710712
/// ```
711713
///
712714
/// This will check that a build line includes `-C opt-level=3` but does

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

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -451,39 +451,44 @@ impl RegistryBuilder {
451451
///
452452
/// # Example
453453
/// ```
454-
/// // Publish package "a" depending on "b".
455-
/// Package::new("a", "1.0.0")
456-
/// .dep("b", "1.0.0")
457-
/// .file("src/lib.rs", r#"
458-
/// extern crate b;
459-
/// pub fn f() -> i32 { b::f() * 2 }
460-
/// "#)
461-
/// .publish();
454+
/// use cargo_test_support::registry::Package;
455+
/// use cargo_test_support::project;
462456
///
463-
/// // Publish package "b".
464-
/// Package::new("b", "1.0.0")
465-
/// .file("src/lib.rs", r#"
466-
/// pub fn f() -> i32 { 12 }
467-
/// "#)
468-
/// .publish();
457+
/// fn crate_package_test() {
458+
/// // Publish package "a" depending on "b".
459+
/// Package::new("a", "1.0.0")
460+
/// .dep("b", "1.0.0")
461+
/// .file("src/lib.rs", r#"
462+
/// extern crate b;
463+
/// pub fn f() -> i32 { b::f() * 2 }
464+
/// "#)
465+
/// .publish();
469466
///
470-
/// // Create a project that uses package "a".
471-
/// let p = project()
472-
/// .file("Cargo.toml", r#"
473-
/// [package]
474-
/// name = "foo"
475-
/// version = "0.0.1"
467+
/// // Publish package "b".
468+
/// Package::new("b", "1.0.0")
469+
/// .file("src/lib.rs", r#"
470+
/// pub fn f() -> i32 { 12 }
471+
/// "#)
472+
/// .publish();
476473
///
477-
/// [dependencies]
478-
/// a = "1.0"
479-
/// "#)
480-
/// .file("src/main.rs", r#"
481-
/// extern crate a;
482-
/// fn main() { println!("{}", a::f()); }
483-
/// "#)
484-
/// .build();
474+
/// // Create a project that uses package "a".
475+
/// let p = project()
476+
/// .file("Cargo.toml", r#"
477+
/// [package]
478+
/// name = "foo"
479+
/// version = "0.0.1"
485480
///
486-
/// p.cargo("run").with_stdout("24").run();
481+
/// [dependencies]
482+
/// a = "1.0"
483+
/// "#)
484+
/// .file("src/main.rs", r#"
485+
/// extern crate a;
486+
/// fn main() { println!("{}", a::f()); }
487+
/// "#)
488+
/// .build();
489+
///
490+
/// p.cargo("run").with_stdout("24").run();
491+
/// }
487492
/// ```
488493
#[must_use]
489494
pub struct Package {
@@ -1240,7 +1245,7 @@ impl Package {
12401245
}
12411246

12421247
/// Adds a normal dependency. Example:
1243-
/// ```
1248+
/// ```toml
12441249
/// [dependencies]
12451250
/// foo = {version = "1.0"}
12461251
/// ```
@@ -1249,7 +1254,7 @@ impl Package {
12491254
}
12501255

12511256
/// Adds a dependency with the given feature. Example:
1252-
/// ```
1257+
/// ```toml
12531258
/// [dependencies]
12541259
/// foo = {version = "1.0", "features": ["feat1", "feat2"]}
12551260
/// ```
@@ -1272,7 +1277,7 @@ impl Package {
12721277
}
12731278

12741279
/// Adds a dev-dependency. Example:
1275-
/// ```
1280+
/// ```toml
12761281
/// [dev-dependencies]
12771282
/// foo = {version = "1.0"}
12781283
/// ```
@@ -1281,7 +1286,7 @@ impl Package {
12811286
}
12821287

12831288
/// Adds a build-dependency. Example:
1284-
/// ```
1289+
/// ```toml
12851290
/// [build-dependencies]
12861291
/// foo = {version = "1.0"}
12871292
/// ```

0 commit comments

Comments
 (0)