diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart index f2c6d79b82ad..57b4ef2475fa 100644 --- a/pkg/analyzer_cli/lib/src/build_mode.dart +++ b/pkg/analyzer_cli/lib/src/build_mode.dart @@ -547,6 +547,10 @@ class BuildMode with HasContextMixin { } void _setAnalysisDriverAnalysisContext(String rootPath) { + if (rootPath == null) { + return; + } + var apiContextRoots = api.ContextLocator( resourceProvider: resourceProvider, ).locateRoots( diff --git a/pkg/analyzer_cli/test/driver_test.dart b/pkg/analyzer_cli/test/driver_test.dart index f78dc97061b2..bcb5cec9af86 100644 --- a/pkg/analyzer_cli/test/driver_test.dart +++ b/pkg/analyzer_cli/test/driver_test.dart @@ -38,6 +38,23 @@ void main() { } class AbstractBuildModeTest extends BaseTest { + List get _sdkSummaryArguments { + var sdkPath = path.dirname( + path.dirname( + Platform.resolvedExecutable, + ), + ); + + var dartSdkSummaryPath = path.join( + sdkPath, + 'lib', + '_internal', + 'strong.sum', + ); + + return ['--dart-sdk-summary', dartSdkSummaryPath]; + } + Future _doDrive( String filePath, { String sourceArgument, @@ -54,24 +71,7 @@ class AbstractBuildModeTest extends BaseTest { args.add('--build-mode'); args.add('--format=machine'); - { - var sdkPath = path.dirname( - path.dirname( - Platform.resolvedExecutable, - ), - ); - - var dartSdkSummaryPath = path.join( - sdkPath, - 'lib', - '_internal', - 'strong.sum', - ); - - args.add('--dart-sdk-summary'); - args.add(dartSdkSummaryPath); - } - + args.addAll(_sdkSummaryArguments); args.addAll(additionalArgs); if (sourceArgument == null) { @@ -587,6 +587,25 @@ var b = new B(); expect(exitCode, isNot(0)); } + Future test_noInputs() async { + await withTempDirAsync((tempDir) async { + var outputPath = path.join(tempDir, 'test.sum'); + + await driveMany([], args: [ + '--build-mode', + '--format=machine', + ..._sdkSummaryArguments, + '--build-summary-only', + '--build-summary-output=$outputPath', + ]); + + var output = File(outputPath); + expect(output.existsSync(), isTrue); + + expect(exitCode, 0); + }); + } + Future test_noStatistics() async { await _doDrive(path.join('data', 'test_file.dart')); // Should not print statistics summary.