
This allows analyze tests to interpret inline comments in a specific format as error message expectations. e.g.,: Adding `// ERROR: this is bad because A, B, C, D` to line 50 in `file.ext` would match an error message that looks like `../path/path/file.ext: 50: this is bad because A, B, C, D` ## 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]. <!-- 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
71 lines
2.8 KiB
Dart
71 lines
2.8 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 '../../foo/stopwatch_external_lib.dart' as externallib;
|
|
|
|
typedef ExternalStopwatchConstructor = externallib.MyStopwatch Function();
|
|
|
|
class StopwatchAtHome extends Stopwatch {
|
|
StopwatchAtHome();
|
|
StopwatchAtHome.create() : this();
|
|
|
|
Stopwatch get stopwatch => this;
|
|
}
|
|
|
|
void testNoStopwatches(Stopwatch stopwatch) {
|
|
// OK for now, but we probably want to catch public APIs that take a Stopwatch?
|
|
stopwatch.runtimeType;
|
|
// Bad: introducing Stopwatch from dart:core.
|
|
final Stopwatch localVariable = Stopwatch(); // ERROR: Stopwatch()
|
|
// Bad: introducing Stopwatch from dart:core.
|
|
Stopwatch().runtimeType; // ERROR: Stopwatch()
|
|
|
|
(localVariable..runtimeType) // OK: not directly introducing Stopwatch.
|
|
.runtimeType;
|
|
|
|
// Bad: introducing a Stopwatch subclass.
|
|
StopwatchAtHome().runtimeType; // ERROR: StopwatchAtHome()
|
|
|
|
// OK: not directly introducing Stopwatch.
|
|
Stopwatch anotherStopwatch = stopwatch;
|
|
// Bad: introducing a Stopwatch constructor.
|
|
StopwatchAtHome Function() constructor = StopwatchAtHome.new; // ERROR: StopwatchAtHome.new
|
|
assert(() {
|
|
anotherStopwatch = constructor()..runtimeType;
|
|
// Bad: introducing a Stopwatch constructor.
|
|
constructor = StopwatchAtHome.create; // ERROR: StopwatchAtHome.create
|
|
anotherStopwatch = constructor()..runtimeType;
|
|
return true;
|
|
}());
|
|
anotherStopwatch.runtimeType;
|
|
|
|
// Bad: introducing an external Stopwatch constructor.
|
|
externallib.MyStopwatch.create(); // ERROR: externallib.MyStopwatch.create()
|
|
ExternalStopwatchConstructor? externalConstructor;
|
|
|
|
assert(() {
|
|
// Bad: introducing an external Stopwatch constructor.
|
|
externalConstructor = externallib.MyStopwatch.new; // ERROR: externallib.MyStopwatch.new
|
|
return true;
|
|
}());
|
|
externalConstructor?.call();
|
|
|
|
// Bad: introducing an external Stopwatch.
|
|
externallib.stopwatch.runtimeType; // ERROR: externallib.stopwatch
|
|
// Bad: calling an external function that returns a Stopwatch.
|
|
externallib.createMyStopwatch().runtimeType; // ERROR: externallib.createMyStopwatch()
|
|
// Bad: calling an external function that returns a Stopwatch.
|
|
externallib.createStopwatch().runtimeType; // ERROR: externallib.createStopwatch()
|
|
// Bad: introducing the tear-off form of an external function that returns a Stopwatch.
|
|
externalConstructor = externallib.createMyStopwatch; // ERROR: externallib.createMyStopwatch
|
|
|
|
// OK: existing instance.
|
|
constructor.call().stopwatch;
|
|
}
|
|
|
|
void testStopwatchIgnore(Stopwatch stopwatch) {
|
|
Stopwatch().runtimeType; // flutter_ignore: stopwatch (see analyze.dart)
|
|
Stopwatch().runtimeType; // flutter_ignore: some_other_ignores, stopwatch (see analyze.dart)
|
|
}
|