upgrade_test.dart 2.28 KB
Newer Older
1 2 3 4
// 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.

5
import 'package:flutter_tools/src/base/file_system.dart';
6
import 'package:flutter_tools/src/base/os.dart';
7
import 'package:flutter_tools/src/cache.dart';
8 9 10
import 'package:flutter_tools/src/commands/upgrade.dart';
import 'package:test/test.dart';

11 12
import '../src/common.dart';
import '../src/context.dart';
13

14 15
void main() {
  group('upgrade', () {
16 17 18 19
    setUpAll(() {
      Cache.disableLocking();
    });

20 21 22
    bool _match(String line) => UpgradeCommand.matchesGitLine(line);

    test('regex match', () {
23
      expect(_match(' .../flutter_gallery/lib/demo/buttons_demo.dart    | 10 +--'), true);
24 25 26 27
      expect(_match(' dev/benchmarks/complex_layout/lib/main.dart        |  24 +-'), true);

      expect(_match(' rename {packages/flutter/doc => dev/docs}/styles.html (92%)'), true);
      expect(_match(' delete mode 100644 doc/index.html'), true);
28
      expect(_match(' create mode 100644 examples/flutter_gallery/lib/gallery/demo.dart'), true);
29 30 31 32 33 34 35 36

      expect(_match('Fast-forward'), true);
    });

    test('regex doesn\'t match', () {
      expect(_match('Updating 79cfe1e..5046107'), false);
      expect(_match('229 files changed, 6179 insertions(+), 3065 deletions(-)'), false);
    });
37 38 39 40 41

    group('findProjectRoot', () {
      Directory temp;

      setUp(() async {
42
        temp = fs.systemTempDirectory.createTempSync('flutter_tools');
43 44 45 46 47 48 49
      });

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

      testUsingContext('in project', () async {
50 51 52
        final String projectPath = await createProject(temp);
        expect(findProjectRoot(projectPath), projectPath);
        expect(findProjectRoot(fs.path.join(projectPath, 'lib')), projectPath);
53

54
        final String hello = fs.path.join(Cache.flutterRoot, 'examples', 'hello_world');
55
        expect(findProjectRoot(hello), hello);
56
        expect(findProjectRoot(fs.path.join(hello, 'lib')), hello);
57 58 59
      });

      testUsingContext('outside project', () async {
60 61
        final String projectPath = await createProject(temp);
        expect(findProjectRoot(fs.directory(projectPath).parent.path), null);
62
        expect(findProjectRoot(Cache.flutterRoot), null);
63 64
      });
    });
65 66
  });
}