Skip to content
Snippets Groups Projects
Unverified Commit b544d5ca authored by Johannes Feichtner's avatar Johannes Feichtner Committed by GitHub
Browse files

test(manager/gradle): refactoring to map tests to Gradle functionality (#18481)

parent 1b2eb931
No related branches found
No related tags found
No related merge requests found
...@@ -105,7 +105,8 @@ describe('modules/manager/gradle/extract', () => { ...@@ -105,7 +105,8 @@ describe('modules/manager/gradle/extract', () => {
it('works with file-ext-var', async () => { it('works with file-ext-var', async () => {
mockFs({ mockFs({
'gradle.properties': 'baz=1.2.3', 'gradle.properties': 'baz=1.2.3',
'build.gradle': 'url "https://example.com"; "foo:bar:$baz@zip"', 'build.gradle':
'repositories { maven { url "https://example.com" } }; "foo:bar:$baz@zip"',
'settings.gradle': null as never, // TODO: #7154 'settings.gradle': null as never, // TODO: #7154
}); });
...@@ -171,10 +172,10 @@ describe('modules/manager/gradle/extract', () => { ...@@ -171,10 +172,10 @@ describe('modules/manager/gradle/extract', () => {
it('deduplicates registry urls', async () => { it('deduplicates registry urls', async () => {
const fsMock = { const fsMock = {
'build.gradle': [ 'build.gradle': [
'url "https://repo.maven.apache.org/maven2"', 'repositories { maven { url "https://repo.maven.apache.org/maven2" } }',
'url "https://repo.maven.apache.org/maven2"', 'repositories { maven { url "https://repo.maven.apache.org/maven2" } }',
'url "https://example.com"', 'repositories { maven { url "https://example.com" } }',
'url "https://example.com"', 'repositories { maven { url "https://example.com" } }',
'id "foo.bar" version "1.2.3"', 'id "foo.bar" version "1.2.3"',
'"foo:bar:1.2.3"', '"foo:bar:1.2.3"',
].join(';\n'), ].join(';\n'),
......
...@@ -32,15 +32,17 @@ describe('modules/manager/gradle/parser', () => { ...@@ -32,15 +32,17 @@ describe('modules/manager/gradle/parser', () => {
expect((await parseGradle('id "foo.bar" version')).deps).toBeEmpty(); expect((await parseGradle('id "foo.bar" version')).deps).toBeEmpty();
}); });
describe('variable assignments', () => { describe('variables', () => {
describe('Groovy: single var assignments', () => {
test.each` test.each`
input | name | value input | name | value
${'version = "1.2.3"'} | ${'version'} | ${'1.2.3'} ${'foo = "1.2.3"'} | ${'foo'} | ${'1.2.3'}
${'set("version", "1.2.3")'} | ${'version'} | ${'1.2.3'} ${'foo.bar = "1.2.3"'} | ${'foo.bar'} | ${'1.2.3'}
${'versions.foobar = "1.2.3"'} | ${'versions.foobar'} | ${'1.2.3'}
${'ext.foobar = "1.2.3"'} | ${'foobar'} | ${'1.2.3'} ${'ext.foobar = "1.2.3"'} | ${'foobar'} | ${'1.2.3'}
${'project.foobar = "1.2.3"'} | ${'foobar'} | ${'1.2.3'} ${'project.foobar = "1.2.3"'} | ${'foobar'} | ${'1.2.3'}
${'project.ext.foo.bar = "1.2.3"'} | ${'foo.bar'} | ${'1.2.3'}
${'rootProject.foobar = "1.2.3"'} | ${'foobar'} | ${'1.2.3'} ${'rootProject.foobar = "1.2.3"'} | ${'foobar'} | ${'1.2.3'}
${'rootProject.foo.bar = "1.2.3"'} | ${'foo.bar'} | ${'1.2.3'}
`('$input', async ({ input, name, value }) => { `('$input', async ({ input, name, value }) => {
const { vars } = await parseGradle(input); const { vars } = await parseGradle(input);
expect(vars).toContainKey(name); expect(vars).toContainKey(name);
...@@ -48,59 +50,60 @@ describe('modules/manager/gradle/parser', () => { ...@@ -48,59 +50,60 @@ describe('modules/manager/gradle/parser', () => {
}); });
}); });
describe('dependencies', () => { describe('Kotlin: single var assignments', () => {
describe('simple cases', () => {
test.each` test.each`
input | output input | name | value
${'group: "foo", name: "bar", version: "1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} ${'set("foo", "1.2.3")'} | ${'foo'} | ${'1.2.3'}
${"implementation platform(group: 'foo', name: 'bar', version: '1.2.3')"} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} ${'version("foo", "1.2.3")'} | ${'foo'} | ${'1.2.3'}
${'group: "foo", name: "bar", version: depVersion'} | ${null} `('$input', async ({ input, name, value }) => {
${'("foo", "bar", "1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} const { vars } = await parseGradle(input);
${'(group = "foo", name = "bar", version = "1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} expect(vars).toContainKey(name);
${'"foo:bar:1.2.3@zip"'} | ${{ currentValue: '1.2.3', dataType: 'zip', depName: 'foo:bar' }} expect(vars[name]).toMatchObject({ key: name, value });
${'(group: "foo", name: "bar", version: "1.2.3", classifier: "sources")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} });
${'(group: "foo", name: "bar", version: "1.2.3") {exclude module: "spring-jcl"}'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
`('$input', async ({ input, output }) => {
const { deps } = await parseGradle(input);
expect(deps).toMatchObject([output].filter(Boolean));
}); });
}); });
describe('annoying methods', () => { describe('dependencies', () => {
describe('simple dependency strings', () => {
test.each` test.each`
input | output input | output
${'createXmlValueRemover("defaults", "integer", "integer")'} | ${{ depName: 'defaults:integer', currentValue: 'integer', skipReason: 'ignored' }} ${'"foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'events("passed", "skipped", "failed")'} | ${{ depName: 'passed:skipped', currentValue: 'failed', skipReason: 'ignored' }} ${'"foo:bar:1.2.3@zip"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', dataType: 'zip' }}
${'args("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }} ${'foo.bar = "foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'arrayOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'listOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'mutableListOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'setOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'mutableSetOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'stages("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
`('$input', async ({ input, output }) => { `('$input', async ({ input, output }) => {
const { deps } = await parseGradle(input); const { deps } = await parseGradle(input);
expect(deps).toMatchObject([output].filter(Boolean)); expect(deps).toMatchObject([output].filter(Boolean));
}); });
}); });
describe('variable substitutions', () => { describe('interpolated dependency strings', () => {
test.each` test.each`
def | str | output def | str | output
${'foo = "1.2.3"'} | ${'"foo:bar:$foo@@@"'} | ${null} ${'foo = "1.2.3"'} | ${'"foo:bar:$foo@@@"'} | ${null}
${''} | ${'"foo:bar:$baz"'} | ${null}
${'foo = "1"; bar = "2"; baz = "3"'} | ${'"foo:bar:$foo.$bar.$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', skipReason: 'contains-variable' }} ${'foo = "1"; bar = "2"; baz = "3"'} | ${'"foo:bar:$foo.$bar.$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', skipReason: 'contains-variable' }}
${'baz = "1.2.3"'} | ${'"foo:bar:$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} ${'baz = "1.2.3"'} | ${'"foo:bar:$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
${'foo.bar = "1.2.3"'} | ${'"foo:bar:$foo.bar"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'foo.bar' }} ${'foo.bar = "1.2.3"'} | ${'"foo:bar:$foo.bar"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'foo.bar' }}
${'foo = "1.2.3"'} | ${'"foo:bar_$foo:4.5.6"'} | ${{ depName: 'foo:bar_1.2.3', managerData: { fileReplacePosition: 28 } }} ${'foo = "1.2.3"'} | ${'"foo:bar_$foo:4.5.6"'} | ${{ depName: 'foo:bar_1.2.3', managerData: { fileReplacePosition: 28 } }}
${''} | ${'foo.bar = "foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'baz = "1.2.3"'} | ${'foobar = "foo:bar:$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} ${'baz = "1.2.3"'} | ${'foobar = "foo:bar:$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
`('$def | $str', async ({ def, str, output }) => {
const { deps } = await parseGradle([def, str].join('\n'));
expect(deps).toMatchObject([output].filter(Boolean));
});
});
describe('map notation dependencies', () => {
test.each`
def | str | output
${''} | ${'group: "foo", name: "bar", version: "1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${''} | ${'group: "foo", name: "bar", version: baz'} | ${null}
${'baz = "1.2.3"'} | ${'group: "foo", name: "bar", version: baz'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} ${'baz = "1.2.3"'} | ${'group: "foo", name: "bar", version: baz'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
${'baz = "1.2.3"'} | ${'library("foo.bar", "foo", "bar").versionRef("baz")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} ${''} | ${'(group: "foo", name: "bar", version: "1.2.3", classifier: "sources")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${''} | ${'library("foo.bar", "foo", "bar").version("1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} ${''} | ${'(group: "foo", name: "bar", version: "1.2.3") {exclude module: "spring-jcl"}'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'library("foo-bar_baz-qux", "foo", "bar")'} | ${'"${foo.bar.baz.qux}:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} ${''} | ${"implementation platform(group: 'foo', name: 'bar', version: '1.2.3')"} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${''} | ${'(group = "foo", name = "bar", version = "1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
`('$def | $str', async ({ def, str, output }) => { `('$def | $str', async ({ def, str, output }) => {
const input = [def, str].join('\n'); const { deps } = await parseGradle([def, str].join('\n'));
const { deps } = await parseGradle(input);
expect(deps).toMatchObject([output].filter(Boolean)); expect(deps).toMatchObject([output].filter(Boolean));
}); });
}); });
...@@ -109,54 +112,106 @@ describe('modules/manager/gradle/parser', () => { ...@@ -109,54 +112,106 @@ describe('modules/manager/gradle/parser', () => {
test.each` test.each`
def | input | output def | input | output
${''} | ${'id "foo.bar" version "1.2.3"'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }} ${''} | ${'id "foo.bar" version "1.2.3"'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
${''} | ${'id(["foo.bar"]) version "1.2.3"'} | ${null}
${''} | ${'id("foo", "bar") version "1.2.3"'} | ${null}
${''} | ${'id("foo.bar") version "1.2.3"'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }} ${''} | ${'id("foo.bar") version "1.2.3"'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
${''} | ${'kotlin("jvm") version "1.3.71"'} | ${{ depName: 'org.jetbrains.kotlin.jvm', packageName: 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin', currentValue: '1.3.71' }} ${''} | ${'id "foo.bar" version "$baz"'} | ${{ depName: 'foo.bar', skipReason: 'unknown-version', currentValue: 'baz' }}
${''} | ${'id "foo.bar" version something'} | ${{ depName: 'foo.bar', currentValue: 'something', skipReason: 'unknown-version' }} ${'baz = "1.2.3"'} | ${'id "foo.bar" version "$baz"'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
${'baz = "1.2.3"'} | ${'id("foo.bar") version "$baz"'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
${''} | ${'id "foo.bar" version "x${ab}cd"'} | ${{ depName: 'foo.bar', skipReason: 'unknown-version' }}
${''} | ${'id("foo.bar") version "$baz"'} | ${{ depName: 'foo.bar', skipReason: 'unknown-version', currentValue: 'baz' }}
${''} | ${'id("foo.bar") version "x${ab}cd"'} | ${{ depName: 'foo.bar', skipReason: 'unknown-version' }}
${''} | ${'id "foo.bar" version baz'} | ${{ depName: 'foo.bar', currentValue: 'baz', skipReason: 'unknown-version' }}
${'baz = "1.2.3"'} | ${'id "foo.bar" version baz'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }} ${'baz = "1.2.3"'} | ${'id "foo.bar" version baz'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
${'baz = "1.2.3"'} | ${'id("foo.bar") version baz'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }} ${'baz = "1.2.3"'} | ${'id("foo.bar") version baz'} | ${{ depName: 'foo.bar', packageName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
${''} | ${'kotlin("jvm") version "1.3.71"'} | ${{ depName: 'org.jetbrains.kotlin.jvm', packageName: 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin', currentValue: '1.3.71' }}
${'baz = "1.3.71"'} | ${'kotlin("jvm") version baz'} | ${{ depName: 'org.jetbrains.kotlin.jvm', packageName: 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin', currentValue: '1.3.71' }} ${'baz = "1.3.71"'} | ${'kotlin("jvm") version baz'} | ${{ depName: 'org.jetbrains.kotlin.jvm', packageName: 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin', currentValue: '1.3.71' }}
${'z = "1.2.3"'} | ${'id "x.y" version "$z"'} | ${{ depName: 'x.y', packageName: 'x.y:x.y.gradle.plugin', currentValue: '1.2.3' }} `('$def | $input', async ({ def, input, output }) => {
${''} | ${'id "x.y" version "$z"'} | ${{ depName: 'x.y', skipReason: 'unknown-version', currentValue: 'z' }}
${''} | ${'id "x.y" version "x${y}z"'} | ${{ depName: 'x.y', skipReason: 'unknown-version' }}
${'z = "1.2.3"'} | ${'id("x.y") version "$z"'} | ${{ depName: 'x.y', packageName: 'x.y:x.y.gradle.plugin', currentValue: '1.2.3' }}
${''} | ${'id("x.y") version "$z"'} | ${{ depName: 'x.y', skipReason: 'unknown-version', currentValue: 'z' }}
${''} | ${'id("x.y") version "x${y}z"'} | ${{ depName: 'x.y', skipReason: 'unknown-version' }}
`('$input', async ({ def, input, output }) => {
const { deps } = await parseGradle([def, input].join('\n')); const { deps } = await parseGradle([def, input].join('\n'));
expect(deps).toMatchObject([output].filter(Boolean)); expect(deps).toMatchObject([output].filter(Boolean));
}); });
}); });
}); });
describe('registryUrls', () => { describe('registries', () => {
describe('predefined registries', () => {
test.each`
input | output
${'mavenCentral()'} | ${MAVEN_REPO}
${'google()'} | ${GOOGLE_REPO}
${'google { content { includeGroup "foo" } }'} | ${GOOGLE_REPO}
${'gradlePluginPortal()'} | ${GRADLE_PLUGIN_PORTAL_REPO}
${'jcenter()'} | ${JCENTER_REPO}
`('$input', async ({ input, output }) => {
const { urls } = await parseGradle(input);
expect(urls).toStrictEqual([output].filter(Boolean));
});
});
describe('custom registries', () => {
test.each` test.each`
def | input | url def | input | url
${''} | ${'url ""'} | ${null} ${''} | ${'maven("")'} | ${null}
${''} | ${'url "#!@"'} | ${null} ${''} | ${'maven(["https://foo.bar/baz/qux"])'} | ${null}
${''} | ${'url "https://example.com"'} | ${'https://example.com'} ${''} | ${'maven("foo", "bar")'} | ${null}
${'base="https://foo.bar"'} | ${'url "${base}/baz"'} | ${'https://foo.bar/baz'} ${''} | ${'maven("https://foo.bar/baz")'} | ${'https://foo.bar/baz'}
${''} | ${'url("https://example.com")'} | ${'https://example.com'} ${'base="https://foo.bar"'} | ${'maven("${base}/baz")'} | ${'https://foo.bar/baz'}
${'base="https://foo.bar"'} | ${'url("${base}/baz")'} | ${'https://foo.bar/baz'} ${''} | ${'maven(uri(["https://foo.bar/baz"]))'} | ${null}
${''} | ${'mavenCentral()'} | ${MAVEN_REPO} ${''} | ${'maven { ["https://foo.bar/baz"] }'} | ${null}
${''} | ${'jcenter()'} | ${JCENTER_REPO} ${''} | ${'maven { url "https://foo.bar/baz" }'} | ${'https://foo.bar/baz'}
${''} | ${'google()'} | ${GOOGLE_REPO} ${'base="https://foo.bar"'} | ${'maven { url "${base}/baz" }'} | ${'https://foo.bar/baz'}
${''} | ${'google { content { includeGroup "foo" } }'} | ${GOOGLE_REPO} ${''} | ${'maven { url = "https://foo.bar/baz" }'} | ${'https://foo.bar/baz'}
${''} | ${'gradlePluginPortal()'} | ${GRADLE_PLUGIN_PORTAL_REPO} ${'base="https://foo.bar"'} | ${'maven { url = "${base}/baz" }'} | ${'https://foo.bar/baz'}
${''} | ${'maven("https://foo.bar/baz/qux")'} | ${'https://foo.bar/baz/qux'} ${''} | ${'maven { url = uri("https://foo.bar/baz") }'} | ${'https://foo.bar/baz'}
${'base="https://foo.bar"'} | ${'maven("${base}/baz/qux")'} | ${'https://foo.bar/baz/qux'} ${'base="https://foo.bar"'} | ${'maven { url = uri("${base}/baz") }'} | ${'https://foo.bar/baz'}
${''} | ${'maven { url = uri("https://foo.bar/baz")'} | ${'https://foo.bar/baz'} ${'base="https://foo.bar"'} | ${'maven { name = "baz"\nurl = "${base}/${name}" }'} | ${'https://foo.bar/baz'}
${'base="https://foo.bar"'} | ${'maven { url = uri("${base}/baz")'} | ${'https://foo.bar/baz'}
${''} | ${"maven { url 'https://foo.bar/baz'"} | ${'https://foo.bar/baz'}
${'base="https://foo.bar"'} | ${'maven { url "${base}/baz"'} | ${'https://foo.bar/baz'}
${''} | ${"maven { url = 'https://foo.bar/baz'"} | ${'https://foo.bar/baz'}
${'base="https://foo.bar"'} | ${'maven { url = "${base}/baz"'} | ${'https://foo.bar/baz'}
${'base="https://foo.bar"'} | ${'maven { name = "baz"\nurl = "${base}/${name}"'} | ${'https://foo.bar/baz'}
`('$def | $input', async ({ def, input, url }) => { `('$def | $input', async ({ def, input, url }) => {
const expected = [url].filter(Boolean); const expected = [url].filter(Boolean);
const { urls } = await parseGradle([def, input].join('\n')); const { urls } = await parseGradle([def, input].join('\n'));
expect(urls).toStrictEqual(expected); expect(urls).toStrictEqual(expected);
}); });
}); });
});
describe('version catalog', () => {
test.each`
def | str | output
${'version("baz", "1.2.3")'} | ${'library("foo.bar", "foo", "bar").versionRef("baz")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
${'version("baz", "1.2.3")'} | ${'library("foo.bar", "foo", "bar").versionRef("baz")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
${''} | ${'library("foo.bar", "foo", "bar").version("1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${''} | ${'library(["foo.bar", "foo", "bar"]).version("1.2.3")'} | ${null}
${''} | ${'library("foo", "bar", "baz", "qux"]).version("1.2.3")'} | ${null}
${''} | ${'library("foo.bar", "foo", "bar").version("1.2.3", "4.5.6")'} | ${null}
${'group = "foo"; artifact="bar"'} | ${'library("foo.bar", group, artifact).version("1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'library("foo-bar_baz-qux", "foo", "bar")'} | ${'"${foo.bar.baz.qux}:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
`('$def | $str', async ({ def, str, output }) => {
const input = [def, str].join('\n');
const { deps } = await parseGradle(input);
expect(deps).toMatchObject([output].filter(Boolean));
});
});
describe('heuristic dependency matching', () => {
test.each`
input | output
${'("foo", "bar", "1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'("foo", "bar", "1.2.3", "4.5.6")'} | ${null}
${'(["foo", "bar", "1.2.3"])'} | ${null}
${'someMethod("foo", "bar", "1.2.3")'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'createXmlValueRemover("defaults", "integer", "integer")'} | ${{ depName: 'defaults:integer', currentValue: 'integer', skipReason: 'ignored' }}
${'events("passed", "skipped", "failed")'} | ${{ depName: 'passed:skipped', currentValue: 'failed', skipReason: 'ignored' }}
${'args("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'arrayOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'listOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'mutableListOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'setOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'mutableSetOf("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
${'stages("foo", "bar", "baz")'} | ${{ depName: 'foo:bar', currentValue: 'baz', skipReason: 'ignored' }}
`('$input', async ({ input, output }) => {
const { deps } = await parseGradle(input);
expect(deps).toMatchObject([output].filter(Boolean));
});
});
describe('calculations', () => { describe('calculations', () => {
it('calculates offset', async () => { it('calculates offset', async () => {
...@@ -241,14 +296,16 @@ describe('modules/manager/gradle/parser', () => { ...@@ -241,14 +296,16 @@ describe('modules/manager/gradle/parser', () => {
}, },
}; };
mockFs({ const fileContents = {
'foo/bar.gradle': key + ' = "' + value + '"', 'foo/bar.gradle': key + ' = "' + value + '"',
}); };
mockFs(fileContents);
test.each` test.each`
def | input | output def | input | output
${''} | ${'apply from: ""'} | ${{}} ${''} | ${'apply from: ""'} | ${{}}
${''} | ${'apply from: "foo/invalid.gradle"'} | ${{}} ${''} | ${'apply from: "foo/invalid.gradle"'} | ${{}}
${''} | ${'apply from: "${base}"'} | ${{}}
${''} | ${'apply from: "foo/invalid.non-gradle"'} | ${{}} ${''} | ${'apply from: "foo/invalid.non-gradle"'} | ${{}}
${''} | ${'apply from: "https://someurl.com/file.gradle"'} | ${{}} ${''} | ${'apply from: "https://someurl.com/file.gradle"'} | ${{}}
${''} | ${'apply from: "foo/bar.gradle"'} | ${validOutput} ${''} | ${'apply from: "foo/bar.gradle"'} | ${validOutput}
...@@ -262,9 +319,12 @@ describe('modules/manager/gradle/parser', () => { ...@@ -262,9 +319,12 @@ describe('modules/manager/gradle/parser', () => {
${''} | ${'apply from: new File("foo", "bar.gradle")'} | ${validOutput} ${''} | ${'apply from: new File("foo", "bar.gradle")'} | ${validOutput}
${'base="foo"'} | ${'apply from: new File(base, "bar.gradle")'} | ${validOutput} ${'base="foo"'} | ${'apply from: new File(base, "bar.gradle")'} | ${validOutput}
${'base="foo"'} | ${'apply from: new File("${base}", "bar.gradle")'} | ${validOutput} ${'base="foo"'} | ${'apply from: new File("${base}", "bar.gradle")'} | ${validOutput}
${'path="bar.gradle"'} | ${'apply from: new File("foo", "${path}")'} | ${validOutput}
${''} | ${'apply(from = "foo/bar.gradle"))'} | ${validOutput} ${''} | ${'apply(from = "foo/bar.gradle"))'} | ${validOutput}
${'base="foo"'} | ${'apply(from = "${base}/bar.gradle"))'} | ${validOutput} ${'base="foo"'} | ${'apply(from = "${base}/bar.gradle"))'} | ${validOutput}
${''} | ${'apply(from = File("foo/bar.gradle"))'} | ${validOutput} ${''} | ${'apply(from = File("foo/bar.gradle"))'} | ${validOutput}
${''} | ${'apply(from = File("foo", "bar", "baz"))'} | ${{}}
${''} | ${'apply(from = File(["${somedir}/foo.gradle"]))'} | ${{}}
${'base="foo"'} | ${'apply(from = File("${base}/bar.gradle"))'} | ${validOutput} ${'base="foo"'} | ${'apply(from = File("${base}/bar.gradle"))'} | ${validOutput}
${''} | ${'apply(from = File("foo", "bar.gradle"))'} | ${validOutput} ${''} | ${'apply(from = File("foo", "bar.gradle"))'} | ${validOutput}
${'base="foo"'} | ${'apply(from = File(base, "bar.gradle"))'} | ${validOutput} ${'base="foo"'} | ${'apply(from = File(base, "bar.gradle"))'} | ${validOutput}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment