Commit Graph

88 Commits

Author SHA1 Message Date
Yacin Tmimi
f40b1d9f1a Backport: Do not touch module with #![rustfmt::skip] (4297)
Although the implementation is slightly different than the original PR,
the general idea is the same. After collecting all modules we want to
exclude formatting those that contain the #![rustfmt::skip] attribute.
2021-12-07 18:45:00 -06:00
Yacin Tmimi
a21f1b6c2a Conditionally compile tests based on CFG_RELEASE_CHANNEL env var
Adds the ``nightly_only_test`` and ``stable_only_test`` attribute macros
that prevent or allow certain tests to compile on nightly and stable
respectively. This is achieved through conditionally outputting the
tests TokenStream.

If CFG_RELEASE_CHANNEL is not set, it's assumed that we're running in a
nightly environment.

To mark a test as nightly only:

    #[nightly_only_test]
    #[test]
    fn only_run_on_nightly() {
        ...
    }

To mark a test a stable only:

    #[stable_only_test]
    #[test]
    fn only_run_on_stable() {
        ...
    }
2021-11-27 17:36:18 -06:00
Caleb Cartwright
a5f85058ac fix: handle external mods imported via external->inline load hierarchy 2021-11-04 18:35:38 -05:00
Matthias Krüger
c493ee4828 fix clippy::needless_borrow 2021-10-27 20:41:57 -05:00
Caleb Cartwright
c9c1932be3 feat: stabilize disable_all_formatting 2021-10-13 21:58:13 -05:00
Seiichi Uchida
d4ffd1efa4 Support @generated marker to skip code formatting
This is a copy of #4296 with these changes:
* file is not reopened again to find if the file is generated
* first five lines are scanned for `@generated` marker instead of one
* no attempt is made to only search for marker in comments

`@generated` marker is used by certain tools to understand that the
file is generated, so it should be treated differently than a file
written by a human:
* linters should not be invoked on these files,
* diffs in these files are less important,
* and these files should not be reformatted.

This PR proposes builtin support for `@generated` marker.

I have not found a standard for a generated file marker, but:
* Facebook [uses `@generated` marker](https://tinyurl.com/fb-generated)
* Phabricator tool which was spawned from Facebook internal tool
  [also understands `@generated` marker](https://git.io/JnVHa)
* Cargo inserts `@generated` marker into [generated Cargo.lock files](https://git.io/JnVHP)

My personal story is that rust-protobuf project which I maintain
was broken twice because of incompatibilities/bugs in rustfmt marker
handling: [one](https://github.com/stepancheg/rust-protobuf/issues/493),
[two](https://github.com/stepancheg/rust-protobuf/issues/551).
(Also, rust-protobuf started generating `@generated` marker
[6 years ago](https://git.io/JnV5h)).

While rustfmt AST markers are useful to apply to a certain AST
elements, disable whole-file-at-once all-tools-at-once text level
marker might be easier to use and more reliable for generated code.
2021-09-14 21:22:26 -05:00
Caleb Cartwright
2608f2c63b fix(rustfmt): load nested out-of-line mods correctly 2021-06-17 22:35:19 -05:00
Joshua Nelson
6170948820 Fix warnings
- Fix nightly warning about `format!`
- Remove unused functions and fields
2021-02-17 20:14:46 -06:00
Sean Klein
5e14f760c5 fix: Avoid incorrect global 'cfg_if' Symbol interning
Fixes #4656
2021-01-27 19:26:58 -06:00
Caleb Cartwright
98975e1a64 tests: adjust some cherry-picekd tests 2020-11-02 18:31:51 -06:00
Caleb Cartwright
86a41bc80b tests: add test for panic on new_parser_from_file 2020-11-02 18:31:51 -06:00
Caleb Cartwright
9faba4539b fix(parser): better unclosed delims handling 2020-11-02 18:31:51 -06:00
Caleb Cartwright
ce1a3efff0 fix: backport fix for submod parser errors 2020-06-11 21:49:40 -05:00
Caleb Cartwright
dead3a807d fix: backport mod resolution error handling 2020-06-11 21:11:18 -05:00
Caleb Cartwright
ba4bf03d84 don't fail on recoverable parser errors in ignored files (#3782) 2019-10-07 10:24:08 +09:00
Matthew Pomes
e28ae8b4a3 Init Logger for unit tests (#3829)
Add `init_log()` function which attempts to init logger, and
ignores failure. The function is called at the beginning of
every test, and will fail if the logger is already initialized.
The logger must be initialized in every test, becuase cargo runs
the tests in parallel, with no garentees about the order and time
each starts.
2019-10-04 11:24:33 +09:00
Caleb Cartwright
ad5d9fba9b fix formatting mods inside cfg_if macro (#3763) 2019-09-02 18:36:51 +09:00
Caleb Cartwright
dfd27663dc add json emit mode (#3735) 2019-08-16 11:14:53 +09:00
Michele d'Amico
76e2ba25bd #3665: Implemented (#3689) 2019-07-17 09:40:33 +09:00
Ruben Schmidmeister
37695b3c45 Extract configuration snippet tests into own module (#3667)
* Extract configuration snippet tests into own module

* Move helper function outside of test function
2019-07-14 10:22:18 +09:00
Caleb Cartwright
944fc57e10 tests: ensure min number of system/idempotent tests ran (#3629) 2019-06-16 23:47:22 +09:00
Seiichi Uchida
a4eab17d7c
Fix is_subpath 2019-06-14 19:16:17 +09:00
Ruben Schmidmeister
dbac28b4b4 Use trait to abstract emit modes (#3616) 2019-06-13 06:59:20 +09:00
Seiichi Uchida
47a11cd516
Format modules defined in cfg_attr (#3604) 2019-06-09 09:20:39 +09:00
Seiichi Uchida
e71bffb008
Format modules defined inside cfg_if macro calls (#3600) 2019-06-08 18:47:18 +09:00
Ruben Schmidmeister
8b57668c33
Move macro to separate module 2019-05-17 16:13:46 +02:00
Ruben Schmidmeister
4745cec7f3
Re-use nightly channel macro 2019-05-17 16:07:49 +02:00
Ruben Schmidmeister
fd22c27c47
Allow tests to be run on nightly only 2019-05-17 15:58:01 +02:00
David Alber
bfe5e9c108 Fix condition typo 2019-05-05 11:55:11 -07:00
topecongiro
f8d3aa5908 Add a path to the parent dir of rustfmt.toml as a prefix
Paths users specify in `ignore` configuraiton option is relative to the
directory which contains the rustfmt.toml file. When processing the ignore paths
internally, rustfmt should add a path to the directory as a  prefix since
RealPath passed from libsyntax is a full path.
2019-04-23 08:12:02 +09:00
Ruben Schmidmeister
3dc625c661 Use annotate-snippets for emitting errors (#3507) 2019-04-17 05:33:36 -07:00
rChaser53
34bf13718a Allow specifying glob pattern to ignore config option (#3488) 2019-04-14 03:30:44 -07:00
Matthias Krüger
4352681d62 fix clippy warnings
clippy::needless_return
clippy::redundant_closure
clippy::or_fun_call
clippy::len_zero
clippy::expect_fun_call
clippy::assertions_on_constants
clippy::identity_conversion
clippy::chars_last_cmp
2019-04-11 13:48:13 +02:00
Shotaro Yamada
9fda937779 Remove redundant & 2019-03-29 19:17:50 +09:00
topecongiro
968d30f5d8 Run tests in a thread with larger stack size 2019-03-26 23:35:07 +09:00
rchaser53
bbbc1e86eb refrect topecongiro reviews
- &Vec<syntax::ast::PathSegment> => &[ast::PathSegment]
    - remove unnecessary implements
    - transfer skip logic to inside rewrite_macro
    - fix test
    - use util methods in libsyntax
    - use meta_item_list directly
    - avoid no_entry.rs for test using module system
    - add logic to skip rustfmt::skip::macros only
    - remove base_skip_macro_names
    - remove Rc
    - use clone to append skip_macro_names
2019-03-21 21:45:39 +09:00
Stéphane Campinas
be0ada27f4 Add comment which refers to an issue on nightly-only test
Co-Authored-By: topecongiro <seuchida@gmail.com>
2019-03-17 12:33:18 +09:00
topecongiro
7fc4e418bf Tweak test settings 2019-03-17 12:33:18 +09:00
topecongiro
bde77714e6 Disable self_tests on beta channel 2019-03-17 12:21:57 +09:00
Igor Matuszewski
6b993c8b8b Fix stdin_works... test on Windows 2019-03-04 18:28:25 +01:00
Igor Matuszewski
b3c28dba83 Expose ModifiedLines and implement parsing data from the string output
This moves `Modified{Chunks,Lines}` from `src/formatting.rs` to
`src/rustfmt_diff.rs` and reexports it in `src/lib.rs`.

With this, a conversion from `Vec<Mismatch>` to `ModifiedLines` was implemented
and now this implements complementary `Display` and `FromStr`, which
simplified the previously used `output_modified` function and which allows to
parse the raw data emitted with `EmitMode::ModifiedLines`.
2019-03-04 18:19:30 +01:00
Igor Matuszewski
0437bf7a7d Allow for stdin input in EmitMode::ModifiedLines 2019-03-04 18:19:30 +01:00
Alexander Regueiro
7a3b7c9275 Various cosmetic improvements (#3403) 2019-02-19 11:56:42 +09:00
Hirokazu Hata
4bb90f5cc8 Fix rust_2018_idioms warnings 2019-02-09 16:14:30 +09:00
Evgenii
ece629b1cc transition to Rust 2018 2019-02-04 13:30:43 +03:00
Seiichi Uchida
3f6ea7788b
Merge pull request #3240 from Xanewok/parser-panic
Catch possible tokenizer panics
2018-12-18 11:30:08 +09:00
Andreas Jonson
653f3ae636 use the rustfmt function to find the bin
makes it possible to execute the test after a release build
2018-12-14 23:32:25 +01:00
Andreas Jonson
836562baf4 remove deprecated dependency assert_cli 2018-12-14 23:32:08 +01:00
Igor Matuszewski
10b9afa906 Add test asserting we catch Rust parser panics 2018-12-13 13:35:15 +01:00
Matthias Krüger
3aa153398a fix a few clippy warnings
types.rs:
fix single_char_pattern (use character patters instead of string for .ends_with() and .starts_with()

patterns.rs
expr.rs
file_lines.rs:
fix into_iter_on_ref_ptr (use iter() or iter_mut() instead of into_iter()

tests/mod.rs:
check_files(): take Option<PathBuf> by reference
2018-11-16 22:25:33 +01:00