|
| 1 | +// Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:io'; |
| 6 | + |
| 7 | +import 'package:flutter_tools/src/base/os.dart'; |
| 8 | +import 'package:flutter_tools/src/commands/analyze.dart'; |
| 9 | +import 'package:path/path.dart' as path; |
| 10 | +import 'package:test/test.dart'; |
| 11 | + |
| 12 | +import 'src/common.dart'; |
| 13 | +import 'src/context.dart'; |
| 14 | +import 'src/mocks.dart'; |
| 15 | + |
| 16 | +void main() { |
| 17 | + Directory tempDir; |
| 18 | + |
| 19 | + setUp(() { |
| 20 | + tempDir = Directory.systemTemp.createTempSync('analysis_duplicate_names_test'); |
| 21 | + }); |
| 22 | + |
| 23 | + tearDown(() { |
| 24 | + tempDir?.deleteSync(recursive: true); |
| 25 | + }); |
| 26 | + |
| 27 | + group('analyze', () { |
| 28 | + testUsingContext('flutter analyze with two files with the same name', () async { |
| 29 | + |
| 30 | + File dartFileA = new File(path.join(tempDir.path, 'a.dart')); |
| 31 | + dartFileA.parent.createSync(); |
| 32 | + dartFileA.writeAsStringSync('library test;'); |
| 33 | + File dartFileB = new File(path.join(tempDir.path, 'b.dart')); |
| 34 | + dartFileB.writeAsStringSync('library test;'); |
| 35 | + |
| 36 | + AnalyzeCommand command = new AnalyzeCommand(); |
| 37 | + applyMocksToCommand(command); |
| 38 | + return createTestCommandRunner(command).run(['analyze', '--no-current-package', '--no-current-directory', dartFileA.path, dartFileB.path]).then((int code) { |
| 39 | + expect(code, equals(1)); |
| 40 | + expect(testLogger.errorText, '[warning] The imported libraries \'a.dart\' and \'b.dart\' cannot have the same name \'test\' (${dartFileB.path})\n'); |
| 41 | + expect(testLogger.statusText, 'Analyzing 2 entry points...\n'); |
| 42 | + }); |
| 43 | + |
| 44 | + }, overrides: <Type, dynamic>{ |
| 45 | + OperatingSystemUtils: os |
| 46 | + }); |
| 47 | + }); |
| 48 | +} |
0 commit comments