analyze_test.dart 1.61 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/cache.dart';
7
import 'package:flutter_tools/src/commands/analyze_base.dart';
8
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
9 10 11 12 13
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'src/context.dart';

14
void main() {
15 16 17
  Directory tempDir;

  setUp(() {
18
    FlutterCommandRunner.initFlutterRoot();
19
    tempDir = fs.systemTempDirectory.createTempSync('analysis_test');
20 21 22 23 24 25 26
  });

  tearDown(() {
    tempDir?.deleteSync(recursive: true);
  });

  group('analyze', () {
27 28 29

    testUsingContext('inRepo', () {
      // Absolute paths
30 31 32 33
      expect(inRepo(<String>[tempDir.path]), isFalse);
      expect(inRepo(<String>[path.join(tempDir.path, 'foo')]), isFalse);
      expect(inRepo(<String>[Cache.flutterRoot]), isTrue);
      expect(inRepo(<String>[path.join(Cache.flutterRoot, 'foo')]), isTrue);
34
      // Relative paths
35
      String oldWorkingDirectory = fs.currentDirectory.path;
36
      try {
37
        fs.currentDirectory = Cache.flutterRoot;
38 39
        expect(inRepo(<String>['.']), isTrue);
        expect(inRepo(<String>['foo']), isTrue);
40
        fs.currentDirectory = tempDir.path;
41 42
        expect(inRepo(<String>['.']), isFalse);
        expect(inRepo(<String>['foo']), isFalse);
43
      } finally {
44
        fs.currentDirectory = oldWorkingDirectory;
45 46
      }
      // Ensure no exceptions
47 48
      inRepo(null);
      inRepo(<String>[]);
49
    });
50 51
  });
}