analyze_test.dart 1.51 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 'package:test/test.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 21 22
    fs = new MemoryFileSystem();
    fs.directory(_kFlutterRoot).createSync(recursive: true);
    Cache.flutterRoot = _kFlutterRoot;
23
    tempDir = fs.systemTempDirectory.createTempSync('analysis_test');
24 25 26
  });

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

34
      // Relative paths
35 36 37 38 39 40 41
      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);

42
      // Ensure no exceptions
43 44
      inRepo(null);
      inRepo(<String>[]);
45 46
    }, overrides: <Type, Generator>{
      FileSystem: () => fs,
47
    });
48 49
  });
}