run_test.dart 2.33 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 The Chromium 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:async';
import 'dart:io';

8 9
import 'package:path/path.dart' as path;
import 'package:process/process.dart';
10 11 12
import 'package:test/test.dart';

void main() {
13
  const ProcessManager processManager = const LocalProcessManager();
14

15
  group('run.dart script', () {
16
    Future<ProcessResult> runScript(List<String> testNames) async {
17
      final List<String> options = <String>['bin/run.dart'];
18 19 20
      for (String testName in testNames) {
        options..addAll(<String>['-t', testName]);
      }
21 22 23
      final String dart = path.absolute(path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', 'dart'));
      final ProcessResult scriptProcess = processManager.runSync(
        <String>[dart]..addAll(options)
24
      );
25 26 27 28 29 30 31 32
      return scriptProcess;
    }

    Future<void> expectScriptResult(List<String> testNames, int expectedExitCode) async {
      final ProcessResult result = await runScript(testNames);
      expect(result.exitCode, expectedExitCode,
          reason: '[ stderr from test process ]\n\n${result.stderr}\n\n[ end of stderr ]'
          '\n\n[ stdout from test process ]\n\n${result.stdout}\n\n[ end of stdout ]');
33 34
    }

35
    test('exits with code 0 when succeeds', () async {
36
      await expectScriptResult(<String>['smoke_test_success'], 0);
37 38
    });

39
    test('accepts file paths', () async {
40
      await expectScriptResult(<String>['bin/tasks/smoke_test_success.dart'], 0);
41 42 43
    });

    test('rejects invalid file paths', () async {
44
      await expectScriptResult(<String>['lib/framework/adb.dart'], 1);
45 46 47
    });

    test('exits with code 1 when task throws', () async {
48
      await expectScriptResult(<String>['smoke_test_throws'], 1);
49
    });
50

51
    test('exits with code 1 when fails', () async {
52
      await expectScriptResult(<String>['smoke_test_failure'], 1);
53 54
    });

55
    test('exits with code 1 when fails to connect', () async {
56
      await expectScriptResult(<String>['smoke_test_setup_failure'], 1);
57
    }, skip: true); // https://github.com/flutter/flutter/issues/5901
58

59
    test('exits with code 1 when results are mixed', () async {
60
      await expectScriptResult(<String>[
61 62
          'smoke_test_failure',
          'smoke_test_success',
63
        ],
64 65 66 67 68
        1,
      );
    });
  });
}