fix #916 autofix CLI, add integration test for it

This commit is contained in:
WebFreak001 2023-07-09 12:46:31 +02:00
parent 4c759b072c
commit ff75ccebfd
No known key found for this signature in database
GPG Key ID: AEFC88D11109D1AA
9 changed files with 33 additions and 7 deletions

2
.gitattributes vendored
View File

@ -1 +1 @@
tests/it/source_autofix.d text eol=lf
tests/it/autofix_ide/source_autofix.d text eol=lf

View File

@ -611,8 +611,8 @@ private struct UserSelect
if (special.shorthands.canFind(input))
return special.id;
int item = input.to!int;
if (item < 0 || item > regularItems.length)
int item = input.to!int - 1;
if (item < 0 || item >= regularItems.length)
throw new Exception("Selected option number out of range.");
return item;
}

View File

@ -13,7 +13,26 @@ cd "$DSCANNER_DIR/tests"
# IDE APIs
# --------
# checking that reporting format stays consistent or only gets extended
diff <(../bin/dscanner --report it/source_autofix.d | jq -S .) <(jq -S . it/source_autofix.report.json)
diff <(../bin/dscanner --resolveMessage b16 it/source_autofix.d | jq -S .) <(jq -S . it/source_autofix.autofix.json)
diff <(../bin/dscanner --report it/autofix_ide/source_autofix.d | jq -S .) <(jq -S . it/autofix_ide/source_autofix.report.json)
diff <(../bin/dscanner --resolveMessage b16 it/autofix_ide/source_autofix.d | jq -S .) <(jq -S . it/autofix_ide/source_autofix.autofix.json)
# CLI tests
# ---------
# check that `dscanner fix` works as expected
echo '1. test no changes if EOFing'
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
printf "" | ../bin/dscanner fix it/autofix_cli/test.d
diff it/autofix_cli/test.d it/autofix_cli/source.d
echo '2. test no changes for simple enter pressing'
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
printf "\n" | ../bin/dscanner fix it/autofix_cli/test.d
diff it/autofix_cli/test.d it/autofix_cli/source.d
echo '3. test change applies automatically with --applySingle'
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
../bin/dscanner fix --applySingle it/autofix_cli/test.d | grep -F 'Writing changes to it/autofix_cli/test.d'
diff it/autofix_cli/test.d it/autofix_cli/fixed.d
echo '4. test change apply when entering "1"'
cp -v it/autofix_cli/source.d it/autofix_cli/test.d
printf "1\n" | ../bin/dscanner fix it/autofix_cli/test.d | grep -F 'Writing changes to it/autofix_cli/test.d'
diff it/autofix_cli/test.d it/autofix_cli/fixed.d

1
tests/it/autofix_cli/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test.d

View File

@ -0,0 +1,3 @@
void main()
{
}

View File

@ -0,0 +1,3 @@
auto main()
{
}

View File

@ -8,7 +8,7 @@
"endColumn": 12,
"endIndex": 22,
"endLine": 3,
"fileName": "it\/source_autofix.d",
"fileName": "it/autofix_ide/source_autofix.d",
"index": 16,
"key": "dscanner.confusing.function_attributes",
"line": 3,
@ -78,7 +78,7 @@
"endColumn": 10,
"endIndex": 71,
"endLine": 8,
"fileName": "it/source_autofix.d",
"fileName": "it/autofix_ide/source_autofix.d",
"index": 64,
"key": "dscanner.suspicious.static_if_else",
"line": 8,