Skip to content

Commit fc6b3cc

Browse files
committed
doc: execution model of doctest
NOTE: This is an undocumented implementation details.
1 parent af0fbf4 commit fc6b3cc

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

src/doc/man/cargo-test.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,21 @@ The libtest harness may be disabled by setting `harness = false` in the target
4040
manifest settings, in which case your code will need to provide its own `main`
4141
function to handle running tests.
4242

43+
### Documentation tests
44+
4345
Documentation tests are also run by default, which is handled by `rustdoc`. It
4446
extracts code samples from documentation comments of the library target, and
45-
then executes them. See the [rustdoc book](https://doc.rust-lang.org/rustdoc/)
46-
for more information on writing doc tests.
47+
then executes them.
48+
49+
Different from normal test targets, each code block compiles to a doctest
50+
executable on the fly with `rustc`. These executables runs in parallel in
51+
separate processes. The compilation of a code block is in fact a part of test
52+
function controlled by libtest, so some options such as `--jobs` might not
53+
take effect. Note that this execution model of doctests is an undocumented
54+
implementation details, beware of depending on it.
55+
56+
See the [rustdoc book](https://doc.rust-lang.org/rustdoc/) for more information
57+
on writing doc tests.
4758

4859
## OPTIONS
4960

src/doc/man/generated_txt/cargo-test.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@ DESCRIPTION
3636
target manifest settings, in which case your code will need to provide
3737
its own main function to handle running tests.
3838

39+
Documentation tests
3940
Documentation tests are also run by default, which is handled by
4041
rustdoc. It extracts code samples from documentation comments of the
41-
library target, and then executes them. See the rustdoc book
42-
<https://doc.rust-lang.org/rustdoc/> for more information on writing doc
43-
tests.
42+
library target, and then executes them.
43+
44+
Different from normal test targets, each code block compiles to a
45+
doctest executable on the fly with rustc. These executables runs in
46+
parallel in separate processes. The compilation of a code block is in
47+
fact a part of test function controlled by libtest, so some options such
48+
as --jobs might not take effect. Note that this execution model of
49+
doctests is an undocumented implementation details, beware of depending
50+
on it.
51+
52+
See the rustdoc book <https://doc.rust-lang.org/rustdoc/> for more
53+
information on writing doc tests.
4454

4555
OPTIONS
4656
Test Options

src/doc/src/commands/cargo-test.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,21 @@ The libtest harness may be disabled by setting `harness = false` in the target
4040
manifest settings, in which case your code will need to provide its own `main`
4141
function to handle running tests.
4242

43+
### Documentation tests
44+
4345
Documentation tests are also run by default, which is handled by `rustdoc`. It
4446
extracts code samples from documentation comments of the library target, and
45-
then executes them. See the [rustdoc book](https://doc.rust-lang.org/rustdoc/)
46-
for more information on writing doc tests.
47+
then executes them.
48+
49+
Different from normal test targets, each code block compiles to a doctest
50+
executable on the fly with `rustc`. These executables runs in parallel in
51+
separate processes. The compilation of a code block is in fact a part of test
52+
function controlled by libtest, so some options such as `--jobs` might not
53+
take effect. Note that this execution model of doctests is an undocumented
54+
implementation details, beware of depending on it.
55+
56+
See the [rustdoc book](https://doc.rust-lang.org/rustdoc/) for more information
57+
on writing doc tests.
4758

4859
## OPTIONS
4960

src/doc/src/reference/cargo-targets.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ parallel, reporting the success and failure of each test. See [the `harness`
100100
field](#the-harness-field) if you want to use a different harness or test
101101
strategy.
102102

103+
> There is another style of test in Cargo: [documentation tests][documentation examples].
104+
> They are handled by `rustdoc` and have a slightly different execution model.
105+
> For more information, please see [`cargo test`][cargo-test-documentation-tests].
106+
103107
[libtest harness]: ../../rustc/tests/index.html
108+
[cargo-test-documentation-tests]: ../commands/cargo-test.md#documentation-tests
104109

105110
#### Integration tests
106111

src/etc/man/cargo-test.1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ special executable as aforementioned, and then is run serially.
3939
The libtest harness may be disabled by setting \fBharness = false\fR in the target
4040
manifest settings, in which case your code will need to provide its own \fBmain\fR
4141
function to handle running tests.
42-
.sp
42+
.SS "Documentation tests"
4343
Documentation tests are also run by default, which is handled by \fBrustdoc\fR\&. It
4444
extracts code samples from documentation comments of the library target, and
45-
then executes them. See the \fIrustdoc book\fR <https://doc.rust\-lang.org/rustdoc/>
46-
for more information on writing doc tests.
45+
then executes them.
46+
.sp
47+
Different from normal test targets, each code block compiles to a doctest
48+
executable on the fly with \fBrustc\fR\&. These executables runs in parallel in
49+
separate processes. The compilation of a code block is in fact a part of test
50+
function controlled by libtest, so some options such as \fB\-\-jobs\fR might not
51+
take effect. Note that this execution model of doctests is an undocumented
52+
implementation details, beware of depending on it.
53+
.sp
54+
See the \fIrustdoc book\fR <https://doc.rust\-lang.org/rustdoc/> for more information
55+
on writing doc tests.
4756
.SH "OPTIONS"
4857
.SS "Test Options"
4958
.sp

0 commit comments

Comments
 (0)