mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Clang-tidy: Fixed math on shard-id validator. (flutter/engine#37433)
Clang-tidy: Fixed math on shard-id validator.
This commit is contained in:
parent
2155c6ce00
commit
55cbf264b2
@ -120,7 +120,7 @@ class Options {
|
||||
}
|
||||
final String? shardIdString = argResults['shard-id'] as String?;
|
||||
final int? shardId = shardIdString == null ? null : int.parse(shardIdString);
|
||||
if (shardId != null && (shardId >= shardCommands.length || shardId < 0)) {
|
||||
if (shardId != null && (shardId > shardCommands.length || shardId < 0)) {
|
||||
return Options._error('Invalid shard-id value: $shardId.', errSink: errSink);
|
||||
}
|
||||
return Options._fromArgResults(
|
||||
|
||||
@ -2,12 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io' as io show File, Platform, stderr;
|
||||
import 'dart:io' as io show Directory, File, Platform, stderr;
|
||||
|
||||
import 'package:clang_tidy/clang_tidy.dart';
|
||||
import 'package:clang_tidy/src/command.dart';
|
||||
import 'package:clang_tidy/src/options.dart';
|
||||
import 'package:litetest/litetest.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:process_runner/process_runner.dart';
|
||||
|
||||
// Recorded locally from clang-tidy.
|
||||
@ -38,6 +39,18 @@ Suppressed 3474 warnings (3466 in non-user code, 8 NOLINT).
|
||||
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
|
||||
1 warning treated as error''';
|
||||
|
||||
void _withTempFile(String prefix, void Function(String path) func) {
|
||||
final String filePath =
|
||||
path.join(io.Directory.systemTemp.path, '$prefix-temp-file');
|
||||
final io.File file = io.File(filePath);
|
||||
file.createSync();
|
||||
try {
|
||||
func(file.path);
|
||||
} finally {
|
||||
file.deleteSync();
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> main(List<String> args) async {
|
||||
if (args.isEmpty) {
|
||||
io.stderr.writeln(
|
||||
@ -115,6 +128,37 @@ Future<int> main(List<String> args) async {
|
||||
));
|
||||
});
|
||||
|
||||
test('shard-id valid', () async {
|
||||
_withTempFile('shard-id-valid', (String path) {
|
||||
final Options options = Options.fromCommandLine( <String>[
|
||||
'--compile-commands=$path',
|
||||
'--shard-variants=variant',
|
||||
'--shard-id=1',
|
||||
],);
|
||||
expect(options.errorMessage, isNull);
|
||||
expect(options.shardId, equals(1));
|
||||
});
|
||||
});
|
||||
|
||||
test('shard-id invalid', () async {
|
||||
_withTempFile('shard-id-valid', (String path) {
|
||||
final StringBuffer errBuffer = StringBuffer();
|
||||
final Options options = Options.fromCommandLine(<String>[
|
||||
'--compile-commands=$path',
|
||||
'--shard-variants=variant',
|
||||
'--shard-id=2',
|
||||
], errSink: errBuffer);
|
||||
expect(options.errorMessage, isNotNull);
|
||||
expect(options.shardId, isNull);
|
||||
print('foo ${options.errorMessage}');
|
||||
expect(
|
||||
options.errorMessage,
|
||||
contains(
|
||||
'Invalid shard-id value',
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
test('Error when --compile-commands path does not exist', () async {
|
||||
final StringBuffer outBuffer = StringBuffer();
|
||||
final StringBuffer errBuffer = StringBuffer();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user