Skip to content

Commit e785672

Browse files
Adjust fixture docs a bit
1 parent b5f3815 commit e785672

File tree

3 files changed

+63
-61
lines changed

3 files changed

+63
-61
lines changed

crates/base_db/src/fixture.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,4 @@
1-
//! Fixtures are strings containing rust source code with optional metadata.
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-
//! ```
1+
//! A set of high-level utility fixture methods to use in tests.
602
use std::{mem, str::FromStr, sync::Arc};
613

624
use cfg::CfgOptions;

crates/test_utils/src/fixture.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
//! Defines `Fixture` -- a convenient way to describe the initial state of
22
//! 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+
//! ```
363
464
use rustc_hash::FxHashMap;
565
use stdx::{lines_with_ends, split_once, trim_indent};
@@ -24,7 +84,7 @@ impl Fixture {
2484
/// //- some meta
2585
/// line 1
2686
/// line 2
27-
/// // - other meta
87+
/// //- other meta
2888
/// ```
2989
pub fn parse(ra_fixture: &str) -> Vec<Fixture> {
3090
let fixture = trim_indent(ra_fixture);

docs/dev/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn spam() {
390390
```
391391

392392
To specify input data, we use a single string literal in a special format, which can describe a set of rust files.
393-
See the `Fixture` type.
393+
See the `Fixture` its module for fixture examples and documentation.
394394

395395
**Architecture Invariant:** all code invariants are tested by `#[test]` tests.
396396
There's no additional checks in CI, formatting and tidy tests are run with `cargo test`.

0 commit comments

Comments
 (0)