[flutter_tools] Update roll_dev.dart (#59215)

This commit is contained in:
Christopher Fujino
2020-06-16 09:30:04 -07:00
committed by GitHub
parent e66a5cf55d
commit 807b60250a
3 changed files with 247 additions and 65 deletions

View File

@@ -14,6 +14,8 @@ void main() {
const String level = 'z';
const String commit = 'abcde012345';
const String origin = 'upstream';
const String lastVersion = '1.2.0-0.0.pre';
const String nextVersion = '1.2.0-1.0.pre';
FakeArgResults fakeArgResults;
MockGit mockGit;
@@ -26,8 +28,6 @@ void main() {
level: level,
commit: commit,
origin: origin,
justPrint: false,
autoApprove: true,
help: true,
);
expect(
@@ -42,12 +42,9 @@ void main() {
test('returns false if level not provided', () {
fakeArgResults = FakeArgResults(
level: level,
level: null,
commit: commit,
origin: origin,
justPrint: false,
autoApprove: true,
help: true,
);
expect(
run(
@@ -62,11 +59,8 @@ void main() {
test('returns false if commit not provided', () {
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
commit: null,
origin: origin,
justPrint: false,
autoApprove: true,
help: true,
);
expect(
run(
@@ -79,28 +73,22 @@ void main() {
});
test('throws exception if upstream remote wrong', () {
when(mockGit.getOutput('remote get-url $origin', any)).thenReturn('wrong-remote');
const String remote = 'wrong-remote';
when(mockGit.getOutput('remote get-url $origin', any)).thenReturn(remote);
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
justPrint: false,
autoApprove: true,
help: false,
);
Exception exception;
try {
run(
const String errorMessage = 'The remote named $origin is set to $remote, when $kUpstreamRemote was expected.';
expect(
() => run(
usage: usage,
argResults: fakeArgResults,
git: mockGit,
);
} on Exception catch (e) {
exception = e;
}
const String pattern = r'The current directory is not a Flutter '
'repository checkout with a correctly configured upstream remote.';
expect(exception?.toString(), contains(pattern));
),
throwsExceptionWith(errorMessage),
);
});
test('throws exception if git checkout not clean', () {
@@ -112,9 +100,6 @@ void main() {
level: level,
commit: commit,
origin: origin,
justPrint: false,
autoApprove: true,
help: false,
);
Exception exception;
try {
@@ -132,20 +117,22 @@ void main() {
expect(exception?.toString(), contains(pattern));
});
test('does not tag if --just-print is specified', () {
test('does not reset or tag if --just-print is specified', () {
when(mockGit.getOutput('remote get-url $origin', any)).thenReturn(kUpstreamRemote);
when(mockGit.getOutput('status --porcelain', any)).thenReturn('');
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn('1.2.3-0.0.pre');
)).thenReturn(lastVersion);
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn('zxy321');
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
justPrint: true,
autoApprove: true,
help: false,
);
expect(run(
usage: usage,
@@ -153,25 +140,141 @@ void main() {
git: mockGit,
), false);
verify(mockGit.run('fetch $origin', any));
verify(mockGit.run('reset $commit --hard', any));
verifyNever(mockGit.run('reset $commit --hard', any));
verifyNever(mockGit.getOutput('rev-parse HEAD', any));
});
test('successfully tags and publishes release', () {
test('exits with exception if --skip-tagging is provided but commit isn\'t '
'already tagged', () {
when(mockGit.getOutput('remote get-url $origin', any)).thenReturn(kUpstreamRemote);
when(mockGit.getOutput('status --porcelain', any)).thenReturn('');
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn('1.2.3-0.0.pre');
)).thenReturn(lastVersion);
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn('zxy321');
const String exceptionMessage = 'Failed to verify $commit is already '
'tagged. You can only use the flag `$kSkipTagging` if the commit has '
'already been tagged.';
when(mockGit.run(
'describe --exact-match --tags $commit',
any,
)).thenThrow(Exception(exceptionMessage));
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
skipTagging: true,
);
expect(
() => run(
usage: usage,
argResults: fakeArgResults,
git: mockGit,
),
throwsExceptionWith(exceptionMessage),
);
verify(mockGit.run('fetch $origin', any));
verifyNever(mockGit.run('reset $commit --hard', any));
verifyNever(mockGit.getOutput('rev-parse HEAD', any));
});
test('throws exception if desired commit is already tip of dev branch', () {
when(mockGit.getOutput('remote get-url $origin', any)).thenReturn(kUpstreamRemote);
when(mockGit.getOutput('status --porcelain', any)).thenReturn('');
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn(lastVersion);
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn(commit);
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
justPrint: true,
);
expect(
() => run(
usage: usage,
argResults: fakeArgResults,
git: mockGit,
),
throwsExceptionWith('is already on the dev branch as'),
);
verify(mockGit.run('fetch $origin', any));
verifyNever(mockGit.run('reset $commit --hard', any));
verifyNever(mockGit.getOutput('rev-parse HEAD', any));
});
test('does not tag if last release is not direct ancestor of desired '
'commit and --force not supplied', () {
when(mockGit.getOutput('remote get-url $origin', any))
.thenReturn(kUpstreamRemote);
when(mockGit.getOutput('status --porcelain', any))
.thenReturn('');
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn(lastVersion);
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn('zxy321');
when(mockGit.run('merge-base --is-ancestor $lastVersion $commit', any))
.thenThrow(Exception(
'Failed to verify $lastVersion is a direct ancestor of $commit. The '
'flag `--force` is required to force push a new release past a '
'cherry-pick',
));
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
);
const String errorMessage = 'Failed to verify $lastVersion is a direct '
'ancestor of $commit. The flag `--force` is required to force push a '
'new release past a cherry-pick';
expect(
() => run(
argResults: fakeArgResults,
git: mockGit,
usage: usage,
),
throwsExceptionWith(errorMessage),
);
verify(mockGit.run('fetch $origin', any));
verifyNever(mockGit.run('reset $commit --hard', any));
verifyNever(mockGit.run('push $origin HEAD:dev', any));
verifyNever(mockGit.run('tag $nextVersion', any));
});
test('does not tag but updates branch if --skip-tagging provided', () {
when(mockGit.getOutput('remote get-url $origin', any))
.thenReturn(kUpstreamRemote);
when(mockGit.getOutput('status --porcelain', any))
.thenReturn('');
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn(lastVersion);
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn('zxy321');
when(mockGit.getOutput('rev-parse HEAD', any)).thenReturn(commit);
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
justPrint: false,
autoApprove: true,
help: false,
skipTagging: true,
);
expect(run(
usage: usage,
@@ -180,7 +283,39 @@ void main() {
), true);
verify(mockGit.run('fetch $origin', any));
verify(mockGit.run('reset $commit --hard', any));
verify(mockGit.run('tag 1.2.0-1.0.pre', any));
verifyNever(mockGit.run('tag $nextVersion', any));
verifyNever(mockGit.run('push $origin $nextVersion', any));
verify(mockGit.run('push $origin HEAD:dev', any));
});
test('successfully tags and publishes release', () {
when(mockGit.getOutput('remote get-url $origin', any))
.thenReturn(kUpstreamRemote);
when(mockGit.getOutput('status --porcelain', any))
.thenReturn('');
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn('1.2.0-0.0.pre');
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn('zxy321');
when(mockGit.getOutput('rev-parse HEAD', any)).thenReturn(commit);
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
);
expect(run(
usage: usage,
argResults: fakeArgResults,
git: mockGit,
), true);
verify(mockGit.run('fetch $origin', any));
verify(mockGit.run('reset $commit --hard', any));
verify(mockGit.run('tag $nextVersion', any));
verify(mockGit.run('push $origin $nextVersion', any));
verify(mockGit.run('push $origin HEAD:dev', any));
});
@@ -190,15 +325,16 @@ void main() {
when(mockGit.getOutput(
'describe --match *.*.*-*.*.pre --exact-match --tags refs/remotes/$origin/dev',
any,
)).thenReturn('1.2.3-0.0.pre');
)).thenReturn(lastVersion);
when(mockGit.getOutput(
'rev-parse $lastVersion',
any,
)).thenReturn('zxy321');
when(mockGit.getOutput('rev-parse HEAD', any)).thenReturn(commit);
fakeArgResults = FakeArgResults(
level: level,
commit: commit,
origin: origin,
justPrint: false,
autoApprove: true,
help: false,
force: true,
);
expect(run(
@@ -208,7 +344,7 @@ void main() {
), true);
verify(mockGit.run('fetch $origin', any));
verify(mockGit.run('reset $commit --hard', any));
verify(mockGit.run('tag 1.2.0-1.0.pre', any));
verify(mockGit.run('tag $nextVersion', any));
verify(mockGit.run('push --force $origin HEAD:dev', any));
});
});
@@ -268,14 +404,14 @@ void main() {
String version = '1.0.0-0.0.pre-1-g$hash';
expect(
() => incrementLevel(version, level),
throwsException,
throwsExceptionWith('Git reported the latest version as "$version"'),
reason: 'should throw because $version should be an exact tag',
);
version = '1.2.3';
expect(
() => incrementLevel(version, level),
throwsException,
throwsExceptionWith('Git reported the latest version as "$version"'),
reason: 'should throw because $version should be a dev tag, not stable.'
);
@@ -283,7 +419,7 @@ void main() {
level = 'q';
expect(
() => incrementLevel(version, level),
throwsException,
throwsExceptionWith('Git reported the latest version as "$version"'),
reason: 'should throw because $level is unsupported',
);
});
@@ -329,15 +465,26 @@ void main() {
});
}
Matcher throwsExceptionWith(String messageSubString) {
return throwsA(
isA<Exception>().having(
(Exception e) => e.toString(),
'description',
contains(messageSubString),
),
);
}
class FakeArgResults implements ArgResults {
FakeArgResults({
String level,
String commit,
String origin,
bool justPrint,
bool autoApprove,
bool help,
bool justPrint = false,
bool autoApprove = true, // so we don't have to mock stdin
bool help = false,
bool force = false,
bool skipTagging = false,
}) : _parsedArgs = <String, dynamic>{
'increment': level,
'commit': commit,
@@ -346,6 +493,7 @@ class FakeArgResults implements ArgResults {
'yes': autoApprove,
'help': help,
'force': force,
'skip-tagging': skipTagging,
};
@override