halkyon/test/release/version_test.dart

88 lines
2.8 KiB
Dart
Raw Normal View History

import 'package:test/test.dart';
import '../../tool/src/release/version.dart';
void main() {
Commit commit(String subject, [String body = '']) =>
Commit(hash: 'c0ffee', subject: subject, body: body);
group('a version', () {
test('reads as semantic versioning writes it, and nothing else', () {
expect(Version.tryParse('0.17.0'), const Version(0, 17, 0));
expect(Version.tryParse('1.2.3')?.toString(), '1.2.3');
for (final text in [
'1.2',
'1.2.3.4',
'v1.2.3',
'1.2.3-beta',
'',
'x.y.z',
]) {
expect(Version.tryParse(text), isNull, reason: text);
}
});
test('is raised by one part, the parts after it starting again', () {
const version = Version(1, 4, 2);
expect(version.bumped(Bump.major), const Version(2, 0, 0));
expect(version.bumped(Bump.minor), const Version(1, 5, 0));
expect(version.bumped(Bump.patch), const Version(1, 4, 3));
});
test("is read with its build from a pubspec's version line", () {
expect(declaredVersion('name: x\nversion: 0.17.0+20\n'), (
const Version(0, 17, 0),
20,
));
expect(declaredVersion('name: x\nversion: 0.17.0\n'), isNull);
expect(declaredVersion('name: x\n'), isNull);
});
});
group('the commits since the last release', () {
const beforeOne = Version(0, 17, 0);
const afterOne = Version(1, 2, 0);
test('a feature raises the minor number, a fix or speed-up the patch', () {
expect(bumpFor(beforeOne, [commit('feat(study): x')]), Bump.minor);
expect(bumpFor(beforeOne, [commit('feat: x')]), Bump.minor);
expect(bumpFor(beforeOne, [commit('fix(sync): x')]), Bump.patch);
expect(bumpFor(beforeOne, [commit('perf: x')]), Bump.patch);
expect(
bumpFor(beforeOne, [commit('fix: x'), commit('feat(app): y')]),
Bump.minor,
);
});
test('a breaking change raises the major number from 1.0 on, the minor '
'one before', () {
expect(bumpFor(afterOne, [commit('refactor(auth)!: x')]), Bump.major);
expect(bumpFor(beforeOne, [commit('refactor(auth)!: x')]), Bump.minor);
expect(
bumpFor(afterOne, [
commit('docs: x', 'Why.\n\nBREAKING CHANGE: older apps stop.'),
]),
Bump.major,
);
// Only at a line's start does it count.
expect(
bumpFor(afterOne, [commit('docs: x', 'No BREAKING CHANGE: here.')]),
isNull,
);
});
test('other types release nothing by themselves', () {
expect(
bumpFor(beforeOne, [
commit('docs: x'),
commit('chore(release): learn-v0.18.0'),
commit('build: y'),
commit('Merge branch z'),
commit('halkyon_app: an untyped subject'),
]),
isNull,
);
expect(bumpFor(beforeOne, const []), isNull);
});
});
}