Skip to content

Commit e6b82b6

Browse files
committed
flutter analyze test
Test that flutter analyze catches no error if two imported libraries have the same name. Also, make tests know how to find the flutter root and fix style in one test to be consistent with the rest of the file.
1 parent b9f28e6 commit e6b82b6

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

packages/flutter_tools/lib/src/runner/flutter_command_runner.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,17 @@ class FlutterCommandRunner extends CommandRunner {
150150
if (Platform.environment.containsKey(kFlutterRootEnvironmentVariableName))
151151
return Platform.environment[kFlutterRootEnvironmentVariableName];
152152
try {
153+
if (Platform.script.scheme == 'data')
154+
return '../..'; // we're running as a test
153155
String script = Platform.script.toFilePath();
154156
if (path.basename(script) == kSnapshotFileName)
155157
return path.dirname(path.dirname(path.dirname(script)));
156158
if (path.basename(script) == kFlutterToolsScriptFileName)
157159
return path.dirname(path.dirname(path.dirname(path.dirname(script))));
158160
} catch (error) {
159-
printTrace('Unable to locate fluter root: $error');
161+
// we don't have a logger at the time this is run
162+
// (which is why we don't use printTrace here)
163+
print('Unable to locate flutter root: $error');
160164
}
161165
return '.';
162166
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

packages/flutter_tools/test/drive_test.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ void main() {
6868
return createTestCommandRunner(command).run(args).then((int code) {
6969
expect(code, equals(1));
7070
BufferLogger buffer = logger;
71-
expect(buffer.errorText,
72-
contains('Test file not found: /some/app/test_driver/e2e_test.dart'));
71+
expect(buffer.errorText, contains(
72+
'Test file not found: /some/app/test_driver/e2e_test.dart'
73+
));
7374
});
7475
});
7576

0 commit comments

Comments
 (0)