|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 |
| -import 'dart:io' as io show File, Platform, stderr; |
| 5 | +import 'dart:io' as io show Directory, File, Platform, stderr; |
6 | 6 |
|
7 | 7 | import 'package:clang_tidy/clang_tidy.dart';
|
8 | 8 | import 'package:clang_tidy/src/command.dart';
|
9 | 9 | import 'package:clang_tidy/src/options.dart';
|
10 | 10 | import 'package:litetest/litetest.dart';
|
| 11 | +import 'package:path/path.dart' as path; |
11 | 12 | import 'package:process_runner/process_runner.dart';
|
12 | 13 |
|
13 | 14 | // Recorded locally from clang-tidy.
|
@@ -38,6 +39,18 @@ Suppressed 3474 warnings (3466 in non-user code, 8 NOLINT).
|
38 | 39 | Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
|
39 | 40 | 1 warning treated as error''';
|
40 | 41 |
|
| 42 | +void _withTempFile(String prefix, void Function(String path) func) { |
| 43 | + final String filePath = |
| 44 | + path.join(io.Directory.systemTemp.path, '$prefix-temp-file'); |
| 45 | + final io.File file = io.File(filePath); |
| 46 | + file.createSync(); |
| 47 | + try { |
| 48 | + func(file.path); |
| 49 | + } finally { |
| 50 | + file.deleteSync(); |
| 51 | + } |
| 52 | +} |
| 53 | + |
41 | 54 | Future<int> main(List<String> args) async {
|
42 | 55 | if (args.isEmpty) {
|
43 | 56 | io.stderr.writeln(
|
@@ -115,6 +128,37 @@ Future<int> main(List<String> args) async {
|
115 | 128 | ));
|
116 | 129 | });
|
117 | 130 |
|
| 131 | + test('shard-id valid', () async { |
| 132 | + _withTempFile('shard-id-valid', (String path) { |
| 133 | + final Options options = Options.fromCommandLine( <String>[ |
| 134 | + '--compile-commands=$path', |
| 135 | + '--shard-variants=variant', |
| 136 | + '--shard-id=1', |
| 137 | + ],); |
| 138 | + expect(options.errorMessage, isNull); |
| 139 | + expect(options.shardId, equals(1)); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + test('shard-id invalid', () async { |
| 144 | + _withTempFile('shard-id-valid', (String path) { |
| 145 | + final StringBuffer errBuffer = StringBuffer(); |
| 146 | + final Options options = Options.fromCommandLine(<String>[ |
| 147 | + '--compile-commands=$path', |
| 148 | + '--shard-variants=variant', |
| 149 | + '--shard-id=2', |
| 150 | + ], errSink: errBuffer); |
| 151 | + expect(options.errorMessage, isNotNull); |
| 152 | + expect(options.shardId, isNull); |
| 153 | + print('foo ${options.errorMessage}'); |
| 154 | + expect( |
| 155 | + options.errorMessage, |
| 156 | + contains( |
| 157 | + 'Invalid shard-id value', |
| 158 | + )); |
| 159 | + }); |
| 160 | + }); |
| 161 | + |
118 | 162 | test('Error when --compile-commands path does not exist', () async {
|
119 | 163 | final StringBuffer outBuffer = StringBuffer();
|
120 | 164 | final StringBuffer errBuffer = StringBuffer();
|
|
0 commit comments