run_test.dart 2.24 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

import 'common.dart';
12 13

void 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 20 21 22 23
      final ProcessResult scriptProcess = processManager.runSync(<String>[
        dart,
        'bin/run.dart',
        for (String testName in testNames) ...<String>['-t', testName],
      ]);
24 25 26 27 28 29 30 31
      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 ]');
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 61
          'smoke_test_failure',
          'smoke_test_success',
62
        ],
63 64 65 66 67
        1,
      );
    });
  });
}