-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pigeon] Started transitioning to run_tests.dart / added a windows su…
…pport (#519)
- Loading branch information
Showing
6 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int> Function() function; | ||
final String? description; | ||
} | ||
|
||
const Map<String, _TestInfo> _tests = <String, _TestInfo>{ | ||
'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<Process> _streamOutput(Future<Process> processFuture) async { | ||
final Process process = await processFuture; | ||
stdout.addStream(process.stdout); | ||
stderr.addStream(process.stderr); | ||
return process; | ||
} | ||
|
||
Future<int> _runAndroidUnitTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runDartCompilationTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runDartUnitTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runFlutterUnitTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runIosE2eTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runIosUnitTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runMockHandlerTests() async { | ||
throw UnimplementedError('See run_tests.sh.'); | ||
} | ||
|
||
Future<int> _runPigeon({ | ||
required String input, | ||
String? cppHeaderOut, | ||
String? cppSourceOut, | ||
}) async { | ||
const bool hasDart = false; | ||
final List<String> args = <String>[ | ||
'pub', | ||
'run', | ||
'pigeon', | ||
'--input', | ||
input, | ||
]; | ||
if (cppHeaderOut != null) { | ||
args.addAll(<String>[ | ||
'--objc_header_out', // TODO(gaaclarke): Switch to c++. | ||
cppHeaderOut, | ||
]); | ||
} | ||
if (cppSourceOut != null) { | ||
args.addAll(<String>[ | ||
'--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<int> _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', <String>['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', | ||
<String>[])); | ||
|
||
return run.exitCode; | ||
} | ||
|
||
Future<void> main(List<String> 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<String> testsToRun = _tests.keys.toList(); | ||
if (argResults.wasParsed(_listFlag)) { | ||
print('available tests:'); | ||
for (final MapEntry<String, _TestInfo> 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 <test name>] | ||
${parser.usage}'''); | ||
exit(0); | ||
} else if (argResults.wasParsed(_testFlag)) { | ||
testsToRun = <String>[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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/pigeon/platform_tests/android_unit_tests/android/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
buildscript { | ||
ext.kotlin_version = '1.3.50' | ||
ext.kotlin_version = '1.6.0' | ||
repositories { | ||
google() | ||
jcenter() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/pigeon/platform_tests/windows_unit_tests/windows/test/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.g.h | ||
*.g.cpp |