Skip to content

Commit f6ce62a

Browse files
committed
test: added actual ui-toml tests
1 parent a4d8766 commit f6ce62a

File tree

16 files changed

+271
-32
lines changed

16 files changed

+271
-32
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6216,7 +6216,9 @@ Released 2018-09-13
62166216
[`standard-macro-braces`]: https://doc.rust-lang.org/clippy/lint_configuration.html#standard-macro-braces
62176217
[`struct-field-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#struct-field-name-threshold
62186218
[`suppress-restriction-lint-in-const`]: https://doc.rust-lang.org/clippy/lint_configuration.html#suppress-restriction-lint-in-const
6219-
[`test-without-fail-case`]: https://doc.rust-lang.org/clippy/lint_configuration.html#test-without-fail-case
6219+
[`test-without-fail-case-fallible-paths`]: https://doc.rust-lang.org/clippy/lint_configuration.html#test-without-fail-case-fallible-paths
6220+
[`test-without-fail-case-include-indexing-as-fallible`]: https://doc.rust-lang.org/clippy/lint_configuration.html#test-without-fail-case-include-indexing-as-fallible
6221+
[`test-without-fail-case-non-fallible-paths`]: https://doc.rust-lang.org/clippy/lint_configuration.html#test-without-fail-case-non-fallible-paths
62206222
[`too-large-for-stack`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-large-for-stack
62216223
[`too-many-arguments-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-many-arguments-threshold
62226224
[`too-many-lines-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-many-lines-threshold

book/src/lint_configuration.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,50 @@ if no suggestion can be made.
831831
* [`indexing_slicing`](https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing)
832832

833833

834-
## `test-without-fail-case`
835-
Lint tests to understand whether it can fail or not.
834+
## `test-without-fail-case-fallible-paths`
835+
List of full paths of macros and functions, that can fail. If a test, or a function
836+
that the test calls contains a call to any one of these, lint will mark the test fallible.
836837

837-
**Default Value:** `{ include_indexing_as_fallible = false, fallible_paths = ["core::panic", "core::assert", "core::assert_eq", "core::assert_ne"], non_fallible_paths = ["std::print", "std::println", "std::dbg", "std::eprint", "std::eprintln"] }`
838+
By default this macros are defined as `assert!`, `assert_eq!`, `panic!`.
839+
840+
**Default Value:** `["core::panic", "core::assert", "core::assert_eq", "core::assert_ne"]`
841+
842+
---
843+
**Affected lints:**
844+
* [`test_without_fail_case`](https://rust-lang.github.io/rust-clippy/master/index.html#test_without_fail_case)
845+
846+
847+
## `test-without-fail-case-include-indexing-as-fallible`
848+
Whether to consider indexing as a fallible operation while assesing if a test can fail.
849+
Indexing is fallible, and thus the a test that is doing that can fail but it is likely
850+
that tests that fail this way were not intended.
851+
852+
If set true, the lint will consider indexing into a slice a failable case
853+
and won't lint tests that has some sort of indexing. This analysis still done
854+
in a interprocedural manner. Meaning that any indexing opeartion done inside of
855+
a function that the test calls will still result the test getting marked fallible.
856+
857+
By default this is set to `false`. That is because from a usability perspective,
858+
indexing an array is not the intended way to fail a test. So setting this `true`
859+
reduces false positives but makes the analysis more focused on possible byproducts
860+
of a test. That is the set of operations to get the point we assert something rather
861+
than the existance of asserting that thing.
862+
863+
**Default Value:** `false`
864+
865+
---
866+
**Affected lints:**
867+
* [`test_without_fail_case`](https://rust-lang.github.io/rust-clippy/master/index.html#test_without_fail_case)
868+
869+
870+
## `test-without-fail-case-non-fallible-paths`
871+
List of full paths of macros and functions, that we want to mark as "not going to fail".
872+
This allows us to make the lint more focused on actual short comings of our test suite
873+
by marking common routines non-fallible, even though they are fallible.
874+
875+
By default this list contains: `println!`, `print!`, `dbg!`.
876+
877+
**Default Value:** `["std::print", "std::println", "std::dbg", "std::eprint", "std::eprintln"]`
838878

839879
---
840880
**Affected lints:**

clippy_config/src/conf.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,8 @@ define_Conf! {
639639
///
640640
/// By default this macros are defined as `assert!`, `assert_eq!`, `panic!`.
641641
#[lints(test_without_fail_case)]
642-
test_without_fail_case_fallible_paths: Vec<String> = Vec::new(),
643-
/// List of full paths of macros and functions, that we want to mark as "not going to fail".
644-
/// This allows us to make the lint more focused on actual short comings of our test suite
645-
/// by marking common routines non-fallible, even though they are fallible.
646-
///
647-
/// By default this list contains: `println!`, `print!`, `dbg!`.
648-
#[lints(test_without_fail_case)]
649-
test_without_fail_case_non_fallible_paths: Vec<String> = Vec::new(),
642+
test_without_fail_case_fallible_paths: Vec<String> =
643+
DEFAULT_FALLIBLE_PATHS.iter().map(ToString::to_string).collect(),
650644
/// Whether to consider indexing as a fallible operation while assesing if a test can fail.
651645
/// Indexing is fallible, and thus the a test that is doing that can fail but it is likely
652646
/// that tests that fail this way were not intended.
@@ -663,6 +657,14 @@ define_Conf! {
663657
/// than the existance of asserting that thing.
664658
#[lints(test_without_fail_case)]
665659
test_without_fail_case_include_indexing_as_fallible: bool = false,
660+
/// List of full paths of macros and functions, that we want to mark as "not going to fail".
661+
/// This allows us to make the lint more focused on actual short comings of our test suite
662+
/// by marking common routines non-fallible, even though they are fallible.
663+
///
664+
/// By default this list contains: `println!`, `print!`, `dbg!`.
665+
#[lints(test_without_fail_case)]
666+
test_without_fail_case_non_fallible_paths: Vec<String> =
667+
DEFAULT_NONFALLIBLE_PATHS.iter().map(ToString::to_string).collect(),
666668
/// The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap
667669
#[lints(boxed_local, useless_vec)]
668670
too_large_for_stack: u64 = 200,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[macro_export]
2+
macro_rules! fallible_macro {
3+
( $x:expr ) => {{
4+
let _ = $x;
5+
panic!("a");
6+
}};
7+
}
8+
9+
#[macro_export]
10+
macro_rules! non_fallible_macro {
11+
( $x:expr ) => {{
12+
let _ = $x;
13+
}};
14+
}

tests/ui-toml/test_without_fail_case/default/clippy.toml

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test-without-fail-case-fallible-paths = ["test_macro::non_fallible_macro"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test-without-fail-case-include-indexing-as-fallible = true

tests/ui-toml/test_without_fail_case/indexing_fallible/clippy.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/ui-toml/test_without_fail_case/macro_fallible/clippy.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test-without-fail-case-non-fallible-paths = ["test_macro::fallible_macro"]

0 commit comments

Comments
 (0)