OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 @TestOn("vm") |
| 6 library analyzer_cli.test.options; |
| 7 |
| 8 import 'package:analyzer_cli/src/options.dart'; |
| 9 import 'package:args/args.dart'; |
| 10 import 'package:test/test.dart'; |
| 11 |
| 12 main() { |
| 13 group('CommandLineOptions', () { |
| 14 group('parse', () { |
| 15 test('defaults', () { |
| 16 CommandLineOptions options = |
| 17 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); |
| 18 expect(options, isNotNull); |
| 19 expect(options.dartSdkPath, isNotNull); |
| 20 expect(options.disableHints, isFalse); |
| 21 expect(options.lints, isFalse); |
| 22 expect(options.displayVersion, isFalse); |
| 23 expect(options.enableStrictCallChecks, isFalse); |
| 24 expect(options.enableSuperMixins, isFalse); |
| 25 expect(options.enableTypeChecks, isFalse); |
| 26 expect(options.hintsAreFatal, isFalse); |
| 27 expect(options.ignoreUnrecognizedFlags, isFalse); |
| 28 expect(options.log, isFalse); |
| 29 expect(options.machineFormat, isFalse); |
| 30 expect(options.packageRootPath, isNull); |
| 31 expect(options.shouldBatch, isFalse); |
| 32 expect(options.showPackageWarnings, isFalse); |
| 33 expect(options.showSdkWarnings, isFalse); |
| 34 expect(options.sourceFiles, equals(['foo.dart'])); |
| 35 expect(options.warningsAreFatal, isFalse); |
| 36 expect(options.strongMode, isFalse); |
| 37 }); |
| 38 |
| 39 test('batch', () { |
| 40 CommandLineOptions options = |
| 41 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); |
| 42 expect(options.shouldBatch, isTrue); |
| 43 }); |
| 44 |
| 45 test('defined variables', () { |
| 46 CommandLineOptions options = CommandLineOptions |
| 47 .parse(['--dart-sdk', '.', '-Dfoo=bar', 'foo.dart']); |
| 48 expect(options.definedVariables['foo'], equals('bar')); |
| 49 expect(options.definedVariables['bar'], isNull); |
| 50 }); |
| 51 |
| 52 test('enable strict call checks', () { |
| 53 CommandLineOptions options = CommandLineOptions.parse( |
| 54 ['--dart-sdk', '.', '--enable-strict-call-checks', 'foo.dart']); |
| 55 expect(options.enableStrictCallChecks, isTrue); |
| 56 }); |
| 57 |
| 58 test('enable super mixins', () { |
| 59 CommandLineOptions options = CommandLineOptions |
| 60 .parse(['--dart-sdk', '.', '--supermixin', 'foo.dart']); |
| 61 expect(options.enableSuperMixins, isTrue); |
| 62 }); |
| 63 |
| 64 test('enable type checks', () { |
| 65 CommandLineOptions options = CommandLineOptions |
| 66 .parse(['--dart-sdk', '.', '--enable_type_checks', 'foo.dart']); |
| 67 expect(options.enableTypeChecks, isTrue); |
| 68 }); |
| 69 |
| 70 test('hintsAreFatal', () { |
| 71 CommandLineOptions options = CommandLineOptions |
| 72 .parse(['--dart-sdk', '.', '--fatal-hints', 'foo.dart']); |
| 73 expect(options.hintsAreFatal, isTrue); |
| 74 }); |
| 75 |
| 76 test('log', () { |
| 77 CommandLineOptions options = |
| 78 CommandLineOptions.parse(['--dart-sdk', '.', '--log', 'foo.dart']); |
| 79 expect(options.log, isTrue); |
| 80 }); |
| 81 |
| 82 test('machine format', () { |
| 83 CommandLineOptions options = CommandLineOptions |
| 84 .parse(['--dart-sdk', '.', '--format=machine', 'foo.dart']); |
| 85 expect(options.machineFormat, isTrue); |
| 86 }); |
| 87 |
| 88 test('no-hints', () { |
| 89 CommandLineOptions options = CommandLineOptions |
| 90 .parse(['--dart-sdk', '.', '--no-hints', 'foo.dart']); |
| 91 expect(options.disableHints, isTrue); |
| 92 }); |
| 93 |
| 94 test('options', () { |
| 95 CommandLineOptions options = CommandLineOptions.parse( |
| 96 ['--dart-sdk', '.', '--options', 'options.yaml', 'foo.dart']); |
| 97 expect(options.analysisOptionsFile, equals('options.yaml')); |
| 98 }); |
| 99 |
| 100 test('lints', () { |
| 101 CommandLineOptions options = CommandLineOptions |
| 102 .parse(['--dart-sdk', '.', '--lints', 'foo.dart']); |
| 103 expect(options.lints, isTrue); |
| 104 }); |
| 105 |
| 106 test('package root', () { |
| 107 CommandLineOptions options = CommandLineOptions |
| 108 .parse(['--dart-sdk', '.', '-p', 'bar', 'foo.dart']); |
| 109 expect(options.packageRootPath, equals('bar')); |
| 110 }); |
| 111 |
| 112 test('package warnings', () { |
| 113 CommandLineOptions options = CommandLineOptions |
| 114 .parse(['--dart-sdk', '.', '--package-warnings', 'foo.dart']); |
| 115 expect(options.showPackageWarnings, isTrue); |
| 116 }); |
| 117 |
| 118 test('sdk warnings', () { |
| 119 CommandLineOptions options = CommandLineOptions |
| 120 .parse(['--dart-sdk', '.', '--warnings', 'foo.dart']); |
| 121 expect(options.showSdkWarnings, isTrue); |
| 122 }); |
| 123 |
| 124 test('sourceFiles', () { |
| 125 CommandLineOptions options = CommandLineOptions.parse( |
| 126 ['--dart-sdk', '.', '--log', 'foo.dart', 'foo2.dart', 'foo3.dart']); |
| 127 expect(options.sourceFiles, |
| 128 equals(['foo.dart', 'foo2.dart', 'foo3.dart'])); |
| 129 }); |
| 130 |
| 131 test('warningsAreFatal', () { |
| 132 CommandLineOptions options = CommandLineOptions |
| 133 .parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.dart']); |
| 134 expect(options.warningsAreFatal, isTrue); |
| 135 }); |
| 136 |
| 137 test('notice unrecognized flags', () { |
| 138 expect( |
| 139 () => new CommandLineParser() |
| 140 .parse(['--bar', '--baz', 'foo.dart'], {}), |
| 141 throwsA(new isInstanceOf<FormatException>())); |
| 142 }); |
| 143 |
| 144 test('ignore unrecognized flags', () { |
| 145 CommandLineOptions options = CommandLineOptions.parse([ |
| 146 '--ignore-unrecognized-flags', |
| 147 '--bar', |
| 148 '--baz', |
| 149 '--dart-sdk', |
| 150 '.', |
| 151 'foo.dart' |
| 152 ]); |
| 153 expect(options, isNotNull); |
| 154 expect(options.sourceFiles, equals(['foo.dart'])); |
| 155 }); |
| 156 |
| 157 test('ignore unrecognized options', () { |
| 158 CommandLineParser parser = |
| 159 new CommandLineParser(alwaysIgnoreUnrecognized: true); |
| 160 parser.addOption('optionA'); |
| 161 parser.addFlag('flagA'); |
| 162 ArgResults argResults = |
| 163 parser.parse(['--optionA=1', '--optionB=2', '--flagA'], {}); |
| 164 expect(argResults['optionA'], '1'); |
| 165 expect(argResults['flagA'], isTrue); |
| 166 }); |
| 167 |
| 168 test('strong mode', () { |
| 169 CommandLineOptions options = CommandLineOptions |
| 170 .parse(['--strong', 'foo.dart']); |
| 171 expect(options.strongMode, isTrue); |
| 172 }); |
| 173 |
| 174 test("can't specify package and package-root", () { |
| 175 var failureMessage; |
| 176 CommandLineOptions.parse( |
| 177 ['--package-root', '.', '--packages', '.', 'foo.dart'], |
| 178 (msg) => failureMessage = msg); |
| 179 expect(failureMessage, |
| 180 equals("Cannot specify both '--package-root' and '--packages.")); |
| 181 }); |
| 182 |
| 183 test("bad SDK dir", () { |
| 184 var failureMessage; |
| 185 CommandLineOptions.parse( |
| 186 ['--dart-sdk', '&&&&&', 'foo.dart'], (msg) => failureMessage = msg); |
| 187 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); |
| 188 }); |
| 189 }); |
| 190 }); |
| 191 } |
OLD | NEW |