android lint: some test for batch-mode-only inspections

This commit is contained in:
Eugene Kudelevsky
2012-02-06 15:28:02 +04:00
parent c2a480052c
commit d6a94bef2d
9 changed files with 86 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>dup2.png</file>
<line>1</line>
<description>The following unrelated icon files have identical contents: dup1.png, dup2.png</description>
</problem>
</problems>
Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<application android:label="MyApp" >
</application>
<uses-sdk android:minSdkVersion="7"/>
</manifest>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>AndroidManifest.xml</file>
<line>9</line>
<description>&lt;uses-sdk&gt; tag appears after &lt;application&gt; tag</description>
</problem>
</problems>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>proguard.cfg</file>
<line>1</line>
<description>Obsolete proguard file; use -keepclasseswithmembers instead of -keepclasseswithmembernames</description>
</problem>
</problems>
@@ -0,0 +1,3 @@
-keepclasseswithmembernames class * {
public <init>(android.");
}
@@ -1,11 +1,20 @@
package org.jetbrains.android;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionManagerEx;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.android.inspections.lint.*;
import com.intellij.testFramework.InspectionTestUtil;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import org.jetbrains.android.inspections.lint.AndroidAddStringResourceQuickFix;
import org.jetbrains.android.inspections.lint.AndroidLintExternalAnnotator;
import org.jetbrains.android.inspections.lint.AndroidLintInspectionBase;
import org.jetbrains.android.inspections.lint.AndroidLintInspectionToolProvider;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -18,6 +27,7 @@ import java.io.IOException;
*/
public class AndroidLintTest extends AndroidTestCase {
@NonNls private static final String BASE_PATH = "/lint/";
@NonNls private static final String BASE_PATH_GLOBAL = BASE_PATH + "global/";
public AndroidLintTest() {
super(false);
@@ -152,6 +162,44 @@ public class AndroidLintTest extends AndroidTestCase {
"/res/values/typography.xml", "xml");
}
public void testProguard() throws Exception {
createManifest();
myFixture.copyFileToProject(getGlobalTestDir() + "/proguard.cfg", "proguard.cfg");
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintProguardInspection());
}
public void testManifestOrder() throws Exception {
myFixture.copyFileToProject(getGlobalTestDir() + "/AndroidManifest.xml", "AndroidManifest.xml");
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintManifestOrderInspection());
}
public void testDuplicateIcons() throws Exception {
createManifest();
myFixture.copyFileToProject(getGlobalTestDir() + "/dup1.png", "res/drawable/dup1.png");
myFixture.copyFileToProject(getGlobalTestDir() + "/dup2.png", "res/drawable/dup2.png");
myFixture.copyFileToProject(getGlobalTestDir() + "/other.png", "res/drawable/other.png");
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintIconDuplicatesInspection());
}
private void doGlobalInspectionTest(@NotNull AndroidLintInspectionBase inspection) {
final GlobalInspectionToolWrapper wrapper = new GlobalInspectionToolWrapper(inspection);
myFixture.enableInspections(wrapper);
final AnalysisScope scope = new AnalysisScope(myModule);
scope.invalidate();
final InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
final GlobalInspectionContextImpl globalContext =
CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, wrapper);
InspectionTestUtil.runTool(wrapper, scope, globalContext, inspectionManager);
InspectionTestUtil.compareToolResults(wrapper, false, getTestDataPath() + getGlobalTestDir());
}
private String getGlobalTestDir() {
return BASE_PATH_GLOBAL + getTestName(true);
}
private void doTestNoFix(@NotNull AndroidLintInspectionBase inspection, @NotNull String copyTo, @NotNull String extension)
throws IOException {
doTestHighlighting(inspection, copyTo, extension);