[flutter_tools] Allow providing dart-defines to Android, iOS, macOS builds (#51714)
This commit is contained in:
15
dev/devicelab/bin/tasks/android_defines_test.dart
Normal file
15
dev/devicelab/bin/tasks/android_defines_test.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/tasks/defines_task.dart';
|
||||
|
||||
/// Verify that dart defines work on Android.
|
||||
Future<void> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.android;
|
||||
await task(runDartDefinesTask);
|
||||
}
|
||||
15
dev/devicelab/bin/tasks/ios_defines_test.dart
Normal file
15
dev/devicelab/bin/tasks/ios_defines_test.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/tasks/defines_task.dart';
|
||||
|
||||
/// Verify that dart defines work on iOS.
|
||||
Future<void> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.ios;
|
||||
await task(runDartDefinesTask);
|
||||
}
|
||||
30
dev/devicelab/lib/tasks/defines_task.dart
Normal file
30
dev/devicelab/lib/tasks/defines_task.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import '../framework/adb.dart';
|
||||
import '../framework/framework.dart';
|
||||
import '../framework/utils.dart';
|
||||
|
||||
Future<TaskResult> runDartDefinesTask() async {
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
final String deviceId = device.deviceId;
|
||||
final Directory testDirectory = dir('${flutterDirectory.path}/dev/integration_tests/ui');
|
||||
await inDirectory<void>(testDirectory, () async {
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
await flutter('drive', options: <String>[
|
||||
'--verbose',
|
||||
'-d',
|
||||
deviceId,
|
||||
'--dart-define=test.value=ExampleValue',
|
||||
'lib/defines.dart',
|
||||
]);
|
||||
});
|
||||
|
||||
return TaskResult.success(<String, dynamic>{});
|
||||
}
|
||||
@@ -323,6 +323,13 @@ tasks:
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["mac/android"]
|
||||
|
||||
android_defines_test:
|
||||
description: >
|
||||
Builds an APK with a --dart-define and verifies it can be used as a constant
|
||||
stage: devicelab
|
||||
flaky: true
|
||||
required_agent_capabilities: ["linux/android"]
|
||||
|
||||
android_obfuscate_test:
|
||||
description: >
|
||||
Builds an obfuscated APK and verifies a dart identifier cannot be found
|
||||
@@ -400,6 +407,13 @@ tasks:
|
||||
|
||||
# iOS on-device tests
|
||||
|
||||
ios_defines_test:
|
||||
description: >
|
||||
Builds a Framework with a --dart-define and verifies it can be used as a constant
|
||||
stage: devicelab
|
||||
flaky: true
|
||||
required_agent_capabilities: ["mac/ios"]
|
||||
|
||||
ios_content_validation_test:
|
||||
description: >
|
||||
Builds an obfuscated app and verifies contents and structure
|
||||
|
||||
19
dev/integration_tests/ui/lib/defines.dart
Normal file
19
dev/integration_tests/ui/lib/defines.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_driver/driver_extension.dart';
|
||||
|
||||
/// This application displays text passed through a --dart-define.
|
||||
void main() {
|
||||
enableFlutterDriverExtension();
|
||||
runApp(
|
||||
const Center(
|
||||
child: Text(
|
||||
String.fromEnvironment('test.value'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
22
dev/integration_tests/ui/test_driver/defines_test.dart
Normal file
22
dev/integration_tests/ui/test_driver/defines_test.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter_driver/flutter_driver.dart';
|
||||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
void main() {
|
||||
FlutterDriver driver;
|
||||
|
||||
setUpAll(() async {
|
||||
driver = await FlutterDriver.connect();
|
||||
});
|
||||
|
||||
tearDownAll(() async {
|
||||
await driver.close();
|
||||
});
|
||||
|
||||
test('Can run with --dart-deinfe', () async {
|
||||
await driver.waitFor(find.text('ExampleValue'));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user