Skip to content

Commit

Permalink
Iterate on coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-leonhard committed Nov 19, 2024
1 parent 809203f commit 2f85481
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
69 changes: 69 additions & 0 deletions lib/modules/versioning/rust-toolchain/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ describe('modules/versioning/rust-toolchain/index', () => {
${'1.82-beta.12'} | ${false}
`('isValid("$version") === $expected', ({ version, expected }) => {
expect(versioning.isValid(version)).toBe(expected);
expect(versioning.isCompatible(version)).toBe(expected);
});

it.each`
version | expected
${'1.82.0'} | ${true}
${'1.82.42'} | ${true}
${'1.82'} | ${false}
${'v1.0'} | ${false}
${'1'} | ${false}
${'2'} | ${false}
${'10'} | ${false}
${'nightly'} | ${false}
${'nightly-06"ENV GRADLE_VERSION=(?<currentValue>.*)-12-2024'} | ${false}
${'beta'} | ${false}
${'beta-06-12-2024'} | ${false}
${'stable'} | ${false}
${'stable-06-12-2024'} | ${false}
${'1.82.0-beta.1'} | ${false}
${'1.82-beta.12'} | ${false}
`('isVersion("$version") === $expected', ({ version, expected }) => {
expect(versioning.isVersion(version)).toBe(expected);
expect(versioning.isSingleVersion(version)).toBe(expected);
});

it.each`
Expand Down Expand Up @@ -106,6 +129,52 @@ describe('modules/versioning/rust-toolchain/index', () => {
).toEqual(['1.82.0', '1.82.4', '1.83.1', '2.80.5']);
});

it.each`
version | range | expected
${'1.82.0'} | ${'1.83'} | ${true}
${'1.82.53'} | ${'1.83'} | ${true}
${'1.83.1'} | ${'1.83.2'} | ${true}
${'1.83.0'} | ${'1.83'} | ${false}
${'1.83.1'} | ${'1.83'} | ${false}
${'1.84.0'} | ${'1.83'} | ${false}
${'1.83.3'} | ${'1.83.2'} | ${false}
`(
'isLessThanRange("$version", "$range") === $expected',
({ version, range, expected }) => {
expect(versioning.isLessThanRange).toBeDefined();
if (!versioning.isLessThanRange) {
throw new Error();
}
expect(versioning.isLessThanRange(version, range)).toBe(expected);
},
);

it.each`
versions | range | expected
${['1.82.0', '1.83.1', '1.83.2']} | ${'1.83'} | ${'1.83.2'}
${['1.82.0', '1.83.1', '1.83.3']} | ${'1.83.3'} | ${'1.83.3'}
${['1.82.0', '1.83.1', '1.83.2']} | ${'1.84'} | ${null}
${['1.83.4']} | ${'1.83.3'} | ${null}
`(
'getSatisfyingVersion("$versions", "$range") === $expected',
({ versions, range, expected }) => {
expect(versioning.getSatisfyingVersion(versions, range)).toBe(expected);
},
);

it.each`
versions | range | expected
${['1.82.0', '1.83.1', '1.83.2']} | ${'1.83'} | ${'1.83.1'}
${['1.82.0', '1.83.1', '1.83.3']} | ${'1.83.3'} | ${'1.83.3'}
${['1.82.0', '1.83.1', '1.83.2']} | ${'1.84'} | ${null}
${['1.83.4']} | ${'1.83.3'} | ${null}
`(
'minSatisfyingVersion("$versions", "$range") === $expected',
({ versions, range, expected }) => {
expect(versioning.minSatisfyingVersion(versions, range)).toBe(expected);
},
);

it.each`
currentValue | newVersion | rangeStrategy | expected
${'1.82.1'} | ${'1.82.0'} | ${'bump'} | ${'1.82.0'}
Expand Down
17 changes: 7 additions & 10 deletions lib/modules/versioning/rust-toolchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ function _parse(version: string): number[] | null {

const release = [];
const { major, minor, patch } = groups;
if (typeof major === 'undefined') {
return null;
} else {
release.push(Number.parseInt(major, 10));
}
if (typeof minor === 'undefined') {
return null;
} else {
release.push(Number.parseInt(minor, 10));
}
release.push(Number.parseInt(major, 10));
release.push(Number.parseInt(minor, 10));
// patch versions are optional.
if (typeof patch !== 'undefined') {
release.push(Number.parseInt(patch, 10));
Expand Down Expand Up @@ -92,6 +84,7 @@ function rust2npm(input: string): string | null {
if (parsed.length === 2) {
return '~' + parsed.join('.');
}
// istanbul ignore next: unreachable, _parse returns length 2 or 3 only.
throw new Error(`Unexpected releases length: ${parsed.join('.')}`);
}

Expand Down Expand Up @@ -141,6 +134,7 @@ function getNewValue({
currentVersion,
newVersion,
});
// istanbul ignore if: unreachable, input validated by rust2npm
if (!newSemver) {
logger.info(
{ currentValue, newSemver },
Expand All @@ -151,6 +145,7 @@ function getNewValue({
// Transform a tilde range back into a major.minor version.
if (newSemver.startsWith('~')) {
const parsed = _parse(newSemver.substring(1));
// istanbul ignore if: unreachable sanity check
if (!parsed || parsed.length !== 3) {
logger.info(
{ currentValue, newSemver },
Expand All @@ -163,6 +158,7 @@ function getNewValue({
// Transform an exact version back into a major.minor.patch version
if (newSemver.startsWith('=')) {
const newValue = newSemver.substring(1);
// istanbul ignore if: unreachable sanity check
if (!_parse(newValue)) {
logger.info(
{ currentValue, newSemver },
Expand All @@ -172,6 +168,7 @@ function getNewValue({
}
return newValue;
}
// istanbul ignore if: unreachable sanity check
if (!isVersion(newSemver)) {
logger.info(
{ currentValue, newSemver },
Expand Down

0 comments on commit 2f85481

Please sign in to comment.