Skip to content

Commit

Permalink
False positive warning "Function ... is never used" #214
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Apr 7, 2024
1 parent eb69f81 commit d93247d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/test/java/intellij_awk/AwkInspectionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,21 @@ public void testIssue203NoUnusedFunctionErrForUsageInOtherFile() {
myFixture.addFileToProject("c.awk", "BEGIN { f() } ");
assertNoInspectionAtCaret(unusedFunction);
}

public void testIssue203NoUnusedFunctionErrForRepeatingDefinitionInSeparateFiles() {
myFixture.configureByText("a.awk", "function <caret>f(){}");
myFixture.addFileToProject("b.awk", "function f() {}");
myFixture.addFileToProject("c.awk", "BEGIN { f() } ");
assertNoInspectionAtCaret(unusedFunction);
}

public void testIssue203UnusedFunctionErrForRepeatingDefinitionWhenFunctionIsUsedInSameFileAsDefined() {
public void
testIssue203UnusedFunctionErrForRepeatingDefinitionWhenFunctionIsUsedInSameFileAsDefined() {
myFixture.configureByText("a.awk", "function <caret>f(){}");
myFixture.addFileToProject("c.awk", "BEGIN { f() } function f() {}");
assertInspectionIsShown(unusedFunction);
}


public void testUsedVarInFileOutsideProject() {
checkByFileNoProblemAtCaret(unusedGlobalVariable, true);
}
Expand Down Expand Up @@ -299,6 +300,22 @@ public void testUnnecessarySemicolonNecessary4() {
checkByFileNoProblemAtCaret(unnecessarySemicolon);
}

public void testFuncRefToPreventUnusedFunc1() {
checkByFileNoProblemAtCaret(unusedFunction);
}

public void testFuncRefToPreventUnusedFunc1_1() {
checkByFile(unusedFunction);
}

public void testFuncRefToPreventUnusedFunc2() {
checkByFileNoProblemAtCaret(unusedFunction);
}

public void testFuncRefToPreventUnusedFunc2_1() {
checkByFile(unusedFunction);
}

@Override
protected String getTestDataPath() {
return "src/test/testData/inspection";
Expand Down
5 changes: 5 additions & 0 deletions src/test/testData/inspection/funcRefToPreventUnusedFunc1.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN {
PROCINFO["sorted_in"] = "compare"
}

function <caret>compare() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN {
PROCINFO["sorted_in"] = "compare1"
}

function <caret>compare() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BEGIN {
PROCINFO["sorted_in"] = "compare1"
}

6 changes: 6 additions & 0 deletions src/test/testData/inspection/funcRefToPreventUnusedFunc2.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN {
F = "fname"
@F()
}

function <caret>fname() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN {
F = "aaa fname bbb"
@F()
}

function <caret>fname() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN {
F = "aaa fname bbb"
@F()
}

0 comments on commit d93247d

Please sign in to comment.