Add tag support for executing reduced test sets (#86821)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/// Mack class definition for testing.
|
||||
/// Should not be tag-enforced, no analysis failures should be found.
|
||||
void matchesGoldenFile(Object key) {
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/// Sample Code
|
||||
///
|
||||
/// Should not be tag-enforced, no analysis failures should be found.
|
||||
///
|
||||
/// {@tool snippet}
|
||||
/// Sample invocations of [matchesGoldenFile].
|
||||
///
|
||||
/// ```dart
|
||||
/// await expectLater(
|
||||
/// find.text('Save'),
|
||||
/// matchesGoldenFile('save.png'),
|
||||
/// );
|
||||
///
|
||||
/// await expectLater(
|
||||
/// image,
|
||||
/// matchesGoldenFile('save.png'),
|
||||
/// );
|
||||
///
|
||||
/// await expectLater(
|
||||
/// imageFuture,
|
||||
/// matchesGoldenFile(
|
||||
/// 'save.png',
|
||||
/// version: 2,
|
||||
/// ),
|
||||
/// );
|
||||
///
|
||||
/// await expectLater(
|
||||
/// find.byType(MyWidget),
|
||||
/// matchesGoldenFile('goldens/myWidget.png'),
|
||||
/// );
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
|
||||
// Other comments
|
||||
// matchesGoldenFile('comment.png');
|
||||
|
||||
String literal = 'matchesGoldenFile()'; // flutter_ignore: golden_tag (see analyze.dart)
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This would fail analysis, but it is ignored
|
||||
// flutter_ignore_for_file: golden_tag (see analyze.dart)
|
||||
|
||||
@Tags(<String>['some-other-tag'])
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'golden_class.dart';
|
||||
|
||||
void main() {
|
||||
matchesGoldenFile('missing_tag.png');
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// The reduced test set tag is missing. This should fail analysis.
|
||||
@Tags(<String>['some-other-tag'])
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'golden_class.dart';
|
||||
|
||||
void main() {
|
||||
matchesGoldenFile('missing_tag.png');
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// The tag is missing. This should fail analysis.
|
||||
|
||||
import 'golden_class.dart';
|
||||
|
||||
void main() {
|
||||
matchesGoldenFile('missing_tag.png');
|
||||
}
|
||||
@@ -73,6 +73,51 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('analyze.dart - verifyGoldenTags', () async {
|
||||
final String result = await capture(() => verifyGoldenTags(testRootPath, minimumMatches: 6), exitCode: 1);
|
||||
const String noTag = 'Files containing golden tests must be '
|
||||
'tagged using `@Tags(...)` at the top of the file before import statements.';
|
||||
const String missingTag = 'Files containing golden tests must be '
|
||||
"tagged with 'reduced-test-set'.";
|
||||
String lines = <String>[
|
||||
'test/analyze-test-input/root/packages/foo/golden_missing_tag.dart: $missingTag',
|
||||
'test/analyze-test-input/root/packages/foo/golden_no_tag.dart: $noTag',
|
||||
]
|
||||
.map((String line) {
|
||||
return line
|
||||
.replaceAll('/', Platform.isWindows ? r'\' : '/');
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
try {
|
||||
expect(
|
||||
result,
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
'$lines\n'
|
||||
'See: https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter\n'
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
);
|
||||
} catch (_) {
|
||||
// This list of files may come up in one order or the other.
|
||||
lines = <String>[
|
||||
'test/analyze-test-input/root/packages/foo/golden_no_tag.dart: $noTag',
|
||||
'test/analyze-test-input/root/packages/foo/golden_missing_tag.dart: $missingTag',
|
||||
]
|
||||
.map((String line) {
|
||||
return line
|
||||
.replaceAll('/', Platform.isWindows ? r'\' : '/');
|
||||
})
|
||||
.join('\n');
|
||||
expect(
|
||||
result,
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
'$lines\n'
|
||||
'See: https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter\n'
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('analyze.dart - verifyNoMissingLicense', () async {
|
||||
final String result = await capture(() => verifyNoMissingLicense(testRootPath, checkMinimums: false), exitCode: 1);
|
||||
final String lines = 'test/analyze-test-input/root/packages/foo/foo.dart'
|
||||
|
||||
Reference in New Issue
Block a user