format_test.dart 1.31 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:args/command_runner.dart';
6
import 'package:flutter_tools/src/base/file_system.dart';
7 8 9 10
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/format.dart';
import 'package:test/test.dart';

11 12
import '../src/common.dart';
import '../src/context.dart';
13 14 15 16 17 18 19

void main() {
  group('format', () {
    Directory temp;

    setUp(() {
      Cache.disableLocking();
20
      temp = fs.systemTempDirectory.createTempSync('flutter_tools');
21 22 23 24 25 26 27
    });

    tearDown(() {
      temp.deleteSync(recursive: true);
    });

    testUsingContext('a file', () async {
28
      final String projectPath = await createProject(temp);
29

30
      final File srcFile = fs.file(fs.path.join(projectPath, 'lib', 'main.dart'));
31
      final String original = srcFile.readAsStringSync();
32 33
      srcFile.writeAsStringSync(original.replaceFirst('main()', 'main(  )'));

34 35
      final FormatCommand command = new FormatCommand();
      final CommandRunner<Null> runner = createTestCommandRunner(command);
36
      await runner.run(<String>['format', srcFile.path]);
37

38
      final String formatted = srcFile.readAsStringSync();
39 40 41 42
      expect(formatted, original);
    });
  });
}