| 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 @TestOn("vm") | 5 @TestOn("vm") |
| 6 | |
| 7 library analyzer_cli.test.options; | 6 library analyzer_cli.test.options; |
| 8 | 7 |
| 9 import 'package:analyzer_cli/src/options.dart'; | 8 import 'package:analyzer_cli/src/options.dart'; |
| 10 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 11 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 12 | 11 |
| 13 main() { | 12 main() { |
| 14 group('CommandLineOptions', () { | 13 group('CommandLineOptions', () { |
| 15 group('parse', () { | 14 group('parse', () { |
| 16 test('defaults', () { | 15 test('defaults', () { |
| 17 CommandLineOptions options = | 16 CommandLineOptions options = |
| 18 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); | 17 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); |
| 19 expect(options, isNotNull); | 18 expect(options, isNotNull); |
| 20 expect(options.dartSdkPath, isNotNull); | 19 expect(options.dartSdkPath, isNotNull); |
| 21 expect(options.disableHints, isFalse); | 20 expect(options.disableHints, isFalse); |
| 22 expect(options.lints, isFalse); | 21 expect(options.lints, isFalse); |
| 23 expect(options.displayVersion, isFalse); | 22 expect(options.displayVersion, isFalse); |
| 24 expect(options.enableStrictCallChecks, isFalse); | 23 expect(options.enableStrictCallChecks, isFalse); |
| 25 expect(options.enableSuperMixins, isFalse); | 24 expect(options.enableSuperMixins, isFalse); |
| 26 expect(options.enableTypeChecks, isFalse); | 25 expect(options.enableTypeChecks, isFalse); |
| 27 expect(options.ignoreUnrecognizedFlags, isFalse); | 26 expect(options.ignoreUnrecognizedFlags, isFalse); |
| 28 expect(options.log, isFalse); | 27 expect(options.log, isFalse); |
| 29 expect(options.machineFormat, isFalse); | 28 expect(options.machineFormat, isFalse); |
| 30 expect(options.packageRootPath, isNull); | 29 expect(options.packageRootPath, isNull); |
| 31 expect(options.shouldBatch, isFalse); | 30 expect(options.shouldBatch, isFalse); |
| 32 expect(options.showPackageWarnings, isFalse); | 31 expect(options.showPackageWarnings, isFalse); |
| 33 expect(options.showSdkWarnings, isFalse); | 32 expect(options.showSdkWarnings, isFalse); |
| 34 expect(options.sourceFiles, equals(['foo.dart'])); | 33 expect(options.sourceFiles, equals(['foo.dart'])); |
| 35 expect(options.warningsAreFatal, isFalse); | 34 expect(options.warningsAreFatal, isFalse); |
| 36 expect(options.customUrlMappings, isNotNull); | |
| 37 expect(options.customUrlMappings.isEmpty, isTrue); | |
| 38 expect(options.strongMode, isFalse); | 35 expect(options.strongMode, isFalse); |
| 39 }); | 36 }); |
| 40 | 37 |
| 41 test('batch', () { | 38 test('batch', () { |
| 42 CommandLineOptions options = | 39 CommandLineOptions options = |
| 43 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); | 40 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); |
| 44 expect(options.shouldBatch, isTrue); | 41 expect(options.shouldBatch, isTrue); |
| 45 }); | 42 }); |
| 46 | 43 |
| 47 test('defined variables', () { | 44 test('defined variables', () { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 expect(options.sourceFiles, | 120 expect(options.sourceFiles, |
| 124 equals(['foo.dart', 'foo2.dart', 'foo3.dart'])); | 121 equals(['foo.dart', 'foo2.dart', 'foo3.dart'])); |
| 125 }); | 122 }); |
| 126 | 123 |
| 127 test('warningsAreFatal', () { | 124 test('warningsAreFatal', () { |
| 128 CommandLineOptions options = CommandLineOptions | 125 CommandLineOptions options = CommandLineOptions |
| 129 .parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.dart']); | 126 .parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.dart']); |
| 130 expect(options.warningsAreFatal, isTrue); | 127 expect(options.warningsAreFatal, isTrue); |
| 131 }); | 128 }); |
| 132 | 129 |
| 133 test('customUrlMappings', () { | |
| 134 CommandLineOptions options = CommandLineOptions.parse([ | |
| 135 '--dart-sdk', | |
| 136 '.', | |
| 137 '--url-mapping', | |
| 138 'dart:dummy,/path/to/dummy.dart', | |
| 139 'foo.dart' | |
| 140 ]); | |
| 141 expect(options.customUrlMappings, isNotNull); | |
| 142 expect(options.customUrlMappings.isEmpty, isFalse); | |
| 143 expect(options.customUrlMappings['dart:dummy'], | |
| 144 equals('/path/to/dummy.dart')); | |
| 145 }); | |
| 146 | |
| 147 test('notice unrecognized flags', () { | 130 test('notice unrecognized flags', () { |
| 148 expect(() => new CommandLineParser().parse( | 131 expect( |
| 149 ['--bar', '--baz', 'foo.dart'], {}), | 132 () => new CommandLineParser() |
| 133 .parse(['--bar', '--baz', 'foo.dart'], {}), |
| 150 throwsA(new isInstanceOf<FormatException>())); | 134 throwsA(new isInstanceOf<FormatException>())); |
| 151 }); | 135 }); |
| 152 | 136 |
| 153 test('ignore unrecognized flags', () { | 137 test('ignore unrecognized flags', () { |
| 154 CommandLineOptions options = CommandLineOptions.parse([ | 138 CommandLineOptions options = CommandLineOptions.parse([ |
| 155 '--ignore-unrecognized-flags', | 139 '--ignore-unrecognized-flags', |
| 156 '--bar', | 140 '--bar', |
| 157 '--baz', | 141 '--baz', |
| 158 '--dart-sdk', | 142 '--dart-sdk', |
| 159 '.', | 143 '.', |
| (...skipping 16 matching lines...) Expand all Loading... |
| 176 | 160 |
| 177 test('strong mode', () { | 161 test('strong mode', () { |
| 178 CommandLineOptions options = CommandLineOptions | 162 CommandLineOptions options = CommandLineOptions |
| 179 .parse(['--strong', '--strong-hints', 'foo.dart']); | 163 .parse(['--strong', '--strong-hints', 'foo.dart']); |
| 180 expect(options.strongMode, isTrue); | 164 expect(options.strongMode, isTrue); |
| 181 expect(options.strongHints, isTrue); | 165 expect(options.strongHints, isTrue); |
| 182 }); | 166 }); |
| 183 | 167 |
| 184 test("can't specify package and package-root", () { | 168 test("can't specify package and package-root", () { |
| 185 var failureMessage; | 169 var failureMessage; |
| 186 CommandLineOptions.parse([ | 170 CommandLineOptions.parse( |
| 187 '--package-root', | 171 ['--package-root', '.', '--packages', '.', 'foo.dart'], |
| 188 '.', | 172 (msg) => failureMessage = msg); |
| 189 '--packages', | |
| 190 '.', | |
| 191 'foo.dart' | |
| 192 ], (msg) => failureMessage = msg); | |
| 193 expect(failureMessage, | 173 expect(failureMessage, |
| 194 equals("Cannot specify both '--package-root' and '--packages.")); | 174 equals("Cannot specify both '--package-root' and '--packages.")); |
| 195 }); | 175 }); |
| 196 | 176 |
| 197 test("bad SDK dir", () { | 177 test("bad SDK dir", () { |
| 198 var failureMessage; | 178 var failureMessage; |
| 199 CommandLineOptions.parse( | 179 CommandLineOptions.parse( |
| 200 ['--dart-sdk', '&&&&&', 'foo.dart'], (msg) => failureMessage = msg); | 180 ['--dart-sdk', '&&&&&', 'foo.dart'], (msg) => failureMessage = msg); |
| 201 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); | 181 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); |
| 202 }); | 182 }); |
| 203 }); | 183 }); |
| 204 }); | 184 }); |
| 205 } | 185 } |
| OLD | NEW |