-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[flutter_plugin_tools] Add Linux support to native-test #4294
Changes from 10 commits
523f9cf
4107c6e
9f1f56e
3616b24
e223710
d5391c4
b6b1cd7
6bead5b
9c290d6
597f04f
4dc5490
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // 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. | ||
| #include <flutter_linux/flutter_linux.h> | ||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "include/url_launcher_linux/url_launcher_plugin.h" | ||
| #include "url_launcher_plugin_private.h" | ||
|
|
||
| namespace url_launcher_plugin { | ||
| namespace test { | ||
|
|
||
| TEST(UrlLauncherPlugin, CanLaunchSuccess) { | ||
| g_autoptr(FlValue) args = fl_value_new_map(); | ||
| fl_value_set_string_take(args, "url", | ||
| fl_value_new_string("https://flutter.dev")); | ||
| FlMethodResponse* response = can_launch(nullptr, args); | ||
| ASSERT_NE(response, nullptr); | ||
| ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response)); | ||
| g_autoptr(FlValue) expected = fl_value_new_bool(true); | ||
| EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result( | ||
| FL_METHOD_SUCCESS_RESPONSE(response)), | ||
| expected)); | ||
| } | ||
|
|
||
| TEST(UrlLauncherPlugin, CanLaunchFailureUnhandled) { | ||
| g_autoptr(FlValue) args = fl_value_new_map(); | ||
| fl_value_set_string_take(args, "url", fl_value_new_string("madeup:scheme")); | ||
| FlMethodResponse* response = can_launch(nullptr, args); | ||
| ASSERT_NE(response, nullptr); | ||
| ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response)); | ||
| g_autoptr(FlValue) expected = fl_value_new_bool(false); | ||
| EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result( | ||
| FL_METHOD_SUCCESS_RESPONSE(response)), | ||
| expected)); | ||
| } | ||
|
|
||
| // For consistency with the established mobile implementations, | ||
| // an invalid URL should return false, not an error. | ||
| TEST(UrlLauncherPlugin, CanLaunchFailureInvalidUrl) { | ||
| g_autoptr(FlValue) args = fl_value_new_map(); | ||
| fl_value_set_string_take(args, "url", fl_value_new_string("")); | ||
| FlMethodResponse* response = can_launch(nullptr, args); | ||
| ASSERT_NE(response, nullptr); | ||
| ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response)); | ||
| g_autoptr(FlValue) expected = fl_value_new_bool(false); | ||
| EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result( | ||
| FL_METHOD_SUCCESS_RESPONSE(response)), | ||
| expected)); | ||
| } | ||
|
|
||
| } // namespace test | ||
| } // namespace url_launcher_plugin |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // 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. | ||
|
|
||
| #include <flutter_linux/flutter_linux.h> | ||
|
|
||
| #include "include/url_launcher_linux/url_launcher_plugin.h" | ||
|
|
||
| // Handles the canLaunch method call. | ||
| // | ||
| // Temporarily exposed for testing due to | ||
| // https://github.com/flutter/flutter/issues/88724 | ||
| FlMethodResponse* can_launch(FlUrlLauncherPlugin* self, FlValue* args); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,9 @@ const String _iosDestinationFlag = 'ios-destination'; | |
| const int _exitNoIosSimulators = 3; | ||
|
|
||
| /// The command to run native tests for plugins: | ||
| /// - iOS and macOS: XCTests (XCUnitTest and XCUITest) in plugins. | ||
| /// - iOS and macOS: XCTests (XCUnitTest and XCUITest) | ||
| /// - Android: JUnit tests | ||
| /// - Windows and Linux: GoogleTest tests | ||
| class NativeTestCommand extends PackageLoopingCommand { | ||
| /// Creates an instance of the test command. | ||
| NativeTestCommand( | ||
|
|
@@ -39,6 +41,7 @@ class NativeTestCommand extends PackageLoopingCommand { | |
| ); | ||
| argParser.addFlag(kPlatformAndroid, help: 'Runs Android tests'); | ||
| argParser.addFlag(kPlatformIos, help: 'Runs iOS tests'); | ||
| argParser.addFlag(kPlatformLinux, help: 'Runs Linux tests'); | ||
| argParser.addFlag(kPlatformMacos, help: 'Runs macOS tests'); | ||
| argParser.addFlag(kPlatformWindows, help: 'Runs Windows tests'); | ||
|
|
||
|
|
@@ -63,9 +66,11 @@ class NativeTestCommand extends PackageLoopingCommand { | |
| Runs native unit tests and native integration tests. | ||
|
|
||
| Currently supported platforms: | ||
| - Android (unit tests only) | ||
| - Android | ||
| - iOS: requires 'xcrun' to be in your path. | ||
| - Linux (unit tests only) | ||
| - macOS: requires 'xcrun' to be in your path. | ||
| - Windows (unit tests only) | ||
|
|
||
| The example app(s) must be built for all targeted platforms before running | ||
| this command. | ||
|
|
@@ -80,6 +85,7 @@ this command. | |
| _platforms = <String, _PlatformDetails>{ | ||
| kPlatformAndroid: _PlatformDetails('Android', _testAndroid), | ||
| kPlatformIos: _PlatformDetails('iOS', _testIos), | ||
| kPlatformLinux: _PlatformDetails('Linux', _testLinux), | ||
| kPlatformMacos: _PlatformDetails('macOS', _testMacOS), | ||
| kPlatformWindows: _PlatformDetails('Windows', _testWindows), | ||
| }; | ||
|
|
@@ -103,6 +109,11 @@ this command. | |
| 'See https://github.com/flutter/flutter/issues/70233.'); | ||
| } | ||
|
|
||
| if (getBoolArg(kPlatformLinux) && getBoolArg(_integrationTestFlag)) { | ||
| logWarning('This command currently only supports unit tests for Linux. ' | ||
| 'See https://github.com/flutter/flutter/issues/70235.'); | ||
| } | ||
|
|
||
| // iOS-specific run-level state. | ||
| if (_requestedPlatforms.contains('ios')) { | ||
| String destination = getStringArg(_iosDestinationFlag); | ||
|
|
@@ -418,6 +429,21 @@ this command. | |
| buildDirectoryName: 'windows', isTestBinary: isTestBinary); | ||
| } | ||
|
|
||
| Future<_PlatformResult> _testLinux( | ||
| RepositoryPackage plugin, _TestMode mode) async { | ||
| if (mode.integrationOnly) { | ||
| return _PlatformResult(RunState.skipped); | ||
| } | ||
|
|
||
| bool isTestBinary(File file) { | ||
| return file.basename.endsWith('_test') || | ||
| file.basename.endsWith('_tests'); | ||
| } | ||
|
|
||
| return _runGoogleTestTests(plugin, | ||
| buildDirectoryName: 'linux', isTestBinary: isTestBinary); | ||
| } | ||
|
|
||
| /// Finds every file in the [buildDirectoryName] subdirectory of [plugin]'s | ||
| /// build directory for which [isTestBinary] is true, and runs all of them, | ||
| /// returning the overall result. | ||
|
|
@@ -442,10 +468,11 @@ this command. | |
| .whereType<File>() | ||
| .where(isTestBinary) | ||
| .where((File file) { | ||
| // Only run the debug build of the unit tests, to avoid running the | ||
| // same tests multiple times. | ||
| // Only run the release build of the unit tests, to avoid running the | ||
| // same tests multiple times. Release is used rather than debug since | ||
| // `build-examples` builds release versions. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was going to say perhaps we should be changing to generate a debug build of build-examples given that it's typically more convenient to debug debug builds. That said, in the end you want to verify the release build of the library code in the plugin, and people shouldn't be relying on If this ever gets problematic, we could add a buildmode flag.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that there's actually a more annoying problem, which is that the current behavior isn't going to be good for local use. Filed flutter/flutter#89303. I'm going to do that as a follow-up since it applies to the already-landed Windows flow in the same way, but I'll do it shortly. |
||
| final List<String> components = path.split(file.path); | ||
| return components.contains('debug') || components.contains('Debug'); | ||
| return components.contains('release') || components.contains('Release'); | ||
| })); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit consider phrasing as a TODO to aid in tech-debt greppability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done.