Skip to content

Commit

Permalink
Move use_test_throws_matchers tests (dart-lang/linter#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Jul 5, 2023
1 parent 3812ef7 commit 291de9e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 51 deletions.
2 changes: 2 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ import 'use_late_for_private_fields_and_variables_test.dart'
as use_late_for_private_fields_and_variables;
import 'use_named_constants_test.dart' as use_named_constants;
import 'use_super_parameters_test.dart' as use_super_parameters;
import 'use_test_throws_matchers_test.dart' as use_test_throws_matchers;
import 'void_checks_test.dart' as void_checks;

void main() {
Expand Down Expand Up @@ -290,5 +291,6 @@ void main() {
use_late_for_private_fields_and_variables.main();
use_named_constants.main();
use_super_parameters.main();
use_test_throws_matchers.main();
void_checks.main();
}
98 changes: 98 additions & 0 deletions test/rules/use_test_throws_matchers_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(UseTestThrowsMatchersTest);
});
}

@reflectiveTest
class UseTestThrowsMatchersTest extends LintRuleTest {
@override
String get lintRule => 'use_test_throws_matchers';

@override
void setUp() {
super.setUp();
var testApiPath = '$workspaceRootPath/test_api';
var packageConfigBuilder = PackageConfigFileBuilder();
packageConfigBuilder.add(
name: 'test_api',
rootPath: testApiPath,
);
writeTestPackageConfig(packageConfigBuilder);
newFile('$testApiPath/lib/src/frontend/expect.dart', r'''
void expect(dynamic actual, dynamic matcher) {}
Never fail(String message) {}
''');
newFile('$testApiPath/lib/test_api.dart', r'''
export 'src/frontend/expect.dart';
''');
}

test_failInTry() async {
await assertDiagnostics(r'''
import 'package:test_api/test_api.dart';
void f() {
try {
f();
fail('fail');
} catch (e) {}
}
''', [
lint(74, 13),
]);
}

test_failWithExpectInCatch() async {
await assertNoDiagnostics(r'''
import 'package:test_api/test_api.dart';
void f() {
try {
f();
fail('fail');
} catch (e) {
expect(e, null);
} finally {
print('hello');
}
}
''');
}

test_failWithExpectInOnCatch() async {
await assertNoDiagnostics(r'''
import 'package:test_api/test_api.dart';
void f() {
try {
f();
fail('fail');
} on Exception catch (e) {
expect(e, null);
} catch (e) {
expect(e, null);
}
}
''');
}

test_noFail() async {
await assertNoDiagnostics(r'''
void f() {
try {
f();
} catch (e) {}
}
''');
}
}
2 changes: 0 additions & 2 deletions test_data/mock_packages/test_api/lib/src/frontend/expect.dart

This file was deleted.

3 changes: 0 additions & 3 deletions test_data/mock_packages/test_api/lib/test_api.dart

This file was deleted.

4 changes: 0 additions & 4 deletions test_data/mock_packages/test_api/pubspec.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions test_data/rules/.dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
"rootUri": "../../mock_packages/meta/",
"packageUri": "lib/",
"languageVersion": "2.17"
},
{
"name": "test_api",
"rootUri": "../../mock_packages/test_api/",
"packageUri": "lib/",
"languageVersion": "2.17"
}
],
"generated": "2022-06-30T01:27:31.576781Z",
Expand Down
36 changes: 0 additions & 36 deletions test_data/rules/use_test_throws_matchers.dart

This file was deleted.

0 comments on commit 291de9e

Please sign in to comment.