dart-sdk/pkg/test_runner/test/options_test.dart
Robert Nystrom 3f7805a90e Make the NNBD command-line options less, uh, half-baked.
- Better name than "optedIn".
- Actually hook up the command-line option to the configuration.
- Add tests, which would have caught the previous mistake.
- Don't allow comma-separated values for "--progress" and "--nnbd".
- Remove unused dead "--strong" option.

Change-Id: I57d7cb0d81af50d662dcf3f7f4c9ca1f2b102f2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116544
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2019-09-10 22:39:19 +00:00

81 lines
2.8 KiB
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
import 'package:test_runner/src/configuration.dart';
import 'package:test_runner/src/options.dart';
void main() {
testDefaults();
testOptions();
testValidation();
}
void testDefaults() {
// TODO(rnystrom): Test other options.
var configuration = parseConfiguration([]);
Expect.equals(Progress.compact, configuration.progress);
Expect.equals(NnbdMode.legacy, configuration.nnbdMode);
}
void testOptions() {
// TODO(rnystrom): Test other options.
var configurations = parseConfigurations(['--mode=debug,release']);
Expect.equals(2, configurations.length);
Expect.equals(Mode.debug, configurations[0].mode);
Expect.equals(Mode.release, configurations[1].mode);
var configuration = parseConfiguration(['--nnbd=weak']);
Expect.equals(NnbdMode.weak, configuration.nnbdMode);
}
void testValidation() {
// TODO(rnystrom): Test other options.
expectValidationError(
['--timeout=notint'], 'Integer value expected for option "--timeout".');
expectValidationError(
['--timeout=1,2'], 'Integer value expected for option "--timeout".');
expectValidationError(['--progress=unknown'],
'Unknown value "unknown" for option "--progress".');
// Don't allow multiple.
expectValidationError(['--progress=compact,silent'],
'Only a single value is allowed for option "--progress".');
expectValidationError(
['--nnbd=unknown'], 'Unknown value "unknown" for option "--nnbd".');
// Don't allow multiple.
expectValidationError(['--nnbd=weak,strong'],
'Only a single value is allowed for option "--nnbd".');
}
TestConfiguration parseConfiguration(List<String> arguments) {
var configurations = parseConfigurations(arguments);
Expect.equals(1, configurations.length);
return configurations.first;
}
List<TestConfiguration> parseConfigurations(List<String> arguments) {
var parser = OptionsParser();
var configurations = parser.parse(arguments);
// By default, without an explicit selector, you get two configurations, one
// for observatory_ui, and one for all the other selectors. Discard the
// observatory one to keep things simpler.
configurations
.removeWhere((config) => config.selectors.containsKey('observatory_ui'));
return configurations;
}
void expectValidationError(List<String> arguments, String error) {
try {
OptionsParser().parse(arguments);
Expect.fail('Should have thrown an exception, but did not.');
} on OptionParseException catch (exception) {
Expect.equals(error, exception.message);
} catch (exception) {
Expect.fail('Wrong exception: $exception');
}
}