create_test.dart 1.8 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 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:io';

7
import 'package:args/command_runner.dart';
8
import 'package:flutter_tools/src/artifacts.dart';
9
import 'package:flutter_tools/src/base/process.dart';
10 11
import 'package:flutter_tools/src/commands/create.dart';
import 'package:path/path.dart' as path;
12 13 14 15 16
import 'package:test/test.dart';

main() => defineTests();

defineTests() {
17
  group('create', () {
18 19 20
    Directory temp;

    setUp(() {
21
      temp = Directory.systemTemp.createTempSync('flutter_tools');
22 23 24 25 26 27
    });

    tearDown(() {
      temp.deleteSync(recursive: true);
    });

Devon Carew's avatar
Devon Carew committed
28 29 30 31
    // This test consistently times out on our windows bot. The code is already
    // covered on the linux one.
    if (!Platform.isWindows) {
      // Verify that we create a project that is well-formed.
Devon Carew's avatar
Devon Carew committed
32
      test('flutter-simple', () async {
33
        ArtifactStore.flutterRoot = '../..';
34
        CreateCommand command = new CreateCommand();
Devon Carew's avatar
Devon Carew committed
35 36
        CommandRunner runner = new CommandRunner('test_flutter', '')
          ..addCommand(command);
37
        await runner.run(['create', '--out', temp.path])
Devon Carew's avatar
Devon Carew committed
38 39
            .then((int code) => expect(code, equals(0)));

40 41
        String mainPath = path.join(temp.path, 'lib', 'main.dart');
        expect(new File(mainPath).existsSync(), true);
Devon Carew's avatar
Devon Carew committed
42
        ProcessResult exec = Process.runSync(
43 44 45
          sdkBinaryName('dartanalyzer'), ['--fatal-warnings', mainPath],
          workingDirectory: temp.path
        );
Devon Carew's avatar
Devon Carew committed
46 47 48 49 50 51 52 53 54
        if (exec.exitCode != 0) {
          print(exec.stdout);
          print(exec.stderr);
        }
        expect(exec.exitCode, 0);
      },
      // This test can take a while due to network requests.
      timeout: new Timeout(new Duration(minutes: 2)));
    }
55 56
  });
}