Skip to content

Commit b5c4f2f

Browse files
committed
Update parser tests with env var
1 parent d739731 commit b5c4f2f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ SOURCE_FILE@0..48
5656
R_CURLY@46..47 "}"
5757
WHITESPACE@47..48 "\n"
5858
error 24..24: attributes are not allowed on BIN_EXPR
59-
error 44..44: attributes are not allowed on IF_EXPR

crates/test_utils/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
pub mod mark;
1111

1212
use std::{
13-
fs,
13+
env, fs,
1414
path::{Path, PathBuf},
1515
};
1616

17-
pub use ra_cfg::CfgOptions;
17+
use serde_json::Value;
1818
use stdx::split1;
19+
use text_size::{TextRange, TextSize};
1920

21+
pub use ra_cfg::CfgOptions;
2022
pub use relative_path::{RelativePath, RelativePathBuf};
2123
pub use rustc_hash::FxHashMap;
22-
use serde_json::Value;
23-
use text_size::{TextRange, TextSize};
2424

2525
pub use difference::Changeset as __Changeset;
2626

@@ -625,8 +625,6 @@ pub fn skip_slow_tests() -> bool {
625625
should_skip
626626
}
627627

628-
const REWRITE: bool = false;
629-
630628
/// Asserts that `expected` and `actual` strings are equal. If they differ only
631629
/// in trailing or leading whitespace the test won't fail and
632630
/// the contents of `actual` will be written to the file located at `path`.
@@ -642,7 +640,7 @@ fn assert_equal_text(expected: &str, actual: &str, path: &Path) {
642640
fs::write(path, actual).unwrap();
643641
return;
644642
}
645-
if REWRITE {
643+
if env::var("UPDATE_EXPECTATIONS").is_ok() {
646644
println!("rewriting {}", pretty_path.display());
647645
fs::write(path, actual).unwrap();
648646
return;

docs/dev/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ There are two kinds of tests:
342342
The purpose of inline tests is not to achieve full coverage by test cases, but to explain to the reader of the code what each particular `if` and `match` is responsible for.
343343
If you are tempted to add a large inline test, it might be a good idea to leave only the simplest example in place, and move the test to a manual `parser/ok` test.
344344

345+
To update test data, run with `UPDATE_EXPECTATIONS` variable:
346+
347+
```bash
348+
env UPDATE_EXPECTATIONS=1 cargo qt
349+
```
350+
345351
# Logging
346352

347353
Logging is done by both rust-analyzer and VS Code, so it might be tricky to

0 commit comments

Comments
 (0)