You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #14272 - epage:test-docs, r=weihanglo
docs(test): Expand documentation of cargo-test-support
### What does this PR try to resolve?
In wanting to document #14039, I felt it would be good to put that documentation in `cargo-test-support`. To do so, I wanted a baseline of existing documentation for it to build on top of.
I was tempted to move more of "Writing tests" contrib documentation here, as its more about using `cargo-test-support` but I decided to hold off for now as most of that was long-form documentation and this is mostly focused on reference documentation.
### How should we test and review this PR?
### Additional information
Copy file name to clipboardExpand all lines: crates/cargo-test-macro/src/lib.rs
+43
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,49 @@ use std::path::Path;
14
14
use std::process::Command;
15
15
use std::sync::Once;
16
16
17
+
/// Replacement for `#[test]`
18
+
///
19
+
/// The `#[cargo_test]` attribute extends `#[test]` with some setup before starting the test.
20
+
/// It will create a filesystem "sandbox" under the "cargo integration test" directory for each test, such as `/path/to/cargo/target/tmp/cit/t123/`.
21
+
/// The sandbox will contain a `home` directory that will be used instead of your normal home directory.
22
+
///
23
+
/// The `#[cargo_test]` attribute takes several options that will affect how the test is generated.
24
+
/// They are listed in parentheses separated with commas, such as:
25
+
///
26
+
/// ```rust,ignore
27
+
/// #[cargo_test(nightly, reason = "-Zfoo is unstable")]
28
+
/// ```
29
+
///
30
+
/// The options it supports are:
31
+
///
32
+
/// * `>=1.64` --- This indicates that the test will only run with the given version of `rustc` or newer.
33
+
/// This can be used when a new `rustc` feature has been stabilized that the test depends on.
34
+
/// If this is specified, a `reason` is required to explain why it is being checked.
35
+
/// * `nightly` --- This will cause the test to be ignored if not running on the nightly toolchain.
36
+
/// This is useful for tests that use unstable options in `rustc` or `rustdoc`.
37
+
/// These tests are run in Cargo's CI, but are disabled in rust-lang/rust's CI due to the difficulty of updating both repos simultaneously.
38
+
/// A `reason` field is required to explain why it is nightly-only.
39
+
/// * `requires_<cmd>` --- This indicates a command that is required to be installed to be run.
40
+
/// For example, `requires_rustfmt` means the test will only run if the executable `rustfmt` is installed.
41
+
/// These tests are *always* run on CI.
42
+
/// This is mainly used to avoid requiring contributors from having every dependency installed.
43
+
/// * `build_std_real` --- This is a "real" `-Zbuild-std` test (in the `build_std` integration test).
44
+
/// This only runs on nightly, and only if the environment variable `CARGO_RUN_BUILD_STD_TESTS` is set (these tests on run on Linux).
45
+
/// * `build_std_mock` --- This is a "mock" `-Zbuild-std` test (which uses a mock standard library).
46
+
/// This only runs on nightly, and is disabled for windows-gnu.
47
+
/// * `public_network_test` --- This tests contacts the public internet.
48
+
/// These tests are disabled unless the `CARGO_PUBLIC_NETWORK_TESTS` environment variable is set.
49
+
/// Use of this should be *extremely rare*, please avoid using it if possible.
50
+
/// The hosts it contacts should have a relatively high confidence that they are reliable and stable (such as github.com), especially in CI.
51
+
/// The tests should be carefully considered for developer security and privacy as well.
52
+
/// * `container_test` --- This indicates that it is a test that uses Docker.
53
+
/// These tests are disabled unless the `CARGO_CONTAINER_TESTS` environment variable is set.
54
+
/// This requires that you have Docker installed.
55
+
/// The SSH tests also assume that you have OpenSSH installed.
56
+
/// These should work on Linux, macOS, and Windows where possible.
57
+
/// Unfortunately these tests are not run in CI for macOS or Windows (no Docker on macOS, and Windows does not support Linux images).
58
+
/// See [`cargo-test-support::containers`](https://doc.rust-lang.org/nightly/nightly-rustc/cargo_test_support/containers) for more on writing these tests.
59
+
/// * `ignore_windows="reason"` --- Indicates that the test should be ignored on windows for the given reason.
0 commit comments