diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 3467ac890e15..81660fd4d368 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* [ci] Started transitioning to a Dart test runner, added windows support. + ## 1.0.10 * [front-end] Made sure that explicit use of Object actually creates the codec diff --git a/packages/pigeon/bin/run_tests.dart b/packages/pigeon/bin/run_tests.dart new file mode 100644 index 000000000000..b02afc00f07a --- /dev/null +++ b/packages/pigeon/bin/run_tests.dart @@ -0,0 +1,194 @@ +// 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. + +//////////////////////////////////////////////////////////////////////////////// +/// Script for executing the Pigeon tests +/// +/// This currently only supports Windows tests. +/// +/// usage: pub run pigeon:run_tests +//////////////////////////////////////////////////////////////////////////////// +import 'dart:io' show Process, exit, stdout, stderr; +import 'package:args/args.dart'; +import 'package:meta/meta.dart'; +import 'package:pigeon/functional.dart'; + +const String _testFlag = 'test'; +const String _listFlag = 'list'; + +@immutable +class _TestInfo { + const _TestInfo({required this.function, this.description}); + final Future Function() function; + final String? description; +} + +const Map _tests = { + 'windows_unittests': _TestInfo( + function: _runWindowsUnitTests, + description: 'Unit tests on generated Windows C++ code.'), + 'android_unittests': _TestInfo( + function: _runAndroidUnitTests, + description: 'Unit tests on generated Java code.'), + 'dart_compilation_tests': _TestInfo( + function: _runDartCompilationTests, + description: 'Compilation tests on generated Dart code.'), + 'dart_unittests': _TestInfo( + function: _runDartUnitTests, + description: 'Unit tests on and analysis on Pigeon\'s implementation.'), + 'flutter_unittests': _TestInfo( + function: _runFlutterUnitTests, + description: 'Unit tests on generated Dart code.'), + 'ios_e2e_tests': _TestInfo( + function: _runIosE2eTests, + description: 'End-to-end Objective-C tests run on iOS Simulator'), + 'ios_unittests': _TestInfo( + function: _runIosUnitTests, + description: 'Unit tests on generated Objective-C code.'), + 'mock_handler_tests': _TestInfo( + function: _runMockHandlerTests, + description: 'Unit tests on generated Dart mock handler code.'), +}; + +Future _streamOutput(Future processFuture) async { + final Process process = await processFuture; + stdout.addStream(process.stdout); + stderr.addStream(process.stderr); + return process; +} + +Future _runAndroidUnitTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runDartCompilationTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runDartUnitTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runFlutterUnitTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runIosE2eTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runIosUnitTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runMockHandlerTests() async { + throw UnimplementedError('See run_tests.sh.'); +} + +Future _runPigeon({ + required String input, + String? cppHeaderOut, + String? cppSourceOut, +}) async { + const bool hasDart = false; + final List args = [ + 'pub', + 'run', + 'pigeon', + '--input', + input, + ]; + if (cppHeaderOut != null) { + args.addAll([ + '--objc_header_out', // TODO(gaaclarke): Switch to c++. + cppHeaderOut, + ]); + } + if (cppSourceOut != null) { + args.addAll([ + '--objc_source_out', // TODO(gaaclarke): Switch to c++. + cppSourceOut, + ]); + } + if (!hasDart) { + args.add('--one_language'); + } + final Process generate = await _streamOutput(Process.start('dart', args)); + final int generateCode = await generate.exitCode; + if (generateCode != 0) { + return generateCode; + } + return 0; +} + +Future _runWindowsUnitTests() async { + const String windowsUnitTestsPath = './platform_tests/windows_unit_tests'; + final int generateCode = await _runPigeon( + input: './pigeons/message.dart', + cppHeaderOut: '$windowsUnitTestsPath/windows/test/message.g.h', + cppSourceOut: '$windowsUnitTestsPath/windows/test/message.g.cpp', + ); + if (generateCode != 0) { + return generateCode; + } + + final Process compile = await _streamOutput(Process.start( + 'flutter', ['build', 'windows', '--debug'], + workingDirectory: '$windowsUnitTestsPath/example', runInShell: true)); + final int compileCode = await compile.exitCode; + if (compileCode != 0) { + return compileCode; + } + + final Process run = await _streamOutput(Process.start( + '$windowsUnitTestsPath/example/build/windows/plugins/windows_unit_tests/Debug/windows_unit_tests_test.exe', + [])); + + return run.exitCode; +} + +Future main(List args) async { + final ArgParser parser = ArgParser() + ..addOption(_testFlag, abbr: 't', help: 'Only run specified test.') + ..addFlag(_listFlag, + negatable: false, abbr: 'l', help: 'List available tests.') + ..addFlag('help', + negatable: false, abbr: 'h', help: 'Print this reference.'); + + final ArgResults argResults = parser.parse(args); + List testsToRun = _tests.keys.toList(); + if (argResults.wasParsed(_listFlag)) { + print('available tests:'); + for (final MapEntry info in _tests.entries) { + final int tabCount = (4 - info.key.length / 8).toInt(); + final String tabs = repeat('\t', tabCount).join(''); + print('${info.key}$tabs- ${info.value.description}'); + } + exit(0); + } else if (argResults.wasParsed('help')) { + print(''' +Pigeon run_tests +usage: pub run pigeon:run_tests [-l | -t ] + +${parser.usage}'''); + exit(0); + } else if (argResults.wasParsed(_testFlag)) { + testsToRun = [argResults[_testFlag]]; + } + + for (final String test in testsToRun) { + final _TestInfo? info = _tests[test]; + if (info != null) { + print('# Running $test'); + final int testCode = await info.function(); + if (testCode != 0) { + exit(testCode); + } + } else { + print('unknown test: $test'); + exit(1); + } + } + exit(0); +} diff --git a/packages/pigeon/platform_tests/android_unit_tests/android/app/build.gradle b/packages/pigeon/platform_tests/android_unit_tests/android/app/build.gradle index f45bc0bcab56..93562e75b6be 100644 --- a/packages/pigeon/platform_tests/android_unit_tests/android/app/build.gradle +++ b/packages/pigeon/platform_tests/android_unit_tests/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' diff --git a/packages/pigeon/platform_tests/android_unit_tests/android/build.gradle b/packages/pigeon/platform_tests/android_unit_tests/android/build.gradle index 8a8ae3d72b53..30053837a61b 100644 --- a/packages/pigeon/platform_tests/android_unit_tests/android/build.gradle +++ b/packages/pigeon/platform_tests/android_unit_tests/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.6.0' repositories { google() jcenter() diff --git a/packages/pigeon/platform_tests/windows_unit_tests/windows/CMakeLists.txt b/packages/pigeon/platform_tests/windows_unit_tests/windows/CMakeLists.txt index e04b2b5e0996..9d456d42504f 100644 --- a/packages/pigeon/platform_tests/windows_unit_tests/windows/CMakeLists.txt +++ b/packages/pigeon/platform_tests/windows_unit_tests/windows/CMakeLists.txt @@ -53,6 +53,8 @@ FetchContent_MakeAvailable(googletest) # directly into the test binary rather than using the DLL. add_executable(${TEST_RUNNER} test/pigeon_test.cpp + # TODO(gaaclarke): Add test/message.g.cpp. + # TODO(gaaclarke): Add test/message.g.h. ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) diff --git a/packages/pigeon/platform_tests/windows_unit_tests/windows/test/.gitignore b/packages/pigeon/platform_tests/windows_unit_tests/windows/test/.gitignore new file mode 100644 index 000000000000..835726cb1232 --- /dev/null +++ b/packages/pigeon/platform_tests/windows_unit_tests/windows/test/.gitignore @@ -0,0 +1,2 @@ +*.g.h +*.g.cpp