mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
WIP Commits separated as follows: - Update lints in analysis_options files - Run `dart fix --apply` - Clean up leftover analysis issues - Run `dart format .` in the right places. Local analysis and testing passes. Checking CI now. Part of https://github.com/flutter/flutter/issues/178827 - Adoption of flutter_lints in examples/api coming in a separate change (cc @loic-sharma) ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
234 lines
7.6 KiB
Dart
234 lines
7.6 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:file/memory.dart';
|
|
import 'package:flutter_tools/src/artifacts.dart';
|
|
import 'package:flutter_tools/src/base/io.dart';
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
|
import 'package:flutter_tools/src/build_info.dart';
|
|
import 'package:flutter_tools/src/compile.dart';
|
|
import 'package:flutter_tools/src/convert.dart';
|
|
import 'package:package_config/package_config.dart';
|
|
import 'package:process/process.dart';
|
|
import 'package:test/fake.dart';
|
|
|
|
import '../src/common.dart';
|
|
import '../src/fake_process_manager.dart';
|
|
import '../src/fakes.dart';
|
|
|
|
void main() {
|
|
late FakeProcessManager processManager;
|
|
late ResidentCompiler generator;
|
|
late MemoryIOSink frontendServerStdIn;
|
|
late StreamController<String> stdErrStreamController;
|
|
late BufferLogger testLogger;
|
|
late MemoryFileSystem fileSystem;
|
|
|
|
setUp(() {
|
|
testLogger = BufferLogger.test();
|
|
processManager = FakeProcessManager();
|
|
frontendServerStdIn = MemoryIOSink();
|
|
fileSystem = MemoryFileSystem.test();
|
|
generator = ResidentCompiler(
|
|
'sdkroot',
|
|
buildMode: BuildMode.debug,
|
|
artifacts: Artifacts.test(),
|
|
processManager: processManager,
|
|
logger: testLogger,
|
|
platform: FakePlatform(),
|
|
fileSystem: fileSystem,
|
|
shutdownHooks: FakeShutdownHooks(),
|
|
);
|
|
|
|
stdErrStreamController = StreamController<String>();
|
|
processManager.process.stdin = frontendServerStdIn;
|
|
processManager.process.stderr = stdErrStreamController.stream.transform(utf8.encoder);
|
|
});
|
|
|
|
testWithoutContext('compile expression fails if not previously compiled', () async {
|
|
final CompilerOutput? result = await generator.compileExpression(
|
|
'2+2',
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
false,
|
|
);
|
|
|
|
expect(result, isNull);
|
|
});
|
|
|
|
testWithoutContext('compile expression can compile single expression', () async {
|
|
final compileResponseCompleter = Completer<List<int>>();
|
|
final compileExpressionResponseCompleter = Completer<List<int>>();
|
|
fileSystem.file('/path/to/main.dart.dill')
|
|
..createSync(recursive: true)
|
|
..writeAsBytesSync(<int>[1, 2, 3, 4]);
|
|
|
|
processManager.process.stdout = Stream<List<int>>.fromFutures(<Future<List<int>>>[
|
|
compileResponseCompleter.future,
|
|
compileExpressionResponseCompleter.future,
|
|
]);
|
|
compileResponseCompleter.complete(
|
|
Future<List<int>>.value(
|
|
utf8.encode('result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n'),
|
|
),
|
|
);
|
|
|
|
await generator
|
|
.recompile(
|
|
Uri.file('/path/to/main.dart'),
|
|
null,
|
|
/* invalidatedFiles */
|
|
outputPath: '/build/',
|
|
packageConfig: PackageConfig.empty,
|
|
projectRootPath: '',
|
|
fs: fileSystem,
|
|
)
|
|
.then((CompilerOutput? output) {
|
|
expect(frontendServerStdIn.getAndClear(), 'compile file:///path/to/main.dart\n');
|
|
expect(testLogger.errorText, equals('line1\nline2\n'));
|
|
expect(output!.outputFilename, equals('/path/to/main.dart.dill'));
|
|
|
|
compileExpressionResponseCompleter.complete(
|
|
Future<List<int>>.value(
|
|
utf8.encode(
|
|
'result def\nline1\nline2\ndef\ndef /path/to/main.dart.dill.incremental 0\n',
|
|
),
|
|
),
|
|
);
|
|
generator
|
|
.compileExpression('2+2', null, null, null, null, null, null, null, null, false)
|
|
.then((CompilerOutput? outputExpression) {
|
|
expect(outputExpression, isNotNull);
|
|
expect(outputExpression!.expressionData, <int>[1, 2, 3, 4]);
|
|
});
|
|
});
|
|
});
|
|
|
|
testWithoutContext('compile expressions without awaiting', () async {
|
|
final compileResponseCompleter = Completer<List<int>>();
|
|
final compileExpressionResponseCompleter1 = Completer<List<int>>();
|
|
final compileExpressionResponseCompleter2 = Completer<List<int>>();
|
|
|
|
processManager.process.stdout = Stream<List<int>>.fromFutures(<Future<List<int>>>[
|
|
compileResponseCompleter.future,
|
|
compileExpressionResponseCompleter1.future,
|
|
compileExpressionResponseCompleter2.future,
|
|
]);
|
|
|
|
// The test manages timing via completers.
|
|
unawaited(
|
|
generator
|
|
.recompile(
|
|
Uri.parse('/path/to/main.dart'),
|
|
null,
|
|
/* invalidatedFiles */
|
|
outputPath: '/build/',
|
|
packageConfig: PackageConfig.empty,
|
|
projectRootPath: '',
|
|
fs: MemoryFileSystem(),
|
|
)
|
|
.then((CompilerOutput? outputCompile) {
|
|
expect(testLogger.errorText, equals('line1\nline2\n'));
|
|
expect(outputCompile!.outputFilename, equals('/path/to/main.dart.dill'));
|
|
|
|
fileSystem.file('/path/to/main.dart.dill.incremental')
|
|
..createSync(recursive: true)
|
|
..writeAsBytesSync(<int>[0, 1, 2, 3]);
|
|
compileExpressionResponseCompleter1.complete(
|
|
Future<List<int>>.value(
|
|
utf8.encode(
|
|
'result def\nline1\nline2\ndef /path/to/main.dart.dill.incremental 0\n',
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
|
|
// The test manages timing via completers.
|
|
final lastExpressionCompleted = Completer<bool>();
|
|
unawaited(
|
|
generator
|
|
.compileExpression('0+1', null, null, null, null, null, null, null, null, false)
|
|
.then((CompilerOutput? outputExpression) {
|
|
expect(outputExpression, isNotNull);
|
|
expect(outputExpression!.expressionData, <int>[0, 1, 2, 3]);
|
|
|
|
fileSystem.file('/path/to/main.dart.dill.incremental')
|
|
..createSync(recursive: true)
|
|
..writeAsBytesSync(<int>[4, 5, 6, 7]);
|
|
compileExpressionResponseCompleter2.complete(
|
|
Future<List<int>>.value(
|
|
utf8.encode(
|
|
'result def\nline1\nline2\ndef /path/to/main.dart.dill.incremental 0\n',
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
|
|
// The test manages timing via completers.
|
|
unawaited(
|
|
generator
|
|
.compileExpression('1+1', null, null, null, null, null, null, null, null, false)
|
|
.then((CompilerOutput? outputExpression) {
|
|
expect(outputExpression, isNotNull);
|
|
expect(outputExpression!.expressionData, <int>[4, 5, 6, 7]);
|
|
lastExpressionCompleted.complete(true);
|
|
}),
|
|
);
|
|
|
|
compileResponseCompleter.complete(
|
|
Future<List<int>>.value(
|
|
utf8.encode('result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n'),
|
|
),
|
|
);
|
|
|
|
expect(await lastExpressionCompleted.future, isTrue);
|
|
});
|
|
}
|
|
|
|
class FakeProcess extends Fake implements Process {
|
|
@override
|
|
Stream<List<int>> stdout = const Stream<List<int>>.empty();
|
|
|
|
@override
|
|
Stream<List<int>> stderr = const Stream<List<int>>.empty();
|
|
|
|
@override
|
|
IOSink stdin = IOSink(StreamController<List<int>>().sink);
|
|
|
|
@override
|
|
Future<int> get exitCode => Completer<int>().future;
|
|
}
|
|
|
|
class FakeProcessManager extends Fake implements ProcessManager {
|
|
final process = FakeProcess();
|
|
|
|
@override
|
|
bool canRun(dynamic executable, {String? workingDirectory}) {
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future<Process> start(
|
|
List<Object> command, {
|
|
String? workingDirectory,
|
|
Map<String, String>? environment,
|
|
bool includeParentEnvironment = true,
|
|
bool runInShell = false,
|
|
ProcessStartMode mode = ProcessStartMode.normal,
|
|
}) async {
|
|
return process;
|
|
}
|
|
}
|