@Beta public abstract class LintDetectorTest extends BaseLintDetectorTest
NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.
Modifier and Type | Class and Description |
---|---|
class |
LintDetectorTest.CustomIssueRegistry |
class |
LintDetectorTest.TestConfiguration |
static class |
LintDetectorTest.TestFile
Test file description, which can copy from resource directory or from
a specified hardcoded string literal, and copy into a target directory
|
class |
LintDetectorTest.TestLintClient |
sCleanDirs
Constructor and Description |
---|
LintDetectorTest() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowAndroidBuildEnvironment()
Normally having $ANDROID_BUILD_TOP set when running lint is a bad idea
(because it enables some special support in lint for checking code in AOSP
itself.) However, some lint tests (particularly custom lint checks) may not care
about this.
|
protected boolean |
allowCompilationErrors() |
static TestFile.BinaryTestFile |
base64(java.lang.String to,
java.lang.String encoded)
Creates a test file from the given base64 data.
|
static TestFile.BinaryTestFile |
base64gzip(java.lang.String to,
java.lang.String encoded)
Decodes base64 strings into gzip data, then decodes that into a data file.
|
static TestFile.BinaryTestFile |
bytecode(java.lang.String to,
TestFile.BytecodeProducer producer) |
static TestFile.BinaryTestFile |
bytes(java.lang.String to,
byte[] bytes) |
protected java.lang.String |
checkLint(LintDetectorTest.TestLintClient lintClient,
java.util.List<java.io.File> files) |
protected java.lang.String |
checkLint(java.util.List<java.io.File> files) |
protected void |
checkReportedError(com.android.tools.lint.detector.api.Context context,
com.android.tools.lint.detector.api.Issue issue,
com.android.tools.lint.detector.api.Severity severity,
com.android.tools.lint.detector.api.Location location,
java.lang.String message) |
static LintDetectorTest.TestFile |
classpath(java.lang.String... extraLibraries) |
protected void |
configureDriver(com.android.tools.lint.client.api.LintDriver driver) |
LintDetectorTest.TestFile |
copy(java.lang.String from) |
LintDetectorTest.TestFile |
copy(java.lang.String from,
java.lang.String to) |
protected LintDetectorTest.TestLintClient |
createClient() |
static LintDetectorTest.TestFile |
file() |
protected boolean |
forceErrors()
If true, simulate symbol resolutions when
JavaParser.prepareJavaParse(List)
is called |
protected LintDetectorTest.TestConfiguration |
getConfiguration(com.android.tools.lint.client.api.LintClient client,
com.android.tools.lint.detector.api.Project project) |
protected abstract com.android.tools.lint.detector.api.Detector |
getDetector() |
protected com.android.tools.lint.detector.api.Detector |
getDetectorInstance() |
protected abstract java.util.List<com.android.tools.lint.detector.api.Issue> |
getIssues() |
protected java.util.EnumSet<com.android.tools.lint.detector.api.Scope> |
getLintScope(java.util.List<java.io.File> file) |
protected java.io.File |
getProjectDir(java.lang.String name,
LintDetectorTest.TestFile... testFiles)
Creates a project directory structure from the given files
|
protected java.io.File |
getProjectDir(java.lang.String name,
java.lang.String... relativePaths)
Deprecated.
Use
getProjectDir(String, TestFile...) instead |
java.lang.String |
getSuperClass(com.android.tools.lint.detector.api.Project project,
java.lang.String name) |
protected java.io.File |
getTargetDir()
Get the location to write missing golden files to
|
java.io.InputStream |
getTestResource(java.lang.String relativePath,
boolean expectExists) |
static TestFile.GradleTestFile |
gradle(java.lang.String source) |
static TestFile.GradleTestFile |
gradle(java.lang.String to,
java.lang.String source) |
protected boolean |
ignoreSystemErrors() |
static TestFile.ImageTestFile |
image(java.lang.String to,
int width,
int height) |
protected static boolean |
imageFormatSupported(java.lang.String format) |
protected boolean |
includeParentPath() |
protected boolean |
isEnabled(com.android.tools.lint.detector.api.Issue issue) |
static TestFile.JarTestFile |
jar(java.lang.String to) |
static TestFile.JarTestFile |
jar(java.lang.String to,
LintDetectorTest.TestFile... files) |
static LintDetectorTest.TestFile |
java(java.lang.String source) |
static LintDetectorTest.TestFile |
java(java.lang.String to,
java.lang.String source) |
protected TestLintTask |
lint() |
protected java.lang.String |
lintFiles(LintDetectorTest.TestFile... relativePaths) |
protected java.lang.String |
lintFiles(java.lang.String... relativePaths)
Deprecated.
Use
lintFiles(TestFile...) instead |
protected java.lang.String |
lintProject(LintDetectorTest.TestFile... files)
Run lint on the given files when constructed as a separate project
|
protected java.lang.String |
lintProject(java.lang.String... relativePaths)
Deprecated.
Use
lintProject(TestFile...) instead |
protected java.lang.String |
lintProjectIncrementally(java.lang.String currentFile,
LintDetectorTest.TestFile... files) |
protected java.lang.String |
lintProjectIncrementally(java.lang.String currentFile,
java.lang.String... relativePaths)
Deprecated.
Use
lintProjectIncrementally(String, TestFile...) instead |
static TestFile.ManifestTestFile |
manifest() |
static LintDetectorTest.TestFile |
manifest(java.lang.String source) |
static void |
populateProjectDirectory(java.io.File projectDir,
LintDetectorTest.TestFile... testFiles) |
protected static ProjectDescription |
project(LintDetectorTest.TestFile... files) |
static TestFile.PropertyTestFile |
projectProperties() |
protected void |
setUp() |
protected boolean |
skipExtraTokenChecks()
If false (the default), lint will run your detectors twice, first on the
plain source code, and then a second time where it has inserted whitespace
and parentheses pretty much everywhere, to help catch bugs where your detector
is only checking direct parents or siblings rather than properly allowing for
whitespace and parenthesis nodes which can be present for example when using
PSI inside the IDE.
|
static LintDetectorTest.TestFile |
source(java.lang.String to,
java.lang.String source) |
protected void |
tearDown() |
static java.lang.String |
toBase64(byte[] bytes) |
static java.lang.String |
toBase64(java.io.File file) |
static java.lang.String |
toBase64gzip(byte[] bytes) |
static java.lang.String |
toBase64gzip(java.io.File file) |
static LintDetectorTest.TestFile |
xml(java.lang.String to,
java.lang.String source) |
addCleanupDir, addSelection, assertEqualsGolden, assertEqualsGolden, cleanup, deleteFile, findSrcDir, findSrcRelativeDir, getCaretContext, getCaretOffset, getTempDir, getTestDataRelPath, getTestfile, makeTestFile, readTestFile, removeSessionData
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
protected void setUp() throws java.lang.Exception
setUp
in class junit.framework.TestCase
java.lang.Exception
protected void tearDown() throws java.lang.Exception
tearDown
in class junit.framework.TestCase
java.lang.Exception
protected abstract com.android.tools.lint.detector.api.Detector getDetector()
protected final com.android.tools.lint.detector.api.Detector getDetectorInstance()
protected boolean allowCompilationErrors()
protected boolean skipExtraTokenChecks()
protected abstract java.util.List<com.android.tools.lint.detector.api.Issue> getIssues()
protected java.lang.String lintFiles(LintDetectorTest.TestFile... relativePaths) throws java.lang.Exception
java.lang.Exception
@Deprecated protected java.lang.String lintFiles(java.lang.String... relativePaths) throws java.lang.Exception
lintFiles(TestFile...)
insteadjava.lang.Exception
protected java.lang.String checkLint(java.util.List<java.io.File> files) throws java.lang.Exception
java.lang.Exception
protected boolean allowAndroidBuildEnvironment()
protected java.lang.String checkLint(LintDetectorTest.TestLintClient lintClient, java.util.List<java.io.File> files) throws java.lang.Exception
java.lang.Exception
protected void checkReportedError(@NonNull com.android.tools.lint.detector.api.Context context, @NonNull com.android.tools.lint.detector.api.Issue issue, @NonNull com.android.tools.lint.detector.api.Severity severity, @NonNull com.android.tools.lint.detector.api.Location location, @NonNull java.lang.String message)
protected LintDetectorTest.TestLintClient createClient()
protected LintDetectorTest.TestConfiguration getConfiguration(com.android.tools.lint.client.api.LintClient client, com.android.tools.lint.detector.api.Project project)
protected void configureDriver(com.android.tools.lint.client.api.LintDriver driver)
@Deprecated protected java.lang.String lintProject(java.lang.String... relativePaths) throws java.lang.Exception
lintProject(TestFile...)
insteadjava.lang.Exception
@Deprecated protected java.lang.String lintProjectIncrementally(java.lang.String currentFile, java.lang.String... relativePaths) throws java.lang.Exception
lintProjectIncrementally(String, TestFile...)
insteadjava.lang.Exception
protected java.lang.String lintProjectIncrementally(java.lang.String currentFile, LintDetectorTest.TestFile... files) throws java.lang.Exception
java.lang.Exception
protected static ProjectDescription project(@NonNull LintDetectorTest.TestFile... files)
@NonNull protected TestLintTask lint()
protected java.lang.String lintProject(LintDetectorTest.TestFile... files) throws java.lang.Exception
java.lang.Exception
protected java.io.File getTargetDir()
BaseLintDetectorTest
getTargetDir
in class BaseLintDetectorTest
@NonNull public static LintDetectorTest.TestFile file()
@NonNull public static LintDetectorTest.TestFile source(@NonNull java.lang.String to, @NonNull java.lang.String source)
@NonNull public static LintDetectorTest.TestFile java(@NonNull java.lang.String to, @NonNull java.lang.String source)
@NonNull public static LintDetectorTest.TestFile java(@NonNull java.lang.String source)
@NonNull public static LintDetectorTest.TestFile xml(@NonNull java.lang.String to, @NonNull java.lang.String source)
@NonNull public LintDetectorTest.TestFile copy(@NonNull java.lang.String from)
@NonNull public LintDetectorTest.TestFile copy(@NonNull java.lang.String from, @NonNull java.lang.String to)
@NonNull public static TestFile.GradleTestFile gradle(@NonNull java.lang.String to, @NonNull java.lang.String source)
@NonNull public static TestFile.GradleTestFile gradle(@NonNull java.lang.String source)
@NonNull public static TestFile.ManifestTestFile manifest()
@NonNull public static LintDetectorTest.TestFile manifest(@NonNull java.lang.String source)
@NonNull public static TestFile.PropertyTestFile projectProperties()
@NonNull public static TestFile.BinaryTestFile bytecode(@NonNull java.lang.String to, @NonNull TestFile.BytecodeProducer producer)
@NonNull public static TestFile.BinaryTestFile bytes(@NonNull java.lang.String to, @NonNull byte[] bytes)
public static java.lang.String toBase64(@NonNull byte[] bytes)
public static java.lang.String toBase64gzip(@NonNull byte[] bytes)
public static java.lang.String toBase64(@NonNull java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String toBase64gzip(@NonNull java.io.File file) throws java.io.IOException
java.io.IOException
public static TestFile.BinaryTestFile base64(@NonNull java.lang.String to, @NonNull java.lang.String encoded)
toBase64(File)
or toBase64(byte[])
, for example via
assertEquals("", toBase64(new File("path/to/your.class")));
to
- the file to write asencoded
- the encoded data@NonNull public static TestFile.BinaryTestFile base64gzip(@NonNull java.lang.String to, @NonNull java.lang.String encoded)
toBase64gzip(File)
or toBase64gzip(byte[])
,
for example via
assertEquals("", toBase64gzip(new File("path/to/your.class")));
public static LintDetectorTest.TestFile classpath(java.lang.String... extraLibraries)
@NonNull public static TestFile.JarTestFile jar(@NonNull java.lang.String to)
@NonNull public static TestFile.JarTestFile jar(@NonNull java.lang.String to, @NonNull LintDetectorTest.TestFile... files)
public static TestFile.ImageTestFile image(@NonNull java.lang.String to, int width, int height)
protected static boolean imageFormatSupported(@NonNull java.lang.String format)
@Deprecated protected java.io.File getProjectDir(java.lang.String name, java.lang.String... relativePaths) throws java.lang.Exception
getProjectDir(String, TestFile...)
insteadjava.lang.Exception
protected java.io.File getProjectDir(java.lang.String name, LintDetectorTest.TestFile... testFiles) throws java.lang.Exception
java.lang.Exception
public static void populateProjectDirectory(@NonNull java.io.File projectDir, @NonNull LintDetectorTest.TestFile... testFiles) throws java.io.IOException
java.io.IOException
public java.io.InputStream getTestResource(java.lang.String relativePath, boolean expectExists)
getTestResource
in interface TestResourceProvider
getTestResource
in class BaseLintDetectorTest
protected boolean isEnabled(com.android.tools.lint.detector.api.Issue issue)
protected boolean includeParentPath()
protected java.util.EnumSet<com.android.tools.lint.detector.api.Scope> getLintScope(java.util.List<java.io.File> file)
public java.lang.String getSuperClass(com.android.tools.lint.detector.api.Project project, java.lang.String name)
protected boolean forceErrors()
JavaParser.prepareJavaParse(List)
is calledprotected boolean ignoreSystemErrors()