[flutter_tools] Allow providing dart-defines to Android, iOS, macOS builds (#51714)

This commit is contained in:
Jonah Williams
2020-03-05 12:38:40 -08:00
committed by GitHub
parent aed961993d
commit ee60eeea3e
46 changed files with 293 additions and 257 deletions

View 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);
}

View 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);
}

View 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>{});
}

View File

@@ -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

View 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,
),
),
);
}

View 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'));
});
}