analyze_test.dart 1.55 KB
Newer Older
1 2 3 4 5 6
// 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.

import 'dart:io';

7
import 'package:flutter_tools/src/cache.dart';
8
import 'package:flutter_tools/src/commands/analyze_base.dart';
9
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
10 11 12 13 14
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'src/context.dart';

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

  setUp(() {
19
    FlutterCommandRunner.initFlutterRoot();
20 21 22 23 24 25 26 27
    tempDir = Directory.systemTemp.createTempSync('analysis_test');
  });

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

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

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