import 'package:test/test.dart'; import '../../tool/src/release/release_push.dart'; import '../../tool/src/release/version.dart'; void main() { Commit release({ String subject = 'chore(release): train-v0.2.0', List files = const [ 'apps/train/halkyon_train_flutter/pubspec.yaml', 'apps/train/halkyon_train_flutter/assets/whats_new/0.2.0.en.txt', 'apps/train/halkyon_train_flutter/assets/whats_new/0.2.0.de.txt', ], }) => Commit(hash: 'abc', subject: subject, body: 'Build 2.', files: files); const versionOnly = ['-version: 0.1.0+1', '+version: 0.2.0+2']; test('a release commit, the version and what is new alone, needs no ' 'checks', () { expect(releaseCommitProblem(release(), versionOnly), isNull); expect( releaseCommitProblem( release( subject: 'chore(release): todo-v0.1.1', files: ['apps/todo/halkyon_todo_flutter/pubspec.yaml'], ), versionOnly, ), isNull, ); }); test('anything else does: another subject, another file, or the pubspec ' 'changed beyond its version', () { expect( releaseCommitProblem(release(subject: 'fix(train): a fix'), versionOnly), isNotNull, ); expect( releaseCommitProblem( release(subject: 'chore(release): train-v0.2.0 and more'), versionOnly, ), isNotNull, ); for (final file in [ 'apps/train/halkyon_train_flutter/lib/main.dart', 'pubspec.lock', 'apps/train/halkyon_train_flutter/assets/whats_new/notes.md', 'tool/pre-push', ]) { expect( releaseCommitProblem( release(files: [...release().files, file]), versionOnly, ), isNotNull, reason: file, ); } expect(releaseCommitProblem(release(files: []), versionOnly), isNotNull); expect( releaseCommitProblem(release(), [...versionOnly, '+ http: ^1.0.0']), isNotNull, ); }); test('a push needs no checks only when it brings commits, all of them ' 'release commits', () { expect(onlyReleaseCommits(const []), isFalse); expect(onlyReleaseCommits([(release(), versionOnly)]), isTrue); expect( onlyReleaseCommits([ (release(), versionOnly), (release(subject: 'feat(learn): more'), versionOnly), ]), isFalse, ); }); }