diff --git a/lib/versioning/cargo/index.spec.ts b/lib/versioning/cargo/index.spec.ts index a75fe37271804e8ffaa8bb26dab34f29a1f9ad92..cc3f97701e9d69b37883808ba613be4aca58b4cd 100644 --- a/lib/versioning/cargo/index.spec.ts +++ b/lib/versioning/cargo/index.spec.ts @@ -103,6 +103,24 @@ describe('semver.isSingleVersion()', () => { }); }); describe('semver.getNewValue()', () => { + it('returns if empty or *', () => { + expect( + semver.getNewValue({ + currentValue: null, + rangeStrategy: 'bump', + fromVersion: '1.0.0', + toVersion: '1.1.0', + }) + ).toEqual(null); + expect( + semver.getNewValue({ + currentValue: '*', + rangeStrategy: 'bump', + fromVersion: '1.0.0', + toVersion: '1.1.0', + }) + ).toEqual('*'); + }); it('bumps equals', () => { expect( semver.getNewValue({ diff --git a/lib/versioning/cargo/index.ts b/lib/versioning/cargo/index.ts index cf605c34ddceba7fcf47ef4897a77e0fef405931..2cdd3f830376c2aadfc46d2ccaf73e3a929f8a0c 100644 --- a/lib/versioning/cargo/index.ts +++ b/lib/versioning/cargo/index.ts @@ -1,5 +1,6 @@ import { api as npm } from '../npm'; import { VersioningApi, NewValueConfig } from '../common'; +import { logger } from '../../logger'; export const id = 'cargo'; export const displayName = 'Cargo'; @@ -33,6 +34,10 @@ function notEmpty(s: string): boolean { } function npm2cargo(input: string): string { + // istanbul ignore if + if (!input) { + return input; + } // Note: this doesn't remove the ^ const res = input .split(' ') @@ -73,6 +78,9 @@ function getNewValue({ fromVersion, toVersion, }: NewValueConfig): string { + if (!currentValue || currentValue === '*') { + return currentValue; + } if (rangeStrategy === 'pin' || isSingleVersion(currentValue)) { let res = '='; if (currentValue.startsWith('= ')) { @@ -88,6 +96,14 @@ function getNewValue({ toVersion, }); let newCargo = npm2cargo(newSemver); + // istanbul ignore if + if (!newCargo) { + logger.info( + { currentValue, newSemver }, + 'Could not get cargo version from semver' + ); + return currentValue; + } // Try to reverse any caret we added if (newCargo.startsWith('^') && !currentValue.startsWith('^')) { newCargo = newCargo.substring(1);