exceptions_test.dart 2.59 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// 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/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/exceptions.dart';
8
import 'package:flutter_tools/src/globals.dart' as globals;
9

10
import '../../src/common.dart';
11 12 13 14

void main() {
  test('Exceptions', () {
    final MissingInputException missingInputException = MissingInputException(
15
        <File>[globals.fs.file('foo'), globals.fs.file('bar')], 'example');
16 17 18
    final CycleException cycleException = CycleException(<Target>{
      TestTarget()..name = 'foo',
      TestTarget()..name = 'bar',
19 20 21 22 23
    });
    final InvalidPatternException invalidPatternException = InvalidPatternException(
      'ABC'
    );
    final MissingOutputException missingOutputException = MissingOutputException(
24
      <File>[ globals.fs.file('foo'), globals.fs.file('bar') ],
25
      'example',
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    );
    final MisplacedOutputException misplacedOutputException = MisplacedOutputException(
      'foo',
      'example',
    );
    final MissingDefineException missingDefineException = MissingDefineException(
      'foobar',
      'example',
    );

    expect(
        missingInputException.toString(),
        'foo, bar were declared as an inputs, '
        'but did not exist. Check the definition of target:example for errors');
    expect(
        cycleException.toString(),
42
        'Dependency cycle detected in build: foo -> bar',
43 44 45
    );
    expect(
        invalidPatternException.toString(),
46
        'The pattern "ABC" is not valid',
47 48 49 50
    );
    expect(
        missingOutputException.toString(),
        'foo, bar were declared as outputs, but were not generated by the '
51
        'action. Check the definition of target:example for errors',
52 53 54 55 56 57 58 59
    );
    expect(
        misplacedOutputException.toString(),
        'Target example produced an output at foo which is outside of the '
        'current build or project directory',
    );
    expect(
        missingDefineException.toString(),
60
        'Target example required define foobar but it was not provided',
61 62 63
    );
  });
}
64 65 66 67

class TestTarget extends Target {
  TestTarget([this._build]);

68
  final Future<void> Function(Environment environment) _build;
69 70

  @override
71
  Future<void> build(Environment environment) => _build(environment);
72 73 74 75 76 77 78 79 80 81 82 83 84

  @override
  List<Target> dependencies = <Target>[];

  @override
  List<Source> inputs = <Source>[];

  @override
  String name = 'test';

  @override
  List<Source> outputs = <Source>[];
}