diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-06 23:23:41 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-06 23:23:41 +0100 |
commit | a35f7cb6355f00a71a24338eb2d3bfc2920eccb4 (patch) | |
tree | 49ed63e6169ecbc4b07e6ddfbac3465641294143 /crates | |
parent | fcb22a674df4728742a865dda76ce65f0f9205b1 (diff) | |
parent | e785672f15a6da1314585ebcf2c235911a9be4f8 (diff) |
Merge #8382
8382: Make Fixture docs more accessible and fix small doc issues r=SomeoneToIgnore a=SomeoneToIgnore
Follow up of https://github.com/rust-analyzer/rust-analyzer/pull/8302#discussion_r607054896
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/base_db/src/fixture.rs | 60 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 62 |
2 files changed, 62 insertions, 60 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 8d4641355..04e2be390 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -1,62 +1,4 @@ | |||
1 | //! Fixtures are strings containing rust source code with optional metadata. | 1 | //! A set of high-level utility fixture methods to use in tests. |
2 | //! A fixture without metadata is parsed into a single source file. | ||
3 | //! Use this to test functionality local to one file. | ||
4 | //! | ||
5 | //! Simple Example: | ||
6 | //! ``` | ||
7 | //! r#" | ||
8 | //! fn main() { | ||
9 | //! println!("Hello World") | ||
10 | //! } | ||
11 | //! "# | ||
12 | //! ``` | ||
13 | //! | ||
14 | //! Metadata can be added to a fixture after a `//-` comment. | ||
15 | //! The basic form is specifying filenames, | ||
16 | //! which is also how to define multiple files in a single test fixture | ||
17 | //! | ||
18 | //! Example using two files in the same crate: | ||
19 | //! ``` | ||
20 | //! " | ||
21 | //! //- /main.rs | ||
22 | //! mod foo; | ||
23 | //! fn main() { | ||
24 | //! foo::bar(); | ||
25 | //! } | ||
26 | //! | ||
27 | //! //- /foo.rs | ||
28 | //! pub fn bar() {} | ||
29 | //! " | ||
30 | //! ``` | ||
31 | //! | ||
32 | //! Example using two crates with one file each, with one crate depending on the other: | ||
33 | //! ``` | ||
34 | //! r#" | ||
35 | //! //- /main.rs crate:a deps:b | ||
36 | //! fn main() { | ||
37 | //! b::foo(); | ||
38 | //! } | ||
39 | //! //- /lib.rs crate:b | ||
40 | //! pub fn b() { | ||
41 | //! println!("Hello World") | ||
42 | //! } | ||
43 | //! "# | ||
44 | //! ``` | ||
45 | //! | ||
46 | //! Metadata allows specifying all settings and variables | ||
47 | //! that are available in a real rust project: | ||
48 | //! - crate names via `crate:cratename` | ||
49 | //! - dependencies via `deps:dep1,dep2` | ||
50 | //! - configuration settings via `cfg:dbg=false,opt_level=2` | ||
51 | //! - environment variables via `env:PATH=/bin,RUST_LOG=debug` | ||
52 | //! | ||
53 | //! Example using all available metadata: | ||
54 | //! ``` | ||
55 | //! " | ||
56 | //! //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | ||
57 | //! fn insert_source_code_here() {} | ||
58 | //! " | ||
59 | //! ``` | ||
60 | use std::{mem, str::FromStr, sync::Arc}; | 2 | use std::{mem, str::FromStr, sync::Arc}; |
61 | 3 | ||
62 | use cfg::CfgOptions; | 4 | use cfg::CfgOptions; |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 6bc824e94..099baeca2 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -1,5 +1,65 @@ | |||
1 | //! Defines `Fixture` -- a convenient way to describe the initial state of | 1 | //! Defines `Fixture` -- a convenient way to describe the initial state of |
2 | //! rust-analyzer database from a single string. | 2 | //! rust-analyzer database from a single string. |
3 | //! | ||
4 | //! Fixtures are strings containing rust source code with optional metadata. | ||
5 | //! A fixture without metadata is parsed into a single source file. | ||
6 | //! Use this to test functionality local to one file. | ||
7 | //! | ||
8 | //! Simple Example: | ||
9 | //! ``` | ||
10 | //! r#" | ||
11 | //! fn main() { | ||
12 | //! println!("Hello World") | ||
13 | //! } | ||
14 | //! "# | ||
15 | //! ``` | ||
16 | //! | ||
17 | //! Metadata can be added to a fixture after a `//-` comment. | ||
18 | //! The basic form is specifying filenames, | ||
19 | //! which is also how to define multiple files in a single test fixture | ||
20 | //! | ||
21 | //! Example using two files in the same crate: | ||
22 | //! ``` | ||
23 | //! " | ||
24 | //! //- /main.rs | ||
25 | //! mod foo; | ||
26 | //! fn main() { | ||
27 | //! foo::bar(); | ||
28 | //! } | ||
29 | //! | ||
30 | //! //- /foo.rs | ||
31 | //! pub fn bar() {} | ||
32 | //! " | ||
33 | //! ``` | ||
34 | //! | ||
35 | //! Example using two crates with one file each, with one crate depending on the other: | ||
36 | //! ``` | ||
37 | //! r#" | ||
38 | //! //- /main.rs crate:a deps:b | ||
39 | //! fn main() { | ||
40 | //! b::foo(); | ||
41 | //! } | ||
42 | //! //- /lib.rs crate:b | ||
43 | //! pub fn b() { | ||
44 | //! println!("Hello World") | ||
45 | //! } | ||
46 | //! "# | ||
47 | //! ``` | ||
48 | //! | ||
49 | //! Metadata allows specifying all settings and variables | ||
50 | //! that are available in a real rust project: | ||
51 | //! - crate names via `crate:cratename` | ||
52 | //! - dependencies via `deps:dep1,dep2` | ||
53 | //! - configuration settings via `cfg:dbg=false,opt_level=2` | ||
54 | //! - environment variables via `env:PATH=/bin,RUST_LOG=debug` | ||
55 | //! | ||
56 | //! Example using all available metadata: | ||
57 | //! ``` | ||
58 | //! " | ||
59 | //! //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | ||
60 | //! fn insert_source_code_here() {} | ||
61 | //! " | ||
62 | //! ``` | ||
3 | 63 | ||
4 | use rustc_hash::FxHashMap; | 64 | use rustc_hash::FxHashMap; |
5 | use stdx::{lines_with_ends, split_once, trim_indent}; | 65 | use stdx::{lines_with_ends, split_once, trim_indent}; |
@@ -24,7 +84,7 @@ impl Fixture { | |||
24 | /// //- some meta | 84 | /// //- some meta |
25 | /// line 1 | 85 | /// line 1 |
26 | /// line 2 | 86 | /// line 2 |
27 | /// // - other meta | 87 | /// //- other meta |
28 | /// ``` | 88 | /// ``` |
29 | pub fn parse(ra_fixture: &str) -> Vec<Fixture> { | 89 | pub fn parse(ra_fixture: &str) -> Vec<Fixture> { |
30 | let fixture = trim_indent(ra_fixture); | 90 | let fixture = trim_indent(ra_fixture); |