| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, 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 library analyzer.test.src.command_line.command_line_parser_test; | |
| 6 | |
| 7 import 'package:analyzer/src/command_line/command_line_parser.dart'; | |
| 8 import 'package:args/args.dart'; | |
| 9 import 'package:test/test.dart'; | |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 11 | |
| 12 main() { | |
| 13 defineReflectiveSuite(() { | |
| 14 defineReflectiveTests(CommandLineParserTest); | |
| 15 }); | |
| 16 } | |
| 17 | |
| 18 @reflectiveTest | |
| 19 class CommandLineParserTest { | |
| 20 void test_usage() { | |
| 21 CommandLineParser parser = new CommandLineParser(); | |
| 22 parser.addOption('bar'); | |
| 23 String usage = parser.parser.usage; | |
| 24 expect(usage, contains('--bar')); | |
| 25 expect(usage, contains(CommandLineParser.IGNORE_UNRECOGNIZED_FLAG)); | |
| 26 } | |
| 27 | |
| 28 void test_unrecognizedFlags1() { | |
| 29 CommandLineParser parser = new CommandLineParser(); | |
| 30 expect(() { | |
| 31 return parser.parse(['--bar', '--baz', 'foo.dart']); | |
| 32 }, throwsA(new isInstanceOf<FormatException>())); | |
| 33 } | |
| 34 | |
| 35 void test_unrecognizedFlags2() { | |
| 36 CommandLineParser parser = new CommandLineParser(); | |
| 37 parser.addFlag('bar'); | |
| 38 expect(() { | |
| 39 return parser.parse(['--bar', '--baz', 'foo.dart']); | |
| 40 }, throwsA(new isInstanceOf<FormatException>())); | |
| 41 } | |
| 42 | |
| 43 void test_unrecognizedFlags_ignore() { | |
| 44 CommandLineParser parser = | |
| 45 new CommandLineParser(alwaysIgnoreUnrecognized: true); | |
| 46 parser.addOption('optA'); | |
| 47 parser.addOption('optB'); | |
| 48 parser.addOption('optG'); | |
| 49 parser.addFlag('flagA'); | |
| 50 ArgResults argResults = parser.parse([ | |
| 51 '--optA=1', | |
| 52 '--optB', | |
| 53 '2', | |
| 54 '--optC=3', | |
| 55 '--flagA', | |
| 56 '--optD', | |
| 57 '4', | |
| 58 '5', | |
| 59 '--optG=9', | |
| 60 '--optH=10' | |
| 61 ]); | |
| 62 expect(argResults['optA'], '1'); | |
| 63 expect(argResults['optB'], '2'); | |
| 64 expect(argResults['optG'], '9'); | |
| 65 expect(argResults['flagA'], isTrue); | |
| 66 expect(() { | |
| 67 return argResults['optC']; | |
| 68 }, throwsA(new isInstanceOf<ArgumentError>())); | |
| 69 expect(() { | |
| 70 return argResults['optD']; | |
| 71 }, throwsA(new isInstanceOf<ArgumentError>())); | |
| 72 expect(argResults.rest, orderedEquals(<String>['4', '5'])); | |
| 73 } | |
| 74 } | |
| OLD | NEW |