Skip to content

Commit

Permalink
tidy shared test setup (#4405)
Browse files Browse the repository at this point in the history
* tidy shared test setup

* fix
  • Loading branch information
pq authored May 30, 2023
1 parent 0b1eadf commit 6d9e080
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions test/doc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import 'package:test/test.dart';

import '../tool/doc.dart';
import 'util/test_utils.dart';

void main() {
group('doc generation', () {
setUp(setUpSharedTestEnvironment);
test('fixStatus (sanity)', () async {
var fixStatusMap = await fetchFixStatusMap();
// Doc generation reads the fix status map to associate fix status
Expand Down
2 changes: 2 additions & 0 deletions test/engine_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:test/test.dart';

import 'mocks.dart';
import 'test_constants.dart';
import 'util/test_utils.dart';

void main() {
defineLinterEngineTests();
Expand All @@ -27,6 +28,7 @@ void main() {
/// Linter engine tests
void defineLinterEngineTests() {
group('engine', () {
setUp(setUpSharedTestEnvironment);
group('reporter', () {
void doTest(
String label, String expected, Function(PrintingReporter r) report) {
Expand Down
11 changes: 7 additions & 4 deletions test/rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ import 'util/annotation_matcher.dart';
import 'util/test_utils.dart';

void main() {
defineSanityTests();
defineRuleTests();
experiment_tests.main();
defineRuleUnitTests();
group('rule tests', () {
setUp(setUpSharedTestEnvironment);
defineSanityTests();
defineRuleTests();
experiment_tests.main();
defineRuleUnitTests();
});
}

/// Rule tests
Expand Down
11 changes: 10 additions & 1 deletion test/util/test_utils.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// Copyright (c) 2017, 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:analyzer/src/lint/io.dart';
import 'package:linter/src/rules.dart';
import 'package:test/test.dart';

import '../mocks.dart';

void setUpSharedTestEnvironment() {
// Redirect output.
outSink = MockIOSink();
registerLintRules();
}

void testEach<T>(Iterable<T> values, bool Function(T s) f, Matcher m) {
for (var s in values) {
test('"$s"', () => expect(f(s), m));
Expand Down
4 changes: 4 additions & 0 deletions test/validate_rule_description_format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'package:analyzer/src/lint/registry.dart';
import 'package:test/test.dart';

import 'util/test_utils.dart';

void main() {
const keywords = [
'GOOD',
Expand All @@ -16,6 +18,8 @@ void main() {
];

group('rule doc format', () {
setUp(setUpSharedTestEnvironment);

var rules = Registry.ruleRegistry.rules;
test('(setup)', () {
expect(rules, isNotEmpty,
Expand Down

0 comments on commit 6d9e080

Please sign in to comment.