-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move use_test_throws_matchers tests (dart-lang/linter#4529)
- Loading branch information
Showing
7 changed files
with
100 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
2
test_data/mock_packages/test_api/lib/src/frontend/expect.dart
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.