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
Copy file name to clipboardExpand all lines: guide/src/cli/test.md
+16-18Lines changed: 16 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,7 @@ of code samples that could get outdated as the language evolves. Therefore it is
8
8
them to be able to automatically test these code examples.
9
9
10
10
mdBook supports a `test` command that will run code samples as doc tests for your book. At
11
-
the moment, only Rust doc tests are supported.
12
-
13
-
For details on writing code samples and runnable code samples in your book, see [Writing](../guide/writing.md).
11
+
the moment, only Rust doc tests are supported.
14
12
15
13
#### Specify a directory
16
14
@@ -21,10 +19,22 @@ instead of the current working directory.
21
19
mdbook test path/to/book
22
20
```
23
21
24
-
#### `--library-path`
22
+
#### `--dest-dir`
23
+
24
+
The `--dest-dir` (`-d`) option allows you to change the output directory for the
25
+
book. Relative paths are interpreted relative to the book's root directory. If
26
+
not specified it will default to the value of the `build.build-dir` key in
27
+
`book.toml`, or to `./book`.
28
+
29
+
#### `--chapter`
30
+
31
+
The `--chapter` (`-c`) option allows you to test a specific chapter of the
32
+
book using the chapter name or the relative path to the chapter.
33
+
34
+
#### `--library-path``[`deprecated`]`
25
35
26
-
> Note: This argument doesn't provide sufficient information for current Rust compilers.
27
-
Instead, add `package-dir` to your ***book.toml***, as described in [configuration](/format/configuration/general.md#rust-options).
36
+
> Note: This argument doesn't provide sufficient extern crate information to run doc tests in current Rust compilers.
37
+
Instead, add **manifest** to point to a **Cargo.toml** file in your ***book.toml***, as described in [rust configuration](/format/configuration/general.html#rust-options).
28
38
29
39
30
40
The `--library-path` (`-L`) option allows you to add directories to the library
@@ -41,15 +51,3 @@ mdbook test my-book -L target/debug/deps/
41
51
42
52
See the `rustdoc` command-line [documentation](https://doc.rust-lang.org/rustdoc/command-line-arguments.html#-l--library-path-where-to-look-for-dependencies)
43
53
for more information.
44
-
45
-
#### `--dest-dir`
46
-
47
-
The `--dest-dir` (`-d`) option allows you to change the output directory for the
48
-
book. Relative paths are interpreted relative to the book's root directory. If
49
-
not specified it will default to the value of the `build.build-dir` key in
50
-
`book.toml`, or to `./book`.
51
-
52
-
#### `--chapter`
53
-
54
-
The `--chapter` (`-c`) option allows you to test a specific chapter of the
55
-
book using the chapter name or the relative path to the chapter.
Copy file name to clipboardExpand all lines: guide/src/format/configuration/general.md
+22-31Lines changed: 22 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ authors = ["John Doe"]
11
11
description = "The example book covers examples."
12
12
13
13
[rust]
14
-
edition = "2018"
14
+
manifest = "./Cargo.toml"
15
15
16
16
[build]
17
17
build-dir = "my-example-book"
@@ -30,14 +30,24 @@ limit-results = 15
30
30
31
31
## Supported configuration options
32
32
33
-
It is important to note that**any** relative path specified in the
33
+
> Note:**any** relative path specified in the
34
34
configuration will always be taken relative from the root of the book where the
35
35
configuration file is located.
36
36
37
37
### General metadata
38
38
39
39
This is general information about your book.
40
40
41
+
```toml
42
+
[book]
43
+
title = "Example book"
44
+
authors = ["John Doe", "Jane Doe"]
45
+
description = "The example book covers examples."
46
+
src = "my-src"# source files in `root/my-src` instead of `root/src`
47
+
language = "en"
48
+
text-direction = "ltr"
49
+
```
50
+
41
51
-**title:** The title of the book
42
52
-**authors:** The author(s) of the book
43
53
-**description:** A description for the book, which is added as meta
@@ -50,44 +60,25 @@ This is general information about your book.
50
60
-**text-direction**: The direction of text in the book: Left-to-right (LTR) or Right-to-left (RTL). Possible values: `ltr`, `rtl`.
51
61
When not specified, the text direction is derived from the book's `language` attribute.
52
62
53
-
**book.toml**
54
-
```toml
55
-
[book]
56
-
title = "Example book"
57
-
authors = ["John Doe", "Jane Doe"]
58
-
description = "The example book covers examples."
59
-
src = "my-src"# the source files will be found in `root/my-src` instead of `root/src`
60
-
language = "en"
61
-
text-direction = "ltr"
62
-
```
63
-
64
63
### Rust options
65
64
66
65
Options for the Rust language, relevant to running tests and playground
67
66
integration.
68
67
69
68
```toml
70
69
[rust]
71
-
package-dir = "folder/for/Cargo.toml"
72
-
edition = "2015"# the default edition for code blocks
70
+
manifest = "path/for/Cargo.toml"
71
+
edition = "2015"#[deprecated] the default edition for code blocks
73
72
```
74
73
75
-
-**package-dir**: Folder containing a Cargo package whose targets and dependencies
76
-
you want to use in your book's code samples.
77
-
It must be specified if you want to test code samples with `use` statements, even if
78
-
there is a `Cargo.toml` in the folder containing the `book.toml`.
79
-
This can be a relative path, relative to the folder containing `book.toml`.
80
-
81
-
-**edition**: Rust edition to use by default for the code snippets. Default
82
-
is `"2015"`. Individual code blocks can be controlled with the `edition2015`,
83
-
`edition2018` or `edition2021` annotations, such as:
84
-
85
-
~~~text
86
-
```rust,edition2015
87
-
// This only works in 2015.
88
-
let try = true;
89
-
```
90
-
~~~
74
+
-**manifest**: Path to a ***Cargo.toml*** file which is used to resolve dependencies of your sample code. mdBook also uses the `package.edition` configured in the cargo project as the default for code snippets in your book.
75
+
See [Using External Crates and Dependencies](/format/mdbook.html#using-external-crates-and-dependencies) for details.
76
+
77
+
-**edition**`[`deprecated`]`: Rust edition to use by default for the code snippets.
78
+
Default is `"2015"`. Individual code blocks can be controlled with the `edition2015`,
79
+
`edition2018` or `edition2021` annotations, as described in [Rust code block attributes](/format/mdbook.html#rust-code-block-attributes).
80
+
This option is deprecated because it's only useful if your code samples don't depend on external crates or you're not doctest'ing them. In any case, this option cannot be specified if **manifest** is configured.
Copy file name to clipboardExpand all lines: guide/src/format/mdbook.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# mdBook-specific features
2
2
3
+
# Features for code blocks
4
+
5
+
These capabilities primarily affect how the user sees or interacts with code samples in your book and are supported directly by mdBook. Some also affect documentation tests (for which mdBook invokes `rustdoc --test`): this is detailed in the sections below.
6
+
3
7
## Hiding code lines
4
8
5
9
There is a feature in mdBook that lets you hide code lines by prepending them with a specific prefix.
@@ -306,6 +310,21 @@ And the `editable` attribute will enable the [editor] as described at [Rust code
306
310
307
311
[Rust Playground]: https://play.rust-lang.org/
308
312
313
+
## Using external crates and dependencies
314
+
315
+
If your code samples depend on external crates, you will probably want to include `use <crate>` statements in the code and want them to resolve and allow documentation tests to run.
316
+
To configure this:
317
+
318
+
1. Create a ***Cargo.toml*** file with a `[package.dependencies]` section that defines a dependency for each `<crate>` you want to use in any sample. If your book is already embedded in an existing Cargo project, you may be able to use the existing project `Cargo.toml`.
319
+
2. In your ***book.toml***:
320
+
* configure the path to ***Cargo.toml** in `rust.manifest`, as described in [rust configuration](/format/configuration/general.html#rust-options).
321
+
* remove `rust.edition` if it is configured. The edition of rust compiler will be as specified in the ***Cargo.toml***.
322
+
* Refrain from invoking `mdbook test` with `-L` or `--library-path` argument. This, too, will be inferred from cargo project configuration
323
+
324
+
# Features for general content
325
+
326
+
These can be used in markdown text (outside code blocks).
327
+
309
328
## Controlling page \<title\>
310
329
311
330
A chapter can set a \<title\> that is different from its entry in the table of
0 commit comments