blob: 6db12ee2f9c29d5d32b167e2cc67f96ec3a4b8f8 [file]
// Copyright (c) 2023, 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(AvoidSlowAsyncIoTest);
});
}
@reflectiveTest
class AvoidSlowAsyncIoTest extends LintRuleTest {
@override
String get lintRule => LintNames.avoid_slow_async_io;
test_directory_exists() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(Directory dir) async {
await [!dir.exists()!];
}
''');
}
test_directory_exists_extensionType_implements() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
extension type MyDir(Directory dir) implements Directory {}
void f(MyDir dir) async {
await [!dir.exists()!];
}
''');
}
test_directory_existsSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(Directory dir) async {
dir.existsSync();
}
''');
}
test_directory_stat() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(Directory dir) async {
await [!dir.stat()!];
}
''');
}
test_directory_statSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(Directory dir) async {
dir.statSync();
}
''');
}
test_file_exists() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(File file) async {
await [!file.exists()!];
}
''');
}
test_file_exists_extensionType_implements() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
extension type MyFile(File file) implements File {}
void f(MyFile file) async {
await [!file.exists()!];
}
''');
}
test_file_exists_extensionType_redeclares() async {
await assertNoDiagnostics(r'''
import 'dart:io';
extension type MyFile(File file) {
void exists() {}
}
void f(MyFile file) async {
file.exists();
}
''');
}
test_file_existsSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(File file) async {
file.existsSync();
}
''');
}
test_file_lastModified() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(File file) async {
await [!file.lastModified()!];
}
''');
}
test_file_lastModifiedSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(File file) async {
file.lastModifiedSync();
}
''');
}
test_file_stat() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(File file) async {
await [!file.stat()!];
}
''');
}
test_file_statSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(File file) async {
file.statSync();
}
''');
}
test_fileSystemEntity_isDirectory() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(String path) async {
await [!FileSystemEntity.isDirectory(path)!];
}
''');
}
test_fileSystemEntity_isDirectorySync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(String path) async {
FileSystemEntity.isDirectorySync(path);
}
''');
}
test_fileSystemEntity_isFile() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(String path) async {
await [!FileSystemEntity.isFile(path)!];
}
''');
}
test_fileSystemEntity_isFileSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(String path) async {
FileSystemEntity.isFileSync(path);
}
''');
}
test_fileSystemEntity_isLink() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(String path) async {
await [!FileSystemEntity.isLink(path)!];
}
''');
}
test_fileSystemEntity_isLinkSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(String path) async {
FileSystemEntity.isLinkSync(path);
}
''');
}
test_fileSystemEntity_type() async {
await assertDiagnosticsFromMarkup(r'''
import 'dart:io';
void f(String path) async {
[!FileSystemEntity.type(path)!];
}
''');
}
test_fileSystemEntity_typeSync() async {
await assertNoDiagnostics(r'''
import 'dart:io';
void f(String path) async {
FileSystemEntity.typeSync(path);
}
''');
}
}