1// Copyright 2016 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'dart:async'; 6import 'dart:io'; 7 8import 'package:path/path.dart' as path; 9import 'package:process/process.dart'; 10 11import 'common.dart'; 12 13void main() { 14 const ProcessManager processManager = LocalProcessManager(); 15 16 group('run.dart script', () { 17 Future<ProcessResult> runScript(List<String> testNames) async { 18 final String dart = path.absolute(path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', 'dart')); 19 final ProcessResult scriptProcess = processManager.runSync(<String>[ 20 dart, 21 'bin/run.dart', 22 for (String testName in testNames) ...<String>['-t', testName], 23 ]); 24 return scriptProcess; 25 } 26 27 Future<void> expectScriptResult(List<String> testNames, int expectedExitCode) async { 28 final ProcessResult result = await runScript(testNames); 29 expect(result.exitCode, expectedExitCode, 30 reason: '[ stderr from test process ]\n\n${result.stderr}\n\n[ end of stderr ]' 31 '\n\n[ stdout from test process ]\n\n${result.stdout}\n\n[ end of stdout ]'); 32 } 33 34 test('exits with code 0 when succeeds', () async { 35 await expectScriptResult(<String>['smoke_test_success'], 0); 36 }); 37 38 test('accepts file paths', () async { 39 await expectScriptResult(<String>['bin/tasks/smoke_test_success.dart'], 0); 40 }); 41 42 test('rejects invalid file paths', () async { 43 await expectScriptResult(<String>['lib/framework/adb.dart'], 1); 44 }); 45 46 test('exits with code 1 when task throws', () async { 47 await expectScriptResult(<String>['smoke_test_throws'], 1); 48 }); 49 50 test('exits with code 1 when fails', () async { 51 await expectScriptResult(<String>['smoke_test_failure'], 1); 52 }); 53 54 test('exits with code 1 when fails to connect', () async { 55 await expectScriptResult(<String>['smoke_test_setup_failure'], 1); 56 }, skip: true); // https://github.com/flutter/flutter/issues/5901 57 58 test('exits with code 1 when results are mixed', () async { 59 await expectScriptResult(<String>[ 60 'smoke_test_failure', 61 'smoke_test_success', 62 ], 63 1, 64 ); 65 }); 66 }); 67} 68