From 670b5bd8e714a1fd2bd137aa2c5b36760b8ce89b Mon Sep 17 00:00:00 2001 From: Dan Field Date: Mon, 16 Oct 2023 14:55:06 -0700 Subject: [PATCH] Fix `Platform.script` for flutter_tester (flutter/engine#46911) This addresses the problem in https://github.com/flutter/flutter/issues/12847 which changed slightly over time. Today, `Platform.script` does not give an empty `file` URI, it gives something like `file://path/to/package/main.dart` _regardless of how the file is actually named_. After this change, it will give the absolute path to the file being run under test. So before this change, the new test would have a URI like ``` file:///Users/dnfield/src/flutter/engine/src/main.dart ``` And now it has ``` file:///Users/dnfield/src/flutter/engine/src/out/host_debug_unopt_arm64/gen/platform_test.dart.dill ``` This is going to be helpful in generating relative paths from the test file. --- engine/src/flutter/shell/testing/tester_main.cc | 1 + engine/src/flutter/testing/dart/BUILD.gn | 1 + engine/src/flutter/testing/dart/platform_test.dart | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 engine/src/flutter/testing/dart/platform_test.dart diff --git a/engine/src/flutter/shell/testing/tester_main.cc b/engine/src/flutter/shell/testing/tester_main.cc index 607dc6a6a6..8b1b49131b 100644 --- a/engine/src/flutter/shell/testing/tester_main.cc +++ b/engine/src/flutter/shell/testing/tester_main.cc @@ -526,6 +526,7 @@ int main(int argc, char* argv[]) { // it as a positional argument instead. settings.application_kernel_asset = command_line.positional_args()[0]; } + settings.advisory_script_uri = settings.application_kernel_asset; if (settings.application_kernel_asset.empty()) { FML_LOG(ERROR) << "Dart kernel file not specified."; diff --git a/engine/src/flutter/testing/dart/BUILD.gn b/engine/src/flutter/testing/dart/BUILD.gn index 2e1bb1ad38..f59b6166c6 100644 --- a/engine/src/flutter/testing/dart/BUILD.gn +++ b/engine/src/flutter/testing/dart/BUILD.gn @@ -38,6 +38,7 @@ tests = [ "paragraph_test.dart", "path_test.dart", "picture_test.dart", + "platform_test.dart", "platform_view_test.dart", "plugin_utilities_test.dart", "semantics_test.dart", diff --git a/engine/src/flutter/testing/dart/platform_test.dart b/engine/src/flutter/testing/dart/platform_test.dart new file mode 100644 index 0000000000..5ba620ddcc --- /dev/null +++ b/engine/src/flutter/testing/dart/platform_test.dart @@ -0,0 +1,14 @@ +// Copyright 2013 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:io'; + +import 'package:litetest/litetest.dart'; + +void main() { + test('Platform.script has right URI', () async { + // Platform.script should look like file:///path/to/engine/src/out/variant/gen/platform_test.dart.dill + expect(Platform.script.path, endsWith('gen/platform_test.dart.dill')); + }); +}