Skip to content

Commit

Permalink
Parameter error display tests (#1895)
Browse files Browse the repository at this point in the history
* Fix a bug and add more tests for parameter parsing

* dartfmt

* Hide observatory lines from downstream users

* Lines are out of order on windows
  • Loading branch information
jcollins-g authored Jan 11, 2019
1 parent 604767f commit 10f30e8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
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

0 comments on commit 10f30e8

Please sign in to comment.