Skip to content

Commit 519858c

Browse files
authored
Add tests for the verify cli command (#7797)
1 parent 2f35dc9 commit 519858c

File tree

2 files changed

+91
-34
lines changed

2 files changed

+91
-34
lines changed

tool/plugin/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
git: ^2.0.0
1414
markdown: ^7.1.1
1515
path: ^1.8.0
16+
string_validator: 1.1.0
1617

1718
dev_dependencies:
1819
lints: ^5.0.0

tool/plugin/test/plugin_test.dart

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'dart:io';
77
import 'package:plugin_tool/plugin.dart';
88
import 'package:plugin_tool/runner.dart';
99
import 'package:plugin_tool/util.dart';
10+
import 'package:plugin_tool/verify.dart';
11+
import 'package:string_validator/string_validator.dart' as validator;
1012
import 'package:test/test.dart';
1113

1214
void main() {
@@ -26,42 +28,76 @@ void main() {
2628
test('generate', () {
2729
expect(GenerateCommand(BuildCommandRunner()).name, "generate");
2830
});
31+
32+
test('verify', () {
33+
expect(VerifyCommand(BuildCommandRunner()).name, "verify");
34+
});
2935
});
3036

3137
group("spec", () {
38+
/// This method has assertions which can be made for all commands in this
39+
/// test group.
40+
void buildSpecAssertions(BuildCommandRunner runner, String command) {
41+
var specs = (runner.commands[command] as ProductCommand).specs;
42+
expect(specs, isList);
43+
expect(specs, isNotEmpty);
44+
45+
// channel should be set to stable in the product-matrix.json
46+
for (String channel in specs.map((spec) => spec.channel).toList()) {
47+
expect(channel, anyOf('stable'));
48+
}
49+
50+
// name should be set to stable in the product-matrix.json
51+
for (String name in specs.map((spec) => spec.name).toList()) {
52+
expect(name, isNotEmpty);
53+
expect(name.length, 6);
54+
expect(name, validator.isFloat);
55+
}
56+
57+
// ideaProduct should be android-studio or IC
58+
for (String ideaProduct
59+
in specs.map((spec) => spec.ideaProduct).toList()) {
60+
expect(ideaProduct, anyOf('android-studio', 'IC'));
61+
}
62+
63+
// sinceBuild should be in the form of '243'
64+
for (String sinceBuild in specs.map((spec) => spec.sinceBuild).toList()) {
65+
expect(sinceBuild.length, 3);
66+
expect(sinceBuild, validator.isNumeric);
67+
}
68+
69+
// untilBuild should be in the form of '243.*'
70+
for (String untilBuild in specs.map((spec) => spec.untilBuild).toList()) {
71+
expect(untilBuild.length, 5);
72+
expect(untilBuild.substring(0, 2), validator.isNumeric);
73+
}
74+
}
75+
3276
test('build', () async {
3377
var runner = makeTestRunner();
3478
await runner.run(["-r=19", "-d../..", "make"]).whenComplete(() {
35-
var specs = (runner.commands['make'] as ProductCommand).specs;
36-
expect(specs, isNotNull);
37-
expect(
38-
specs.map((spec) => spec.ideaProduct).toList(),
39-
orderedEquals(
40-
['android-studio', 'android-studio', 'android-studio', 'IC']));
79+
buildSpecAssertions(runner, "make");
4180
});
4281
});
4382

4483
test('test', () async {
4584
var runner = makeTestRunner();
4685
await runner.run(["-r=19", "-d../..", "test"]).whenComplete(() {
47-
var specs = (runner.commands['test'] as ProductCommand).specs;
48-
expect(specs, isNotNull);
49-
expect(
50-
specs.map((spec) => spec.ideaProduct).toList(),
51-
orderedEquals(
52-
['android-studio', 'android-studio', 'android-studio', 'IC']));
86+
buildSpecAssertions(runner, "test");
5387
});
5488
});
5589

5690
test('deploy', () async {
5791
var runner = makeTestRunner();
5892
await runner.run(["-r19", "-d../..", "deploy"]).whenComplete(() {
59-
var specs = (runner.commands['deploy'] as ProductCommand).specs;
60-
expect(specs, isNotNull);
61-
expect(
62-
specs.map((spec) => spec.ideaProduct).toList(),
63-
orderedEquals(
64-
['android-studio', 'android-studio', 'android-studio', 'IC']));
93+
buildSpecAssertions(runner, "deploy");
94+
});
95+
});
96+
97+
test('verify', () async {
98+
var runner = makeTestRunner();
99+
await runner.run(["-r19", "-d../..", "verify"]).whenComplete(() {
100+
buildSpecAssertions(runner, "verify");
65101
});
66102
});
67103
});
@@ -159,7 +195,16 @@ void main() {
159195

160196
test('only-version', () async {
161197
ProductCommand command =
162-
makeTestRunner().commands['make'] as ProductCommand;
198+
makeTestRunner().commands['make'] as ProductCommand;
199+
var results = command.argParser.parse(['--only-version=2023.1']);
200+
expect(results['only-version'], '2023.1');
201+
});
202+
});
203+
204+
group('verify', () {
205+
test('only-version', () async {
206+
ProductCommand command =
207+
makeTestRunner().commands['verify'] as ProductCommand;
163208
var results = command.argParser.parse(['--only-version=2023.1']);
164209
expect(results['only-version'], '2023.1');
165210
});
@@ -216,19 +261,10 @@ BuildCommandRunner makeTestRunner() {
216261
runner.addCommand(TestTestCommand(runner));
217262
runner.addCommand(TestDeployCommand(runner));
218263
runner.addCommand(TestGenCommand(runner));
264+
runner.addCommand(TestVerifyCommand(runner));
219265
return runner;
220266
}
221267

222-
class TestMakeCommand extends GradleBuildCommand {
223-
TestMakeCommand(super.runner);
224-
225-
@override
226-
bool get isTesting => true;
227-
228-
@override
229-
Future<int> doit() async => Future(() => 0);
230-
}
231-
232268
class TestDeployCommand extends DeployCommand {
233269
List<String> paths = <String>[];
234270
List<String> plugins = <String>[];
@@ -238,16 +274,16 @@ class TestDeployCommand extends DeployCommand {
238274
@override
239275
bool get isTesting => true;
240276

277+
@override
278+
void changeDirectory(Directory dir) {}
279+
241280
String readTokenFile() {
242281
return "token";
243282
}
244283

245284
@override
246-
void changeDirectory(Directory dir) {}
247-
248-
@override
249-
Future<int> upload(String filePath, String pluginNumber, String token,
250-
String channel) {
285+
Future<int> upload(
286+
String filePath, String pluginNumber, String token, String channel) {
251287
paths.add(filePath);
252288
plugins.add(pluginNumber);
253289
return Future(() => 0);
@@ -264,6 +300,16 @@ class TestGenCommand extends GenerateCommand {
264300
Future<int> doit() async => Future(() => 0);
265301
}
266302

303+
class TestMakeCommand extends GradleBuildCommand {
304+
TestMakeCommand(super.runner);
305+
306+
@override
307+
bool get isTesting => true;
308+
309+
@override
310+
Future<int> doit() async => Future(() => 0);
311+
}
312+
267313
class TestTestCommand extends TestCommand {
268314
TestTestCommand(super.runner);
269315

@@ -273,3 +319,13 @@ class TestTestCommand extends TestCommand {
273319
@override
274320
Future<int> doit() async => Future(() => 0);
275321
}
322+
323+
class TestVerifyCommand extends VerifyCommand {
324+
TestVerifyCommand(super.runner);
325+
326+
@override
327+
bool get isTesting => true;
328+
329+
@override
330+
Future<int> doit() async => Future(() => 0);
331+
}

0 commit comments

Comments
 (0)