dart_dependencies_test.dart 4.03 KB
Newer Older
1 2 3 4 5
// 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 'package:flutter_tools/src/dart/dependencies.dart';
6
import 'package:flutter_tools/src/base/file_system.dart';
7
import 'package:test/test.dart';
8 9

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

12
void main() {
13
  group('DartDependencySetBuilder', () {
14 15 16 17 18 19 20 21 22
    final String dataPath = fs.path.join(
      getFlutterRoot(),
      'packages',
      'flutter_tools',
      'test',
      'data',
      'dart_dependencies_test',
    );

23
    testUsingContext('good', () {
24 25 26
      final String testPath = fs.path.join(dataPath, 'good');
      final String mainPath = fs.path.join(testPath, 'main.dart');
      final String packagesPath = fs.path.join(testPath, '.packages');
27
      final DartDependencySetBuilder builder =
28
          new DartDependencySetBuilder(mainPath, packagesPath);
29
      final Set<String> dependencies = builder.build();
30 31
      expect(dependencies.contains(canonicalizePath(mainPath)), isTrue);
      expect(dependencies.contains(canonicalizePath(fs.path.join(testPath, 'foo.dart'))), isTrue);
32
    });
33

34
    testUsingContext('syntax_error', () {
35 36 37
      final String testPath = fs.path.join(dataPath, 'syntax_error');
      final String mainPath = fs.path.join(testPath, 'main.dart');
      final String packagesPath = fs.path.join(testPath, '.packages');
38
      final DartDependencySetBuilder builder =
39
          new DartDependencySetBuilder(mainPath, packagesPath);
40 41
      try {
        builder.build();
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        fail('expect an exception to be thrown.');
      } on DartDependencyException catch (error) {
        expect(error.toString(), contains('foo.dart: Expected a string literal'));
      }
    });

    testUsingContext('bad_path', () {
      final String testPath = fs.path.join(dataPath, 'bad_path');
      final String mainPath = fs.path.join(testPath, 'main.dart');
      final String packagesPath = fs.path.join(testPath, '.packages');
      final DartDependencySetBuilder builder =
          new DartDependencySetBuilder(mainPath, packagesPath);
      try {
        builder.build();
        fail('expect an exception to be thrown.');
      } on DartDependencyException catch (error) {
        expect(error.toString(), contains('amaze${fs.path.separator}and${fs.path.separator}astonish.dart'));
      }
    });

    testUsingContext('bad_package', () {
      final String testPath = fs.path.join(dataPath, 'bad_package');
      final String mainPath = fs.path.join(testPath, 'main.dart');
      final String packagesPath = fs.path.join(testPath, '.packages');
      final DartDependencySetBuilder builder =
          new DartDependencySetBuilder(mainPath, packagesPath);
      try {
        builder.build();
        fail('expect an exception to be thrown.');
      } on DartDependencyException catch (error) {
        expect(error.toString(), contains('rochambeau'));
        expect(error.toString(), contains('pubspec.yaml'));
74 75
      }
    });
76

77
    testUsingContext('does not change ASCII casing of path', () {
78 79 80 81 82 83 84
      final String testPath = fs.path.join(dataPath, 'asci_casing');
      final String mainPath = fs.path.join(testPath, 'main.dart');
      final String packagesPath = fs.path.join(testPath, '.packages');
      final DartDependencySetBuilder builder = new DartDependencySetBuilder(mainPath, packagesPath);
      final Set<String> deps = builder.build();
      expect(deps, contains(endsWith('This_Import_Has_fuNNy_casING.dart')));
    });
85 86 87 88 89 90 91 92 93 94 95 96 97 98

    testUsingContext('bad_import', () {
      final String testPath = fs.path.join(dataPath, 'bad_import');
      final String mainPath = fs.path.join(testPath, 'main.dart');
      final String packagesPath = fs.path.join(testPath, '.packages');
      final DartDependencySetBuilder builder =
          new DartDependencySetBuilder(mainPath, packagesPath);
      try {
        builder.build();
        fail('expect an exception to be thrown.');
      } on DartDependencyException catch (error) {
        expect(error.toString(), contains('Unable to parse URI'));
      }
    });
99
  });
100
}