Skip to content

Commit b6e3a9a

Browse files
committed
Clean up integration tests
1 parent 1bbc858 commit b6e3a9a

File tree

1 file changed

+88
-66
lines changed

1 file changed

+88
-66
lines changed

crates/ruff_cli/tests/integration_test.rs

Lines changed: 88 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,7 @@ fn check_input_from_argfile() -> Result<()> {
871871
}
872872

873873
#[test]
874-
fn displays_fix_applicability_levels() {
875-
// `--fix` should only apply safe fixes, but should tell the user about `--unsafe-fixes` if
876-
// there are remaining fixes.
874+
fn check_hints_hidden_unsafe_fixes() {
877875
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
878876
.args([
879877
"-",
@@ -898,7 +896,7 @@ fn displays_fix_applicability_levels() {
898896
}
899897

900898
#[test]
901-
fn displays_remaining_unsafe_fixes() {
899+
fn check_hints_hidden_unsafe_fixes_with_no_safe_fixes() {
902900
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
903901
.args(["-", "--output-format", "text", "--no-cache", "--isolated", "--select", "F601"])
904902
.pass_stdin("x = {'a': 1, 'a': 1}\n"),
@@ -915,9 +913,33 @@ fn displays_remaining_unsafe_fixes() {
915913
}
916914

917915
#[test]
918-
fn fix_applies_safe_fixes_only() {
919-
// `--fix` should only apply safe fixes. Since we're runnnig in `stdin` mode, output shouldn't
920-
// be printed.
916+
fn check_shows_unsafe_fixes_with_opt_in() {
917+
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
918+
.args([
919+
"-",
920+
"--output-format=text",
921+
"--isolated",
922+
"--select",
923+
"F601,UP034",
924+
"--no-cache",
925+
"--unsafe-fixes",
926+
])
927+
.pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"),
928+
@r###"
929+
success: false
930+
exit_code: 1
931+
----- stdout -----
932+
-:1:14: F601 [*] Dictionary key literal `'a'` repeated
933+
-:2:7: UP034 [*] Avoid extraneous parentheses
934+
Found 2 errors.
935+
[*] 2 fixable with the --fix option.
936+
937+
----- stderr -----
938+
"###);
939+
}
940+
941+
#[test]
942+
fn fix_applies_safe_fixes_by_default() {
921943
assert_cmd_snapshot!(
922944
Command::new(get_cargo_bin(BIN_NAME))
923945
.args([
@@ -943,7 +965,7 @@ fn fix_applies_safe_fixes_only() {
943965
}
944966

945967
#[test]
946-
fn fix_applies_safe_and_unsafe_fixes_with_unsafe_fixes() {
968+
fn fix_applies_unsafe_fixes_with_opt_in() {
947969
assert_cmd_snapshot!(
948970
Command::new(get_cargo_bin(BIN_NAME))
949971
.args([
@@ -970,39 +992,60 @@ fn fix_applies_safe_and_unsafe_fixes_with_unsafe_fixes() {
970992
}
971993

972994
#[test]
973-
fn diff_shows_safe_and_unsafe_fixes_with_unsafe_fixes() {
995+
fn fix_only_flag_applies_safe_fixes_by_default() {
974996
assert_cmd_snapshot!(
975997
Command::new(get_cargo_bin(BIN_NAME))
976998
.args([
977999
"-",
9781000
"--output-format",
9791001
"text",
9801002
"--isolated",
981-
"--no-cache",
1003+
"--no-cache",
9821004
"--select",
9831005
"F601,UP034",
984-
"--diff",
985-
"--unsafe-fixes",
1006+
"--fix-only",
9861007
])
9871008
.pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"),
9881009
@r###"
989-
success: false
990-
exit_code: 1
1010+
success: true
1011+
exit_code: 0
9911012
----- stdout -----
992-
@@ -1,2 +1,2 @@
993-
-x = {'a': 1}
994-
-print('foo')
995-
+x = {'a': 1, 'a': 1}
996-
+print(('foo'))
1013+
x = {'a': 1, 'a': 1}
1014+
print('foo')
9971015
1016+
----- stderr -----
1017+
"###);
1018+
}
1019+
1020+
#[test]
1021+
fn fix_only_flag_applies_unsafe_fixes_with_opt_in() {
1022+
assert_cmd_snapshot!(
1023+
Command::new(get_cargo_bin(BIN_NAME))
1024+
.args([
1025+
"-",
1026+
"--output-format",
1027+
"text",
1028+
"--isolated",
1029+
"--no-cache",
1030+
"--select",
1031+
"F601,UP034",
1032+
"--fix-only",
1033+
"--unsafe-fixes",
1034+
])
1035+
.pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"),
1036+
@r###"
1037+
success: true
1038+
exit_code: 0
1039+
----- stdout -----
1040+
x = {'a': 1}
1041+
print('foo')
9981042
9991043
----- stderr -----
1000-
"###
1001-
);
1044+
"###);
10021045
}
10031046

10041047
#[test]
1005-
fn diff_shows_safe_fixes_only() {
1048+
fn diff_shows_safe_fixes_by_default() {
10061049
assert_cmd_snapshot!(
10071050
Command::new(get_cargo_bin(BIN_NAME))
10081051
.args([
@@ -1032,54 +1075,33 @@ fn diff_shows_safe_fixes_only() {
10321075
}
10331076

10341077
#[test]
1035-
fn fix_only_applies_safe_and_unsafe_fixes_with_unsafe_fixes() {
1078+
fn diff_shows_unsafe_fixes_with_opt_in() {
10361079
assert_cmd_snapshot!(
10371080
Command::new(get_cargo_bin(BIN_NAME))
1038-
.args([
1039-
"-",
1040-
"--output-format",
1041-
"text",
1042-
"--isolated",
1043-
"--no-cache",
1044-
"--select",
1045-
"F601,UP034",
1046-
"--fix-only",
1047-
"--unsafe-fixes",
1048-
])
1049-
.pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"),
1050-
@r###"
1051-
success: true
1052-
exit_code: 0
1081+
.args([
1082+
"-",
1083+
"--output-format",
1084+
"text",
1085+
"--isolated",
1086+
"--no-cache",
1087+
"--select",
1088+
"F601,UP034",
1089+
"--diff",
1090+
"--unsafe-fixes",
1091+
])
1092+
.pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"),
1093+
@r###"
1094+
success: false
1095+
exit_code: 1
10531096
----- stdout -----
1054-
x = {'a': 1}
1055-
print('foo')
1097+
@@ -1,2 +1,2 @@
1098+
-x = {'a': 1}
1099+
-print('foo')
1100+
+x = {'a': 1, 'a': 1}
1101+
+print(('foo'))
10561102
1057-
----- stderr -----
1058-
"###);
1059-
}
1060-
1061-
#[test]
1062-
fn fix_only_applies_safe_fixes_only() {
1063-
assert_cmd_snapshot!(
1064-
Command::new(get_cargo_bin(BIN_NAME))
1065-
.args([
1066-
"-",
1067-
"--output-format",
1068-
"text",
1069-
"--isolated",
1070-
"--no-cache",
1071-
"--select",
1072-
"F601,UP034",
1073-
"--fix-only",
1074-
])
1075-
.pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"),
1076-
@r###"
1077-
success: true
1078-
exit_code: 0
1079-
----- stdout -----
1080-
x = {'a': 1, 'a': 1}
1081-
print('foo')
10821103
10831104
----- stderr -----
1084-
"###);
1105+
"###
1106+
);
10851107
}

0 commit comments

Comments
 (0)