Skip to content

Commit fed6544

Browse files
authored
fix #916 autofix CLI, add integration test for it (#917)
1 parent 4c759b0 commit fed6544

File tree

9 files changed

+42
-8
lines changed

9 files changed

+42
-8
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tests/it/source_autofix.d text eol=lf
1+
tests/it/autofix_ide/source_autofix.d text eol=lf

src/dscanner/analysis/run.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,12 @@ private struct UserSelect
611611
if (special.shorthands.canFind(input))
612612
return special.id;
613613

614-
int item = input.to!int;
615-
if (item < 0 || item > regularItems.length)
614+
int item = input.to!int - 1;
615+
if (item < 0 || item >= regularItems.length)
616616
throw new Exception("Selected option number out of range.");
617617
return item;
618618
}
619-
catch (ConvException e)
619+
catch (Exception e)
620620
{
621621
writeln("Invalid selection, try again. ", e.message);
622622
}

tests/it.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,34 @@ cd "$DSCANNER_DIR/tests"
1313
# IDE APIs
1414
# --------
1515
# checking that reporting format stays consistent or only gets extended
16-
diff <(../bin/dscanner --report it/source_autofix.d | jq -S .) <(jq -S . it/source_autofix.report.json)
17-
diff <(../bin/dscanner --resolveMessage b16 it/source_autofix.d | jq -S .) <(jq -S . it/source_autofix.autofix.json)
16+
diff <(../bin/dscanner --report it/autofix_ide/source_autofix.d | jq -S .) <(jq -S . it/autofix_ide/source_autofix.report.json)
17+
diff <(../bin/dscanner --resolveMessage b16 it/autofix_ide/source_autofix.d | jq -S .) <(jq -S . it/autofix_ide/source_autofix.autofix.json)
1818

19+
# CLI tests
20+
# ---------
21+
# check that `dscanner fix` works as expected
22+
echo '1. test no changes if EOFing'
23+
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
24+
printf "" | ../bin/dscanner fix it/autofix_cli/test.d
25+
diff it/autofix_cli/test.d it/autofix_cli/source.d
26+
echo '2. test no changes for simple enter pressing'
27+
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
28+
printf "\n" | ../bin/dscanner fix it/autofix_cli/test.d
29+
diff it/autofix_cli/test.d it/autofix_cli/source.d
30+
echo '2.1. test no changes entering 0'
31+
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
32+
printf "0\n" | ../bin/dscanner fix it/autofix_cli/test.d
33+
diff it/autofix_cli/test.d it/autofix_cli/source.d
34+
echo '3. test change applies automatically with --applySingle'
35+
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
36+
../bin/dscanner fix --applySingle it/autofix_cli/test.d | grep -F 'Writing changes to it/autofix_cli/test.d'
37+
diff it/autofix_cli/test.d it/autofix_cli/fixed.d
38+
echo '4. test change apply when entering "1"'
39+
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
40+
printf "1\n" | ../bin/dscanner fix it/autofix_cli/test.d | grep -F 'Writing changes to it/autofix_cli/test.d'
41+
diff it/autofix_cli/test.d it/autofix_cli/fixed.d
42+
echo '5. test invalid selection reasks what to apply'
43+
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
44+
printf "2\n-1\n1000\na\n1\n" | ../bin/dscanner fix it/autofix_cli/test.d | grep -F 'Writing changes to it/autofix_cli/test.d'
45+
diff it/autofix_cli/test.d it/autofix_cli/fixed.d
1946

tests/it/autofix_cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.d

tests/it/autofix_cli/fixed.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void main()
2+
{
3+
}

tests/it/autofix_cli/source.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
auto main()
2+
{
3+
}
File renamed without changes.

tests/it/source_autofix.report.json renamed to tests/it/autofix_ide/source_autofix.report.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"endColumn": 12,
99
"endIndex": 22,
1010
"endLine": 3,
11-
"fileName": "it\/source_autofix.d",
11+
"fileName": "it/autofix_ide/source_autofix.d",
1212
"index": 16,
1313
"key": "dscanner.confusing.function_attributes",
1414
"line": 3,
@@ -78,7 +78,7 @@
7878
"endColumn": 10,
7979
"endIndex": 71,
8080
"endLine": 8,
81-
"fileName": "it/source_autofix.d",
81+
"fileName": "it/autofix_ide/source_autofix.d",
8282
"index": 64,
8383
"key": "dscanner.suspicious.static_if_else",
8484
"line": 8,

0 commit comments

Comments
 (0)