play build versionCode source check: follow a variable (def / ext. / val) to its definition; a variable read from the property is not flagged
This commit is contained in:
parent
0b1451800c
commit
2e7dd44ae6
3 changed files with 23 additions and 2 deletions
|
|
@ -319,6 +319,16 @@ describe('versionCode / versionName source in the build file', () => {
|
|||
// commented out lines do not count; nothing set at all is said too
|
||||
expect(kinds('app/build.gradle', gv(" // versionCode 1\n /* versionName '1.0' */")).map(k => [k[0], k[1]])).toEqual([['versionCode', 'missing'], ['versionName', 'missing']]);
|
||||
});
|
||||
test('a variable read from the property first, then used, is not flagged (STAR DASH pattern); an env-only variable is', () => {
|
||||
const top = (def: string, body: string) => `plugins { id 'com.android.application' }\n${def}\nandroid {\n defaultConfig {\n${body}\n }\n}\n`;
|
||||
const ok = top("def erVersionCode = (project.findProperty('versionCode') ?: System.getenv('ER_ANDROID_VERSION_CODE') ?: '1').toString().toInteger()\ndef erVersionName = project.findProperty('versionName') ?: '1.0.0'",
|
||||
' versionCode erVersionCode\n versionName erVersionName');
|
||||
expect(kinds('app/build.gradle', ok)).toEqual([]);
|
||||
expect(kinds('app/build.gradle', top("ext.vc = (project.findProperty('versionCode') ?: 1) as Integer\next.vn = project.findProperty('versionName') ?: '1.0'", ' versionCode vc\n versionName vn'))).toEqual([]);
|
||||
expect(kinds('app/build.gradle.kts', `val vc = (project.findProperty("versionCode") as String?)?.toInt() ?: 1\nval vn: String = project.findProperty("versionName") as String? ?: "1.0"\nandroid {\n defaultConfig {\n versionCode = vc\n versionName = vn\n }\n}\n`)).toEqual([]);
|
||||
const env = top("def code = (System.getenv('VERSION_CODE') ?: '1').toInteger()", " versionCode code\n versionName project.findProperty('versionName') ?: '1.0'");
|
||||
expect(kinds('app/build.gradle', env).map(k => [k[0], k[1]])).toEqual([['versionCode', 'other']]);
|
||||
});
|
||||
test('Kotlin: literal and env var warn with the exact line; findProperty does not', () => {
|
||||
expect(kinds('app/build.gradle.kts', kv(' versionCode = 5\n versionName = "2.0"'))).toEqual([
|
||||
['versionCode', 'literal', 6, '5', 'versionCode = (project.findProperty("versionCode") as String?)?.toInt() ?: 5'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue