Fix line-dependent tests for formatting (#160389)

These tests are dependent on line numbers. This formats them and updates
the line number to take them off the critical path.
This commit is contained in:
Michael Goderbauer 2024-12-16 16:29:51 -08:00 committed by GitHub
parent 43ee8029c9
commit e19e117c37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2767 additions and 2821 deletions

View File

@ -25,25 +25,27 @@ void _tests() {
}); });
Future<void> pumpTestWidget(WidgetTester tester) async { Future<void> pumpTestWidget(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(
home: ListView( MaterialApp(
children: <Widget>[ home: ListView(
const Text('Plain text'), children: <Widget>[
Semantics( const Text('Plain text'),
selected: true, Semantics(
checked: true, selected: true,
onTap: () { }, checked: true,
onDecrease: () { }, onTap: () {},
value: 'test-value', onDecrease: () {},
increasedValue: 'test-increasedValue', value: 'test-value',
decreasedValue: 'test-decreasedValue', increasedValue: 'test-increasedValue',
hint: 'test-hint', decreasedValue: 'test-decreasedValue',
textDirection: TextDirection.rtl, hint: 'test-hint',
child: const Text('Interactive text'), textDirection: TextDirection.rtl,
), child: const Text('Interactive text'),
], ),
],
),
), ),
)); );
} }
// This test generates code using generateTestSemanticsExpressionForCurrentSemanticsTree // This test generates code using generateTestSemanticsExpressionForCurrentSemanticsTree
@ -55,12 +57,15 @@ void _tests() {
testWidgets('generates code', (WidgetTester tester) async { testWidgets('generates code', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await pumpTestWidget(tester); await pumpTestWidget(tester);
final String code = semantics final String code =
.generateTestSemanticsExpressionForCurrentSemanticsTree(DebugSemanticsDumpOrder.inverseHitTest) semantics
.split('\n') .generateTestSemanticsExpressionForCurrentSemanticsTree(
.map<String>((String line) => line.trim()) DebugSemanticsDumpOrder.inverseHitTest,
.join('\n') )
.trim(); .split('\n')
.map<String>((String line) => line.trim())
.join('\n')
.trim();
File? findThisTestFile(Directory directory) { File? findThisTestFile(Directory directory) {
for (final FileSystemEntity entity in directory.listSync()) { for (final FileSystemEntity entity in directory.listSync()) {
@ -69,7 +74,10 @@ void _tests() {
if (childSearch != null) { if (childSearch != null) {
return childSearch; return childSearch;
} }
} else if (entity is File && entity.path.endsWith('semantics_tester_generate_test_semantics_expression_for_current_semantics_tree_test.dart')) { } else if (entity is File &&
entity.path.endsWith(
'semantics_tester_generate_test_semantics_expression_for_current_semantics_tree_test.dart',
)) {
return entity; return entity;
} }
} }
@ -79,14 +87,13 @@ void _tests() {
final File thisTestFile = findThisTestFile(Directory.current)!; final File thisTestFile = findThisTestFile(Directory.current)!;
expect(thisTestFile, isNotNull); expect(thisTestFile, isNotNull);
String expectedCode = thisTestFile.readAsStringSync(); String expectedCode = thisTestFile.readAsStringSync();
expectedCode = expectedCode.substring( expectedCode =
expectedCode.indexOf('v' * 12) + 12, expectedCode
expectedCode.indexOf('^' * 12) - 3, .substring(expectedCode.indexOf('v' * 12) + 12, expectedCode.indexOf('^' * 12) - 3)
) .split('\n')
.split('\n') .map<String>((String line) => line.trim())
.map<String>((String line) => line.trim()) .join('\n')
.join('\n') .trim();
.trim();
semantics.dispose(); semantics.dispose();
expect('$code,', expectedCode); expect('$code,', expectedCode);
}); });
@ -102,6 +109,7 @@ void _tests() {
// You must update it when changing the output generated by // You must update it when changing the output generated by
// generateTestSemanticsExpressionForCurrentSemanticsTree. Otherwise, // generateTestSemanticsExpressionForCurrentSemanticsTree. Otherwise,
// the test 'generates code', defined above, will fail. // the test 'generates code', defined above, will fail.
// dart format off
// vvvvvvvvvvvv // vvvvvvvvvvvv
TestSemantics.root( TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
@ -154,6 +162,7 @@ void _tests() {
], ],
), ),
// ^^^^^^^^^^^^ // ^^^^^^^^^^^^
// dart format on
ignoreRect: true, ignoreRect: true,
ignoreTransform: true, ignoreTransform: true,
ignoreId: true, ignoreId: true,

File diff suppressed because it is too large Load Diff