Visitar URL original
[data_assets] Cleanup tests · flutter/flutter@b91ad02 · GitHub
Skip to content

Commit b91ad02

Browse files
committed
[data_assets] Cleanup tests
1 parent cbdf361 commit b91ad02

82 files changed

Lines changed: 3559 additions & 158 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎dev/bots/test.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Future<void> _runIntegrationToolTests() async {
247247

248248
await runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'hook_user_defines'));
249249
await runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'link_hook'));
250+
await runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'data_asset_app'));
250251
}
251252

252253
Future<void> _runWidgetPreviewScaffoldToolTests() async {
@@ -354,6 +355,7 @@ Future<void> _runBuildTests() async {
354355
)
355356
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'android_views')))
356357
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'channels')))
358+
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'data_asset_app')))
357359
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'hybrid_android_views')))
358360
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'flutter_gallery')))
359361
..add(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "d446c00806d41e8d39a8e9c56cb01e0330c193b5"
8+
channel: "[user-branch]"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
17+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
18+
- platform: linux
19+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
20+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
21+
- platform: macos
22+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
23+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
24+
- platform: web
25+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
26+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
27+
- platform: windows
28+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
29+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
30+
31+
# User provided section
32+
33+
# List of Local paths (relative to this file) that should be
34+
# ignored by the migrate tool.
35+
#
36+
# Files that are not part of the templates will be ignored by default.
37+
unmanaged_files:
38+
- 'lib/main.dart'
39+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# data_asset_app
2+
3+
A new Flutter project.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter application.
8+
9+
A few resources to get you started if this is your first Flutter project:
10+
11+
- [Learn Flutter](https://docs.flutter.dev/get-started/learn-flutter)
12+
- [Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
13+
- [Flutter learning resources](https://docs.flutter.dev/reference/learning-resources)
14+
15+
For help getting started with Flutter development, view the
16+
[online documentation](https://docs.flutter.dev/), which offers tutorials,
17+
samples, guidance on mobile development, and a full API reference.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at https://dart.dev/lints.
17+
#
18+
# Instead of disabling a lint rule for the entire project in the
19+
# section below, it can also be suppressed for a single line of code
20+
# or a specific dart file by using the `// ignore: name_of_lint` and
21+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
22+
# producing the lint.
23+
rules:
24+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
25+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
26+
27+
# Additional information about this file can be found at
28+
# https://dart.dev/guides/language/analysis-options
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:data_assets/data_assets.dart';
2+
import 'package:hooks/hooks.dart';
3+
4+
void main(List<String> args) async {
5+
await build(args, (BuildInput input, BuildOutputBuilder output) async {
6+
if (input.config.buildAssetTypes.contains('data_assets/data')) {
7+
final List<String> assets = <String>['id1.txt']; // @assets
8+
for (final id in assets) {
9+
output.assets.data.add(
10+
DataAsset(
11+
package: input.packageName,
12+
name: 'data/$id',
13+
file: input.packageRoot.resolve('data/$id'),
14+
),
15+
);
16+
}
17+
}
18+
});
19+
}
20+
// @forced_rerun
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ignore_for_file: avoid_print
2+
import 'package:flutter/services.dart' show rootBundle;
3+
4+
// Only run the code once for each version.
5+
String lastVersion = '';
6+
7+
class AssetData {
8+
const AssetData(this.version, this.found, this.notFound);
9+
final String version;
10+
final Map<String, String> found;
11+
final List<String> notFound;
12+
}
13+
14+
Future<AssetData?> dumpAssets() async {
15+
const String version = 'version1'; // @version
16+
if (lastVersion == version) {
17+
return null;
18+
}
19+
lastVersion = version;
20+
21+
final found = <String, String>{};
22+
final notFound = <String>[];
23+
final List<String> assets = <String>['packages/data_asset_app/data/id1.txt']; // @assets
24+
for (final String assetId in assets) {
25+
try {
26+
found[assetId] = await rootBundle.loadString(assetId);
27+
} catch (e) {
28+
print('EXCEPTION $e');
29+
notFound.add(assetId);
30+
}
31+
}
32+
print('VERSION: $version');
33+
for (final MapEntry(:key, :value) in found.entries) {
34+
print('FOUND "$key": "$value".');
35+
}
36+
for (final id in notFound) {
37+
print('NOT-FOUND "$id".');
38+
}
39+
return AssetData(version, found, notFound);
40+
}
41+
// @forced_rerun
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// ignore_for_file: avoid_print
2+
import 'dart:async';
3+
4+
import 'package:data_asset_package/data_asset_package.dart';
5+
import 'package:flutter/material.dart';
6+
7+
import 'helper.dart';
8+
9+
void main() {
10+
runApp(const MyApp());
11+
}
12+
13+
class MyApp extends StatefulWidget {
14+
const MyApp({super.key});
15+
16+
@override
17+
State<MyApp> createState() => _MyAppState();
18+
}
19+
20+
class _MyAppState extends State<MyApp> {
21+
AssetData? _assetData;
22+
String _dependencyAsset = 'Loading...';
23+
Timer? _timer;
24+
25+
@override
26+
void initState() {
27+
super.initState();
28+
_timer = Timer.periodic(const Duration(milliseconds: 500), (_) async {
29+
final data = await dumpAssets();
30+
final depAsset = await readAsset();
31+
// Print for integration test discovery
32+
if (data != null) {
33+
print('DUMPED ASSETS for ${data.version}');
34+
}
35+
print('DEPENDENCY_ASSET: $depAsset');
36+
37+
if (mounted) {
38+
setState(() {
39+
if (data != null) {
40+
_assetData = data;
41+
}
42+
_dependencyAsset = depAsset;
43+
});
44+
}
45+
});
46+
}
47+
48+
@override
49+
void dispose() {
50+
_timer?.cancel();
51+
super.dispose();
52+
}
53+
54+
@override
55+
Widget build(BuildContext context) {
56+
return MaterialApp(
57+
title: 'Data Asset Demo',
58+
home: Scaffold(
59+
appBar: AppBar(title: const Text('Data Asset Demo')),
60+
body: ListView(
61+
padding: const EdgeInsets.all(16),
62+
children: [
63+
Text('Version: ${_assetData?.version ?? "Unknown"}', style: Theme.of(context).textTheme.headlineSmall),
64+
const Divider(),
65+
const Text('Local Assets:', style: TextStyle(fontWeight: FontWeight.bold)),
66+
if (_assetData != null) ...[
67+
if (_assetData!.found.isEmpty && _assetData!.notFound.isEmpty)
68+
const Text('No assets requested.'),
69+
for (final MapEntry(:key, :value) in _assetData!.found.entries)
70+
Text('FOUND "$key": "$value"'),
71+
for (final id in _assetData!.notFound)
72+
Text('NOT FOUND "$id"', style: const TextStyle(color: Colors.red)),
73+
] else
74+
const Text('Loading assets...'),
75+
const Divider(),
76+
const Text('Dependency Asset:', style: TextStyle(fontWeight: FontWeight.bold)),
77+
Text(_dependencyAsset),
78+
],
79+
),
80+
),
81+
);
82+
}
83+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flutter/ephemeral

0 commit comments

Comments
 (0)