diff options
author | Tor Norbye <tnorbye@google.com> | 2012-11-01 08:49:16 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-11-01 08:49:16 -0700 |
commit | adc3349c2ba5a8d93e4e2d64509e94a45a740ff8 (patch) | |
tree | cef6887ab2dd0aaf18ed474255825055405bfe74 /lint/libs | |
parent | 318dc1f0f1e79f7fa5add8bd95ab7d71cc92838a (diff) | |
download | sdk-adc3349c2ba5a8d93e4e2d64509e94a45a740ff8.zip sdk-adc3349c2ba5a8d93e4e2d64509e94a45a740ff8.tar.gz sdk-adc3349c2ba5a8d93e4e2d64509e94a45a740ff8.tar.bz2 |
Unit tests for ignoring missing densities via lint.xml
Change-Id: I34d2b91dfa2c36b71c54ca9f83b2749b893a5b7c
Diffstat (limited to 'lint/libs')
4 files changed, 63 insertions, 8 deletions
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java index cd0d6e7..0978dc1 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java @@ -16,15 +16,19 @@ package com.android.tools.lint.checks; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.android.tools.lint.LintCliXmlParser; import com.android.tools.lint.LombokParser; import com.android.tools.lint.Main; import com.android.tools.lint.Reporter; import com.android.tools.lint.TextReporter; import com.android.tools.lint.client.api.Configuration; +import com.android.tools.lint.client.api.DefaultConfiguration; import com.android.tools.lint.client.api.IDomParser; import com.android.tools.lint.client.api.IJavaParser; import com.android.tools.lint.client.api.IssueRegistry; +import com.android.tools.lint.client.api.LintClient; import com.android.tools.lint.client.api.LintDriver; import com.android.tools.lint.detector.api.Context; import com.android.tools.lint.detector.api.Detector; @@ -142,8 +146,8 @@ public abstract class AbstractCheckTest extends TestCase { return new TestLintClient(); } - protected TestConfiguration getConfiguration(Project project) { - return new TestConfiguration(); + protected TestConfiguration getConfiguration(LintClient client, Project project) { + return new TestConfiguration(client, project, null); } protected void configureDriver(LintDriver driver) { @@ -435,7 +439,7 @@ public abstract class AbstractCheckTest extends TestCase { @Override public Configuration getConfiguration(Project project) { - return AbstractCheckTest.this.getConfiguration(project); + return AbstractCheckTest.this.getConfiguration(this, project); } @Override @@ -495,7 +499,33 @@ public abstract class AbstractCheckTest extends TestCase { return null; } - public class TestConfiguration extends Configuration { + public class TestConfiguration extends DefaultConfiguration { + protected TestConfiguration( + @NonNull LintClient client, + @NonNull Project project, + @Nullable Configuration parent) { + super(client, project, parent); + } + + public TestConfiguration( + @NonNull LintClient client, + @Nullable Project project, + @Nullable Configuration parent, + @NonNull File configFile) { + super(client, project, parent, configFile); + } + + @Override + @NonNull + protected Severity getDefaultSeverity(@NonNull Issue issue) { + // In unit tests, include issues that are ignored by default + Severity severity = super.getDefaultSeverity(issue); + if (severity == Severity.IGNORE) { + return Severity.WARNING; + } + return severity; + } + @Override public boolean isEnabled(Issue issue) { return AbstractCheckTest.this.isEnabled(issue); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java index af11d22..0671a43 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java @@ -16,6 +16,7 @@ package com.android.tools.lint.checks; +import com.android.tools.lint.client.api.LintClient; import com.android.tools.lint.client.api.LintDriver; import com.android.tools.lint.detector.api.Detector; import com.android.tools.lint.detector.api.Issue; @@ -61,8 +62,8 @@ public class IconDetectorTest extends AbstractCheckTest { } @Override - protected TestConfiguration getConfiguration(Project project) { - return new TestConfiguration() { + protected TestConfiguration getConfiguration(LintClient client, Project project) { + return new TestConfiguration(client, project, null) { @Override public boolean isEnabled(Issue issue) { return super.isEnabled(issue) && mEnabled.contains(issue); @@ -409,4 +410,21 @@ public class IconDetectorTest extends AbstractCheckTest { "res/drawable/ic_launcher.png=>res/drawable-mdpi/ic_launcher12.png" )); } + + public void testIgnoreMissingFolders() throws Exception { + mEnabled = Collections.singleton(IconDetector.ICON_DENSITIES); + assertEquals( + "No warnings.", + + lintProject( + // Use minSDK4 to ensure that we get warnings about missing drawables + "apicheck/minsdk4.xml=>AndroidManifest.xml", + "ignoremissing.xml=>lint.xml", + "res/drawable/ic_launcher.png=>res/drawable-hdpi/ic_launcher1.png", + "res/drawable/ic_launcher.png=>res/drawable-mdpi/ic_launcher1.png", + "res/drawable/ic_launcher.png=>res/drawable-mdpi/ic_launcher2.png" + )); + } + + }
\ No newline at end of file diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java index 5b4d565..ccb9123 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java @@ -16,6 +16,7 @@ package com.android.tools.lint.checks; +import com.android.tools.lint.client.api.LintClient; import com.android.tools.lint.detector.api.Detector; import com.android.tools.lint.detector.api.Issue; import com.android.tools.lint.detector.api.Project; @@ -36,8 +37,8 @@ public class ManifestOrderDetectorTest extends AbstractCheckTest { private Set<Issue> mEnabled = new HashSet<Issue>(); @Override - protected TestConfiguration getConfiguration(Project project) { - return new TestConfiguration() { + protected TestConfiguration getConfiguration(LintClient client, Project project) { + return new TestConfiguration(client, project, null) { @Override public boolean isEnabled(Issue issue) { return super.isEnabled(issue) && mEnabled.contains(issue); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/ignoremissing.xml b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/ignoremissing.xml new file mode 100644 index 0000000..99d804e --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/ignoremissing.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lint> + <issue id="IconDensities" severity="warning"> + <ignore path="res/drawable-hdpi" /> + </issue> +</lint> |