Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter error display tests #1895

Merged
merged 6 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ Future<void> main(List<String> arguments) async {
// TODO(jcollins-g): use exit once dart-lang/sdk#31747 is fixed.
exitCode = 64;
return;
} on DartdocOptionError catch (e) {
stderr.writeln(' fatal error: ${e.message}');
stderr.writeln('');
_printUsage(optionSet.argParser);
exitCode = 64;
return;
}
if (optionSet['help'].valueAt(Directory.current)) {
_printHelp(optionSet.argParser);
Expand All @@ -75,8 +69,17 @@ Future<void> main(List<String> arguments) async {
return;
}

DartdocProgramOptionContext config =
new DartdocProgramOptionContext(optionSet, null);
DartdocProgramOptionContext config;
try {
config = new DartdocProgramOptionContext(optionSet, null);
} on DartdocOptionError catch (e) {
stderr.writeln(' fatal error: ${e.message}');
stderr.writeln('');
await stderr.flush();
_printUsage(optionSet.argParser);
exitCode = 64;
return;
}
startLogging(config);

Directory outputDir = new Directory(config.output);
Expand Down
37 changes: 37 additions & 0 deletions test/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,43 @@ void main() {
await Future.wait(CoverageSubprocessLauncher.coverageResults);
});

test('invalid parameters return non-zero and print a fatal-error',
() async {
List outputLines = [];
await expectLater(
() => subprocessLauncher.runStreamed(
Platform.resolvedExecutable,
[
dartdocPath,
'--nonexisting',
],
perLine: outputLines.add),
throwsA(const TypeMatcher<ProcessException>()));
expect(
outputLines.firstWhere((l) => l.startsWith(' fatal')),
equals(
' fatal error: Could not find an option named "nonexisting".'));
});

test('missing a required file path prints a fatal-error', () async {
List outputLines = [];
String impossiblePath = pathLib.join(dartdocPath, 'impossible');
await expectLater(
() => subprocessLauncher.runStreamed(
Platform.resolvedExecutable,
[
dartdocPath,
'--input',
impossiblePath,
],
perLine: outputLines.add),
throwsA(const TypeMatcher<ProcessException>()));
expect(
outputLines.firstWhere((l) => l.startsWith(' fatal')),
startsWith(
' fatal error: Argument --input, set to ${impossiblePath}, resolves to missing path: '));
});

test('errors cause non-zero exit when warnings are off', () async {
expect(
() => subprocessLauncher.runStreamed(Platform.resolvedExecutable, [
Expand Down
5 changes: 3 additions & 2 deletions test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {

Completer<String> portAsString = new Completer();
void parsePortAsString(String line) {
if (perLine != null) perLine(line);
if (!portAsString.isCompleted) {
if (!portAsString.isCompleted && coverageEnabled) {
Match m = observatoryPortRegexp.matchAsPrefix(line);
if (m?.group(1) != null) portAsString.complete(m.group(1));
} else {
if (perLine != null) perLine(line);
}
}

Expand Down