flutter_run_test.dart 2.07 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:process/process.dart';

import '../src/common.dart';
import 'test_data/basic_project.dart';
11
import 'test_driver.dart';
12
import 'test_utils.dart';
13 14

void main() {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  Directory tempDir;
  final BasicProject _project = BasicProject();
  FlutterRunTestDriver _flutter;

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('run_test.');
    await _project.setUpIn(tempDir);
    _flutter = FlutterRunTestDriver(tempDir);
  });

  tearDown(() async {
    await _flutter.stop();
    tryToDelete(tempDir);
  });

30
  testWithoutContext('flutter run reports an error if an invalid device is supplied', () async {
31 32 33 34
    // This test forces flutter to check for all possible devices to catch issues
    // like https://github.com/flutter/flutter/issues/21418 which were skipped
    // over because other integration tests run using flutter-tester which short-cuts
    // some of the checks for devices.
35
    final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

    const ProcessManager _processManager = LocalProcessManager();
    final ProcessResult _proc = await _processManager.run(
      <String>[flutterBin, 'run', '-d', 'invalid-device-id'],
      workingDirectory: tempDir.path,
    );

    expect(_proc.stdout, isNot(contains('flutter has exited unexpectedly')));
    expect(_proc.stderr, isNot(contains('flutter has exited unexpectedly')));
    if (!_proc.stderr.toString().contains('Unable to locate a development')
        && !_proc.stdout.toString().contains('No devices found with name or id matching')) {
      fail("'flutter run -d invalid-device-id' did not produce the expected error");
    }
  });

51
  testWithoutContext('flutter run writes pid-file', () async {
52 53 54 55
    final File pidFile = tempDir.childFile('test.pid');
    await _flutter.run(pidFile: pidFile);
    expect(pidFile.existsSync(), isTrue);
  });
56
}