Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: pkg/analyzer_cli/test/driver_test.dart

Issue 1825283006: Clean up analyzer_cli build mode tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer_cli.test.driver; 5 library analyzer_cli.test.driver;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/plugin/options.dart'; 9 import 'package:analyzer/plugin/options.dart';
10 import 'package:analyzer/source/analysis_options_provider.dart'; 10 import 'package:analyzer/source/analysis_options_provider.dart';
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Should not be made fatal by `--fatal-warnings`. 279 // Should not be made fatal by `--fatal-warnings`.
280 expect(outSink.toString(), 280 expect(outSink.toString(),
281 contains("[warning] The function 'baz' is not defined")); 281 contains("[warning] The function 'baz' is not defined"));
282 expect(outSink.toString(), contains("1 error and 1 warning found.")); 282 expect(outSink.toString(), contains("1 error and 1 warning found."));
283 }); 283 });
284 }); 284 });
285 }); 285 });
286 286
287 group('build-mode', () { 287 group('build-mode', () {
288 // Shared driver command. 288 // Shared driver command.
289 var testFilePath = path.join( 289 void doDrive(String filePath, {List<String> additionalArgs: const []}) {
290 path.dirname(Platform.script.toFilePath()), 'data', 'test_file.dart'); 290 drive('file:///test_file.dart|$filePath',
291 var doDrive = () => drive('file:///test_file.dart|$testFilePath', 291 args: [
292 args: [ 292 '--dart-sdk',
293 '--dart-sdk', 293 findSdkDirForSummaries(),
294 findSdkDirForSummaries(), 294 '--build-mode',
295 '--build-mode', 295 '--machine'
296 '--machine' 296 ]..addAll(additionalArgs),
297 ], 297 options: 'data/options_tests_project/.analysis_options');
298 options: 'data/options_tests_project/.analysis_options'); 298 }
299 299
300 test('no stats', () { 300 test('no stats', () {
301 doDrive(); 301 doDrive('data/test_file.dart');
302 // Should not print stat summary. 302 // Should not print stat summary.
303 expect(outSink.toString(), isEmpty); 303 expect(outSink.toString(), isEmpty);
304 expect(errorSink.toString(), isEmpty); 304 expect(errorSink.toString(), isEmpty);
305 expect(exitCode, 0); 305 expect(exitCode, 0);
306 }); 306 });
307
308 test(
309 'Fails if file not found, even when --build-suppress-exit-code is give n',
310 () {
311 doDrive('data/non_existent_file.dart',
312 additionalArgs: ['--build-suppress-exit-code']);
313 expect(exitCode, isNot(0));
314 });
315
316 test('Fails if there are errors', () {
317 doDrive('data/file_with_error.dart');
318 expect(exitCode, isNot(0));
319 });
320
321 test(
322 'Succeeds if there are errors, when --build-suppress-exit-code is give n',
323 () {
324 doDrive('data/file_with_error.dart',
325 additionalArgs: ['--build-suppress-exit-code']);
326 expect(exitCode, 0);
327 });
307 }); 328 });
308 329
309 //TODO(pq): fix to be bot-friendly (sdk#25258). 330 //TODO(pq): fix to be bot-friendly (sdk#25258).
310 // group('in temp directory', () { 331 // group('in temp directory', () {
311 // Directory savedCurrentDirectory; 332 // Directory savedCurrentDirectory;
312 // Directory tempDir; 333 // Directory tempDir;
313 // setUp(() { 334 // setUp(() {
314 // // Call base setUp. 335 // // Call base setUp.
315 // _setUp(); 336 // _setUp();
316 // savedCurrentDirectory = Directory.current; 337 // savedCurrentDirectory = Directory.current;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 392 }
372 393
373 const emptyOptionsFile = 'data/empty_options.yaml'; 394 const emptyOptionsFile = 'data/empty_options.yaml';
374 395
375 /// Shared driver. 396 /// Shared driver.
376 Driver driver; 397 Driver driver;
377 398
378 List<ErrorProcessor> get processors => 399 List<ErrorProcessor> get processors =>
379 driver.context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); 400 driver.context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
380 401
402 /// Convert a file specification from a relative path to an absolute path.
403 /// Handles the case where the file specification is of the form "$uri|$path".
404 String adjustFileSpec(String fileSpec) {
405 int uriPrefixLength = fileSpec.indexOf('|') + 1;
406 String uriPrefix = fileSpec.substring(0, uriPrefixLength);
407 String relativePath = fileSpec.substring(uriPrefixLength);
408 return '$uriPrefix${path.join(testDirectory, relativePath)}';
409 }
410
381 /// Start a driver for the given [source], optionally providing additional 411 /// Start a driver for the given [source], optionally providing additional
382 /// [args] and an [options] file path. The value of [options] defaults to 412 /// [args] and an [options] file path. The value of [options] defaults to
383 /// an empty options file to avoid unwanted configuration from an otherwise 413 /// an empty options file to avoid unwanted configuration from an otherwise
384 /// discovered options file. 414 /// discovered options file.
385 void drive(String source, 415 void drive(String source,
386 {String options: emptyOptionsFile, List<String> args: const <String>[]}) { 416 {String options: emptyOptionsFile, List<String> args: const <String>[]}) {
387 driver = new Driver(); 417 driver = new Driver();
388 var cmd = [ 418 var cmd = [
389 '--options', 419 '--options',
390 path.join(testDirectory, options), 420 path.join(testDirectory, options),
391 path.join(testDirectory, source) 421 adjustFileSpec(source)
392 ]..addAll(args); 422 ]..addAll(args);
393 driver.start(cmd); 423 driver.start(cmd);
394 } 424 }
395 425
396 /// Try to find a appropriate directory to pass to "--dart-sdk" that will 426 /// Try to find a appropriate directory to pass to "--dart-sdk" that will
397 /// allow summaries to be found. 427 /// allow summaries to be found.
398 String findSdkDirForSummaries() { 428 String findSdkDirForSummaries() {
399 Set<String> triedDirectories = new Set<String>(); 429 Set<String> triedDirectories = new Set<String>();
400 bool isSuitable(String sdkDir) { 430 bool isSuitable(String sdkDir) {
401 triedDirectories.add(sdkDir); 431 triedDirectories.add(sdkDir);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 this.options = options; 505 this.options = options;
476 } 506 }
477 } 507 }
478 508
479 class TestSource implements Source { 509 class TestSource implements Source {
480 TestSource(); 510 TestSource();
481 511
482 @override 512 @override
483 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 513 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
484 } 514 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698