OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(nweiz): This is under lib so that it can be used by the unittest dummy | 5 // TODO(nweiz): This is under lib so that it can be used by the unittest dummy |
6 // package. Once that package is no longer being updated, move this back into | 6 // package. Once that package is no longer being updated, move this back into |
7 // bin. | 7 // bin. |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
| 10 import 'package:path/path.dart' as p; |
10 import 'package:source_span/source_span.dart'; | 11 import 'package:source_span/source_span.dart'; |
11 import 'package:stack_trace/stack_trace.dart'; | 12 import 'package:stack_trace/stack_trace.dart'; |
12 import 'package:yaml/yaml.dart'; | 13 import 'package:yaml/yaml.dart'; |
13 | 14 |
14 import 'runner.dart'; | 15 import 'runner.dart'; |
15 import 'runner/application_exception.dart'; | 16 import 'runner/application_exception.dart'; |
16 import 'runner/configuration.dart'; | 17 import 'runner/configuration.dart'; |
17 import 'runner/version.dart'; | 18 import 'runner/version.dart'; |
18 import 'util/exit_codes.dart' as exit_codes; | 19 import 'util/exit_codes.dart' as exit_codes; |
19 import 'util/io.dart'; | 20 import 'util/io.dart'; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 if (transformers is! List) return false; | 53 if (transformers is! List) return false; |
53 | 54 |
54 return transformers.any((transformer) { | 55 return transformers.any((transformer) { |
55 if (transformer is String) return transformer == 'test/pub_serve'; | 56 if (transformer is String) return transformer == 'test/pub_serve'; |
56 if (transformer is! Map) return false; | 57 if (transformer is! Map) return false; |
57 if (transformer.keys.length != 1) return false; | 58 if (transformer.keys.length != 1) return false; |
58 return transformer.keys.single == 'test/pub_serve'; | 59 return transformer.keys.single == 'test/pub_serve'; |
59 }); | 60 }); |
60 } | 61 } |
61 | 62 |
| 63 /// Returns the path to the global test configuration file. |
| 64 final String _globalConfigPath = (){ |
| 65 if (Platform.environment.containsKey('DART_TEST_CONFIG')) { |
| 66 return Platform.environment['DART_TEST_CONFIG']; |
| 67 } else if (Platform.operatingSystem == 'windows') { |
| 68 return p.join(Platform.environment['LOCALAPPDATA'], 'DartTest.yaml'); |
| 69 } else { |
| 70 return '${Platform.environment['HOME']}/.dart_test.yaml'; |
| 71 } |
| 72 }(); |
| 73 |
62 main(List<String> args) async { | 74 main(List<String> args) async { |
63 var configuration; | 75 var configuration; |
64 try { | 76 try { |
65 configuration = new Configuration.parse(args); | 77 configuration = new Configuration.parse(args); |
66 } on FormatException catch (error) { | 78 } on FormatException catch (error) { |
67 _printUsage(error.message); | 79 _printUsage(error.message); |
68 exitCode = exit_codes.usage; | 80 exitCode = exit_codes.usage; |
69 return; | 81 return; |
70 } | 82 } |
71 | 83 |
72 if (configuration.help) { | 84 if (configuration.help) { |
73 _printUsage(); | 85 _printUsage(); |
74 return; | 86 return; |
75 } | 87 } |
76 | 88 |
77 if (configuration.version) { | 89 if (configuration.version) { |
78 var version = testVersion; | 90 var version = testVersion; |
79 if (version == null) { | 91 if (version == null) { |
80 stderr.writeln("Couldn't find version number."); | 92 stderr.writeln("Couldn't find version number."); |
81 exitCode = exit_codes.data; | 93 exitCode = exit_codes.data; |
82 } else { | 94 } else { |
83 print(version); | 95 print(version); |
84 } | 96 } |
85 return; | 97 return; |
86 } | 98 } |
87 | 99 |
88 try { | 100 try { |
| 101 var fileConfiguration = Configuration.empty; |
| 102 if (new File(_globalConfigPath).existsSync()) { |
| 103 fileConfiguration = fileConfiguration.merge( |
| 104 new Configuration.load(_globalConfigPath, global: true)); |
| 105 } |
| 106 |
89 if (new File("dart_test.yaml").existsSync()) { | 107 if (new File("dart_test.yaml").existsSync()) { |
90 var fileConfiguration = new Configuration.load("dart_test.yaml"); | 108 fileConfiguration = fileConfiguration.merge( |
91 configuration = fileConfiguration.merge(configuration); | 109 new Configuration.load("dart_test.yaml")); |
92 } | 110 } |
| 111 |
| 112 configuration = fileConfiguration.merge(configuration); |
93 } on SourceSpanFormatException catch (error) { | 113 } on SourceSpanFormatException catch (error) { |
94 stderr.writeln(error.toString(color: configuration.color)); | 114 stderr.writeln(error.toString(color: configuration.color)); |
95 exitCode = exit_codes.data; | 115 exitCode = exit_codes.data; |
96 return; | 116 return; |
97 } on FormatException catch (error) { | 117 } on FormatException catch (error) { |
98 stderr.writeln(error.message); | 118 stderr.writeln(error.message); |
99 exitCode = exit_codes.data; | 119 exitCode = exit_codes.data; |
100 return; | 120 return; |
101 } on IOException catch (error) { | 121 } on IOException catch (error) { |
102 stderr.writeln(error.toString()); | 122 stderr.writeln(error.toString()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 output = stderr; | 200 output = stderr; |
181 } | 201 } |
182 | 202 |
183 output.write("""${wordWrap(message)} | 203 output.write("""${wordWrap(message)} |
184 | 204 |
185 Usage: pub run test [files or directories...] | 205 Usage: pub run test [files or directories...] |
186 | 206 |
187 ${Configuration.usage} | 207 ${Configuration.usage} |
188 """); | 208 """); |
189 } | 209 } |
OLD | NEW |