mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
Applied consistent code formatting across all packages using \$ melos format
└> dart format .
└> RUNNING (in 8 packages)
--------------------------------------------------------------------------------
benchmark_di:
Formatted 18 files (0 changed) in 0.30 seconds.
benchmark_di: SUCCESS
--------------------------------------------------------------------------------
cherrypick:
Formatted 24 files (0 changed) in 0.34 seconds.
cherrypick: SUCCESS
--------------------------------------------------------------------------------
cherrypick_annotations:
Formatted 11 files (0 changed) in 0.14 seconds.
cherrypick_annotations: SUCCESS
--------------------------------------------------------------------------------
cherrypick_flutter:
Formatted 3 files (0 changed) in 0.15 seconds.
cherrypick_flutter: SUCCESS
--------------------------------------------------------------------------------
cherrypick_generator:
Formatted 17 files (0 changed) in 0.27 seconds.
cherrypick_generator: SUCCESS
--------------------------------------------------------------------------------
client_app:
Formatted 4 files (0 changed) in 0.14 seconds.
client_app: SUCCESS
--------------------------------------------------------------------------------
postly:
Formatted lib/router/app_router.gr.dart
Formatted 23 files (1 changed) in 0.33 seconds.
postly: SUCCESS
--------------------------------------------------------------------------------
talker_cherrypick_logger:
Formatted 4 files (0 changed) in 0.18 seconds.
talker_cherrypick_logger: SUCCESS
--------------------------------------------------------------------------------
$ melos format
└> dart format .
└> SUCCESS. No functional or logic changes included.
66 lines
2.1 KiB
Dart
66 lines
2.1 KiB
Dart
import 'package:cherrypick/cherrypick.dart';
|
||
import 'package:test/test.dart';
|
||
import 'mock_logger.dart';
|
||
|
||
class DummyService {}
|
||
|
||
class DummyModule extends Module {
|
||
@override
|
||
void builder(Scope currentScope) {
|
||
bind<DummyService>().toInstance(DummyService()).withName('test');
|
||
}
|
||
}
|
||
|
||
class A {}
|
||
|
||
class B {}
|
||
|
||
class CyclicModule extends Module {
|
||
@override
|
||
void builder(Scope cs) {
|
||
bind<A>().toProvide(() => cs.resolve<B>() as A);
|
||
bind<B>().toProvide(() => cs.resolve<A>() as B);
|
||
}
|
||
}
|
||
|
||
void main() {
|
||
late MockObserver observer;
|
||
|
||
setUp(() {
|
||
observer = MockObserver();
|
||
});
|
||
|
||
test('Global logger receives Binding events', () {
|
||
final scope = Scope(null, observer: observer);
|
||
scope.installModules([DummyModule()]);
|
||
final _ = scope.resolve<DummyService>(named: 'test');
|
||
|
||
// Проверяем, что биндинг DummyService зарегистрирован
|
||
expect(
|
||
observer.bindings.any((m) => m.contains('DummyService')),
|
||
isTrue,
|
||
);
|
||
// Можно добавить проверки diagnostics, если Scope что-то пишет туда
|
||
});
|
||
|
||
test('CycleDetector logs cycle detection error', () {
|
||
final scope = Scope(null, observer: observer);
|
||
// print('[DEBUG] TEST SCOPE logger type=${scope.logger.runtimeType} hash=${scope.logger.hashCode}');
|
||
scope.enableCycleDetection();
|
||
scope.installModules([CyclicModule()]);
|
||
expect(
|
||
() => scope.resolve<A>(),
|
||
throwsA(isA<CircularDependencyException>()),
|
||
);
|
||
// Проверяем, что цикл зафиксирован либо в errors, либо в diagnostics либо cycles
|
||
final foundInErrors =
|
||
observer.errors.any((m) => m.contains('cycle detected'));
|
||
final foundInDiagnostics =
|
||
observer.diagnostics.any((m) => m.contains('cycle detected'));
|
||
final foundCycleNotified = observer.cycles.isNotEmpty;
|
||
expect(foundInErrors || foundInDiagnostics || foundCycleNotified, isTrue,
|
||
reason:
|
||
'Ожидаем хотя бы один лог о цикле! errors: ${observer.errors}\ndiag: ${observer.diagnostics}\ncycles: ${observer.cycles}');
|
||
});
|
||
}
|