analyze_test.dart 1.56 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 6
import 'package:file/file.dart';
import 'package:file/memory.dart';
7
import 'package:flutter_tools/src/cache.dart';
8
import 'package:flutter_tools/src/commands/analyze_base.dart';
9

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

13 14
const String _kFlutterRoot = '/data/flutter';

15
void main() {
16
  FileSystem fs;
17 18 19
  Directory tempDir;

  setUp(() {
20
    fs = MemoryFileSystem();
21 22
    fs.directory(_kFlutterRoot).createSync(recursive: true);
    Cache.flutterRoot = _kFlutterRoot;
23 24 25 26 27
    tempDir = fs.systemTempDirectory.createTempSync('flutter_analysis_test.');
  });

  tearDown(() {
    tryToDelete(tempDir);
28 29 30
  });

  group('analyze', () {
31 32
    testUsingContext('inRepo', () {
      // Absolute paths
33
      expect(inRepo(<String>[tempDir.path]), isFalse);
34
      expect(inRepo(<String>[fs.path.join(tempDir.path, 'foo')]), isFalse);
35
      expect(inRepo(<String>[Cache.flutterRoot]), isTrue);
36
      expect(inRepo(<String>[fs.path.join(Cache.flutterRoot, 'foo')]), isTrue);
37

38
      // Relative paths
39 40 41 42 43 44 45
      fs.currentDirectory = Cache.flutterRoot;
      expect(inRepo(<String>['.']), isTrue);
      expect(inRepo(<String>['foo']), isTrue);
      fs.currentDirectory = tempDir.path;
      expect(inRepo(<String>['.']), isFalse);
      expect(inRepo(<String>['foo']), isFalse);

46
      // Ensure no exceptions
47 48
      inRepo(null);
      inRepo(<String>[]);
49 50
    }, overrides: <Type, Generator>{
      FileSystem: () => fs,
51
    });
52 53
  });
}