Files
sdk/pkg/linter/test/rules/avoid_void_async_test.dart
Brian Wilkerson a16de199d7 Convert many lint tests to use markdown
This is a rediculously large CL, and if you want me to split it up I'm
willing to do so.

However, the changes were all made by running a script I wrote and then
running the formatter over the code, so hopefully a spot-check will be
sufficient.

Change-Id: Ifc59b2cc3bf9e4edf0229a130cd587dc73f95615
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505042
Reviewed-by: Samuel Rawlins <srawlins@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-20 11:27:11 -07:00

263 lines
4.7 KiB
Dart

// Copyright (c) 2022, 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.
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../rule_test_support.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(AvoidVoidAsyncTest);
});
}
@reflectiveTest
class AvoidVoidAsyncTest extends LintRuleTest {
@override
String get lintRule => LintNames.avoid_void_async;
test_function_async_futureVoidReturnType_arrow() async {
await assertNoDiagnostics(r'''
Future<void> f() async => null;
''');
}
test_function_async_futureVoidReturnType_block() async {
await assertNoDiagnostics(r'''
Future<void> c() async {}
''');
}
test_function_async_voidReturnType_arrow() async {
await assertDiagnosticsFromMarkdown(r'''
void [!f!]() async => null;
''');
}
test_function_async_voidReturnType_block() async {
await assertDiagnosticsFromMarkdown(r'''
void [!f!]() async {}
''');
}
test_function_asyncStar() async {
await assertNoDiagnostics(r'''
Stream<void> f() async* {}
''');
}
test_function_notAsync_arrow_topLevel() async {
await assertNoDiagnostics(r'''
void e() => null;
''');
}
test_function_notAsync_voidReturnType() async {
await assertNoDiagnostics(r'''
void f() {}
''');
}
test_function_syncStar() async {
await assertNoDiagnostics(r'''
Iterable<void> f() sync* {}
''');
}
test_functionExpression_async_arrow() async {
await assertNoDiagnostics(r'''
void f() {
() async => null;
}
''');
}
test_functionExpression_async_block() async {
await assertNoDiagnostics(r'''
void f() {
() async {};
}
''');
}
test_functionExpression_notAsync_arrow() async {
await assertNoDiagnostics(r'''
void f() {
() => null;
}
''');
}
test_functionExpression_notAsync_body() async {
await assertNoDiagnostics(r'''
void f() {
() {};
}
''');
}
test_functionLocal_async_arrow() async {
await assertDiagnosticsFromMarkdown(r'''
void f() {
void [!g!]() async => null;
}
''');
}
test_functionLocal_main_async_arrow() async {
await assertDiagnosticsFromMarkdown(r'''
void f() {
void [!main!]() async => null;
}
''');
}
test_getter_async() async {
await assertDiagnosticsFromMarkdown(r'''
void get [!l!] async => null;
''');
}
test_getter_async_voidReturnType() async {
await assertDiagnosticsFromMarkdown(r'''
void get [!f!] async => null;
''');
}
test_getter_notAsync() async {
await assertNoDiagnostics(r'''
void get f => null;
''');
}
test_localFunction_async() async {
await assertDiagnosticsFromMarkdown(r'''
Future<void> f() async {
void [!g!]() async {}
}
''');
}
test_main_async() async {
await assertNoDiagnostics(r'''
Future<void> f() async { }
void main() async {
await f();
}
''');
}
test_method_async_arrow() async {
await assertDiagnosticsFromMarkdown(r'''
class Foo {
void [!d!]() async => null;
}
''');
}
test_method_async_block() async {
await assertDiagnosticsFromMarkdown(r'''
class Foo {
void [!f!]() async {}
}
''');
}
test_method_async_futureVoidReturnType_arrow() async {
await assertNoDiagnostics(r'''
class Foo {
Future<void> f() async => null;
}
''');
}
test_method_async_futureVoidReturnType_block() async {
await assertNoDiagnostics(r'''
class Foo {
Future<void> f() async {}
}
''');
}
test_method_asyncStar() async {
await assertNoDiagnostics(r'''
class Foo {
Stream<void> f() async* {}
}
''');
}
test_method_main_async_arrow() async {
await assertDiagnosticsFromMarkdown(r'''
class Foo {
void [!main!]() async => null;
}
''');
}
test_method_notAsync_arrow() async {
await assertNoDiagnostics(r'''
class Foo {
void e() => null;
}
''');
}
test_method_notAsync_block() async {
await assertNoDiagnostics(r'''
class Foo {
void f() {}
}
''');
}
test_method_syncStar() async {
await assertNoDiagnostics(r'''
class Foo {
Iterable<void> f() sync* {}
}
''');
}
test_operator_async() async {
await assertDiagnosticsFromMarkdown(r'''
class Foo {
void operator [!|!](_) async => null;
}
''');
}
test_operator_notAsync() async {
await assertNoDiagnostics(r'''
class Foo {
void operator &(_) => null;
}
''');
}
test_setter_notAsync() async {
await assertNoDiagnostics(r'''
void set f(_) => null;
''');
}
test_setter_notAsync_implicitReturnType() async {
await assertNoDiagnostics(r'''
set f(_) => null;
''');
}
test_typedef_futureVoidReturnType() async {
await assertNoDiagnostics(r'''
typedef Future<void> F(int x);
''');
}
test_typedef_voidReturnType() async {
await assertNoDiagnostics(r'''
typedef void F(int x);
''');
}
}