blob: 734b35cd139d321d0a5dc03c6e531e37a5a28688 [file] [log] [blame]
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// TODO(jakemac): swap this to @TestOn('pub-serve') once
// https://github.com/dart-lang/test/issues/388 is completed.
@TestOn('!js')
@initializeTracker
library initialize.initializer_test;
import 'foo/bar.dart';
import 'package:initialize/src/initialize_tracker.dart';
import 'package:initialize/initialize.dart';
import 'package:test_package/foo.dart';
import 'package:test/test.dart';
main() {
// Run all initializers.
run().then((_) {
test('annotations are seen in post-order with superclasses first', () {
var expectedNames = [
const LibraryIdentifier(#initialize.test.foo, null, 'foo.dart'),
fooBar,
foo,
Foo,
const LibraryIdentifier(#initialize.test.foo.bar, null, 'foo/bar.dart'),
bar,
Bar,
const LibraryIdentifier(#test_package.bar, 'test_package', 'bar.dart'),
const LibraryIdentifier(#test_package.foo, 'test_package', 'foo.dart'),
const LibraryIdentifier(
#initialize.initializer_test, null, 'initializer_test.dart'),
zap,
Zoop, // Zap extends Zoop, so Zoop comes first.
Zap,
];
expect(InitializeTracker.seen, expectedNames);
});
test('annotations only run once', () {
// Run the initializers again, should be a no-op.
var originalSize = InitializeTracker.seen.length;
return run().then((_) {
expect(InitializeTracker.seen.length, originalSize);
});
});
});
}
@initializeTracker
class Zoop {}
@initializeTracker
class Zap extends Zoop {}
@initializeTracker
zap() {}