upgrade_test.dart 2.26 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
import 'package:flutter_tools/src/commands/upgrade.dart';

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

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

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

    test('regex match', () {
22
      expect(_match(' .../flutter_gallery/lib/demo/buttons_demo.dart    | 10 +--'), true);
23 24 25 26
      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);
27
      expect(_match(' create mode 100644 examples/flutter_gallery/lib/gallery/demo.dart'), true);
28 29 30 31 32 33 34 35

      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);
    });
36 37

    group('findProjectRoot', () {
38
      Directory tempDir;
39 40

      setUp(() async {
41
        tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_upgrade_test.');
42 43 44
      });

      tearDown(() {
45
        tryToDelete(tempDir);
46 47 48
      });

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

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

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