Skip to content

Commit be33892

Browse files
committed
Auto merge of #12032 - ehuss:clarify-test-option, r=weihanglo
Clarify documentation around test target setting. There was some confusion about the wording in this section regarding what happens with an example's `main` function. This tries to be more explicit to clarify what happens when an example is marked as a test. This also adds a few other clarifications and a link to the reference documentation. Closes #11528
2 parents 1cd4ef3 + 03a5d8f commit be33892

File tree

8 files changed

+78
-23
lines changed

8 files changed

+78
-23
lines changed

src/doc/man/cargo-bench.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ following targets of the selected packages:
8686

8787
The default behavior can be changed by setting the `bench` flag for the target
8888
in the manifest settings. Setting examples to `bench = true` will build and
89-
run the example as a benchmark. Setting targets to `bench = false` will stop
90-
them from being benchmarked by default. Target selection options that take a
91-
target by name ignore the `bench` flag and will always benchmark the given
89+
run the example as a benchmark, replacing the example's `main` function with
90+
the libtest harness.
91+
92+
Setting targets to `bench = false` will stop them from being bencharmked by
93+
default. Target selection options that take a target by name (such as
94+
`--example foo`) ignore the `bench` flag and will always benchmark the given
9295
target.
9396

97+
See [Configuring a target](../reference/cargo-targets.html#configuring-a-target)
98+
for more information on per-target settings.
99+
94100
{{> options-targets-bin-auto-built }}
95101

96102
{{> options-targets }}

src/doc/man/cargo-test.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,20 @@ following targets of the selected packages:
8989

9090
The default behavior can be changed by setting the `test` flag for the target
9191
in the manifest settings. Setting examples to `test = true` will build and run
92-
the example as a test. Setting targets to `test = false` will stop them from
93-
being tested by default. Target selection options that take a target by name
92+
the example as a test, replacing the example's `main` function with the
93+
libtest harness. If you don't want the `main` function replaced, also include
94+
`harness = false`, in which case the example will be built and executed as-is.
95+
96+
Setting targets to `test = false` will stop them from being tested by default.
97+
Target selection options that take a target by name (such as `--example foo`)
9498
ignore the `test` flag and will always test the given target.
9599

96100
Doc tests for libraries may be disabled by setting `doctest = false` for the
97101
library in the manifest.
98102

103+
See [Configuring a target](../reference/cargo-targets.html#configuring-a-target)
104+
for more information on per-target settings.
105+
99106
{{> options-targets-bin-auto-built }}
100107

101108
{{> options-targets }}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,17 @@ OPTIONS
120120

121121
The default behavior can be changed by setting the bench flag for the
122122
target in the manifest settings. Setting examples to bench = true will
123-
build and run the example as a benchmark. Setting targets to bench =
124-
false will stop them from being benchmarked by default. Target selection
125-
options that take a target by name ignore the bench flag and will always
126-
benchmark the given target.
123+
build and run the example as a benchmark, replacing the example’s main
124+
function with the libtest harness.
125+
126+
Setting targets to bench = false will stop them from being bencharmked
127+
by default. Target selection options that take a target by name (such as
128+
--example foo) ignore the bench flag and will always benchmark the given
129+
target.
130+
131+
See Configuring a target
132+
<https://doc.rust-lang.org/cargo/reference/cargo-targets.html#configuring-a-target>
133+
for more information on per-target settings.
127134

128135
Binary targets are automatically built if there is an integration test
129136
or benchmark being selected to benchmark. This allows an integration

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,23 @@ OPTIONS
128128

129129
The default behavior can be changed by setting the test flag for the
130130
target in the manifest settings. Setting examples to test = true will
131-
build and run the example as a test. Setting targets to test = false
132-
will stop them from being tested by default. Target selection options
133-
that take a target by name ignore the test flag and will always test the
134-
given target.
131+
build and run the example as a test, replacing the example’s main
132+
function with the libtest harness. If you don’t want the main function
133+
replaced, also include harness = false, in which case the example will
134+
be built and executed as-is.
135+
136+
Setting targets to test = false will stop them from being tested by
137+
default. Target selection options that take a target by name (such as
138+
--example foo) ignore the test flag and will always test the given
139+
target.
135140

136141
Doc tests for libraries may be disabled by setting doctest = false for
137142
the library in the manifest.
138143

144+
See Configuring a target
145+
<https://doc.rust-lang.org/cargo/reference/cargo-targets.html#configuring-a-target>
146+
for more information on per-target settings.
147+
139148
Binary targets are automatically built if there is an integration test
140149
or benchmark being selected to test. This allows an integration test to
141150
execute the binary to exercise and test its behavior. The

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,17 @@ following targets of the selected packages:
143143

144144
The default behavior can be changed by setting the `bench` flag for the target
145145
in the manifest settings. Setting examples to `bench = true` will build and
146-
run the example as a benchmark. Setting targets to `bench = false` will stop
147-
them from being benchmarked by default. Target selection options that take a
148-
target by name ignore the `bench` flag and will always benchmark the given
146+
run the example as a benchmark, replacing the example's `main` function with
147+
the libtest harness.
148+
149+
Setting targets to `bench = false` will stop them from being bencharmked by
150+
default. Target selection options that take a target by name (such as
151+
`--example foo`) ignore the `bench` flag and will always benchmark the given
149152
target.
150153

154+
See [Configuring a target](../reference/cargo-targets.html#configuring-a-target)
155+
for more information on per-target settings.
156+
151157
Binary targets are automatically built if there is an integration test or
152158
benchmark being selected to benchmark. This allows an integration
153159
test to execute the binary to exercise and test its behavior.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,20 @@ following targets of the selected packages:
146146

147147
The default behavior can be changed by setting the `test` flag for the target
148148
in the manifest settings. Setting examples to `test = true` will build and run
149-
the example as a test. Setting targets to `test = false` will stop them from
150-
being tested by default. Target selection options that take a target by name
149+
the example as a test, replacing the example's `main` function with the
150+
libtest harness. If you don't want the `main` function replaced, also include
151+
`harness = false`, in which case the example will be built and executed as-is.
152+
153+
Setting targets to `test = false` will stop them from being tested by default.
154+
Target selection options that take a target by name (such as `--example foo`)
151155
ignore the `test` flag and will always test the given target.
152156

153157
Doc tests for libraries may be disabled by setting `doctest = false` for the
154158
library in the manifest.
155159

160+
See [Configuring a target](../reference/cargo-targets.html#configuring-a-target)
161+
for more information on per-target settings.
162+
156163
Binary targets are automatically built if there is an integration test or
157164
benchmark being selected to test. This allows an integration
158165
test to execute the binary to exercise and test its behavior.

src/etc/man/cargo-bench.1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ available)
145145
.sp
146146
The default behavior can be changed by setting the \fBbench\fR flag for the target
147147
in the manifest settings. Setting examples to \fBbench = true\fR will build and
148-
run the example as a benchmark. Setting targets to \fBbench = false\fR will stop
149-
them from being benchmarked by default. Target selection options that take a
150-
target by name ignore the \fBbench\fR flag and will always benchmark the given
148+
run the example as a benchmark, replacing the example\[cq]s \fBmain\fR function with
149+
the libtest harness.
150+
.sp
151+
Setting targets to \fBbench = false\fR will stop them from being bencharmked by
152+
default. Target selection options that take a target by name (such as
153+
\fB\-\-example foo\fR) ignore the \fBbench\fR flag and will always benchmark the given
151154
target.
152155
.sp
156+
See \fIConfiguring a target\fR <https://doc.rust\-lang.org/cargo/reference/cargo\-targets.html#configuring\-a\-target>
157+
for more information on per\-target settings.
158+
.sp
153159
Binary targets are automatically built if there is an integration test or
154160
benchmark being selected to benchmark. This allows an integration
155161
test to execute the binary to exercise and test its behavior.

src/etc/man/cargo-test.1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,20 @@ available)
149149
.sp
150150
The default behavior can be changed by setting the \fBtest\fR flag for the target
151151
in the manifest settings. Setting examples to \fBtest = true\fR will build and run
152-
the example as a test. Setting targets to \fBtest = false\fR will stop them from
153-
being tested by default. Target selection options that take a target by name
152+
the example as a test, replacing the example\[cq]s \fBmain\fR function with the
153+
libtest harness. If you don\[cq]t want the \fBmain\fR function replaced, also include
154+
\fBharness = false\fR, in which case the example will be built and executed as\-is.
155+
.sp
156+
Setting targets to \fBtest = false\fR will stop them from being tested by default.
157+
Target selection options that take a target by name (such as \fB\-\-example foo\fR)
154158
ignore the \fBtest\fR flag and will always test the given target.
155159
.sp
156160
Doc tests for libraries may be disabled by setting \fBdoctest = false\fR for the
157161
library in the manifest.
158162
.sp
163+
See \fIConfiguring a target\fR <https://doc.rust\-lang.org/cargo/reference/cargo\-targets.html#configuring\-a\-target>
164+
for more information on per\-target settings.
165+
.sp
159166
Binary targets are automatically built if there is an integration test or
160167
benchmark being selected to test. This allows an integration
161168
test to execute the binary to exercise and test its behavior.

0 commit comments

Comments
 (0)