Skip to content

Commit bb3e5d2

Browse files
committed
Fix bug in warnings where not specifying --show-warnings caused dartdoc to succeed even if there were errors.
1 parent 460e22f commit bb3e5d2

File tree

9 files changed

+83
-13
lines changed

9 files changed

+83
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 0.24.1-dev
22
* Added more metadata (element name, project name, etc.) to external tool invocations.
3+
* Fixed a bug where not specifying --show-warnings caused dartdoc to report success
4+
even when errors were present.
35

46
## 0.24.0
57
* Add 'override' to feature list for members which override a superclass (#981)

lib/src/model.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6491,18 +6491,16 @@ class PackageBuilder {
64916491
PackageWarningOptions warningOptions =
64926492
new PackageWarningOptions(config.verboseWarnings);
64936493
// TODO(jcollins-g): explode this into detailed command line options.
6494-
if (config.showWarnings) {
6495-
for (PackageWarning kind in PackageWarning.values) {
6496-
switch (kind) {
6497-
case PackageWarning.toolError:
6498-
case PackageWarning.invalidParameter:
6499-
case PackageWarning.unresolvedExport:
6500-
warningOptions.error(kind);
6501-
break;
6502-
default:
6503-
warningOptions.warn(kind);
6504-
break;
6505-
}
6494+
for (PackageWarning kind in PackageWarning.values) {
6495+
switch (kind) {
6496+
case PackageWarning.toolError:
6497+
case PackageWarning.invalidParameter:
6498+
case PackageWarning.unresolvedExport:
6499+
warningOptions.error(kind);
6500+
break;
6501+
default:
6502+
if (config.showWarnings) warningOptions.warn(kind);
6503+
break;
65066504
}
65076505
}
65086506
return warningOptions;

lib/src/warnings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ final Map<PackageWarning, PackageWarningHelpText> packageWarningText = const {
101101
PackageWarning.unresolvedExport: const PackageWarningHelpText(
102102
PackageWarning.unresolvedExport,
103103
"unresolvedExport",
104-
"An export refers to a URI that can not be resolved."),
104+
"An export refers to a URI that cannot be resolved."),
105105
};
106106

107107
/// Something that package warnings can be called on. Optionally associated

test/dartdoc_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,45 @@ void main() {
7373
expect(Something.isPublic, isTrue);
7474
expect(Something.displayedCategories, isNotEmpty);
7575
});
76+
77+
test('errors generate errors even when warnings are off', () async {
78+
Dartdoc dartdoc = await buildDartdoc([], testPackageToolError);
79+
DartdocResults results = await dartdoc.generateDocsBase();
80+
PackageGraph p = results.packageGraph;
81+
Iterable<String> unresolvedToolErrors = p
82+
.packageWarningCounter.countedWarnings.values
83+
.expand<String>((Set<Tuple2<PackageWarning, String>> s) => s
84+
.where((Tuple2<PackageWarning, String> t) =>
85+
t.item1 == PackageWarning.toolError)
86+
.map<String>((Tuple2<PackageWarning, String> t) => t.item2));
87+
88+
expect(p.packageWarningCounter.errorCount, equals(1));
89+
expect(unresolvedToolErrors.length, equals(1));
90+
expect(unresolvedToolErrors.first,
91+
contains('Tool "drill" returned non-zero exit code'));
92+
});
93+
});
94+
95+
group('Invoking command-line dartdoc', () {
96+
String dartdocPath = pathLib.join('bin', 'dartdoc.dart');
97+
98+
test('errors cause non-zero exit when warnings are off', () async {
99+
ProcessResult result = Process.runSync(Platform.resolvedExecutable, [
100+
dartdocPath,
101+
'--input=$testPackageToolError',
102+
'--output=${pathLib.join(tempDir.absolute.path, 'test_package_tool_error')}',
103+
]);
104+
expect(result.exitCode, isNonZero);
105+
});
106+
test('errors cause non-zero exit when warnings are on', () async {
107+
ProcessResult result = Process.runSync(Platform.resolvedExecutable, [
108+
dartdocPath,
109+
'--input=$testPackageToolError',
110+
'--output=${pathLib.join(tempDir.absolute.path, 'test_package_tool_error')}',
111+
'--show-warnings',
112+
]);
113+
expect(result.exitCode, isNonZero);
114+
});
76115
});
77116

78117
group('Option handling with cross-linking', () {

test/src/utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ final Directory testPackageOptions =
3535
new Directory('testing/test_package_options');
3636
final Directory testPackageOptionsImporter =
3737
new Directory('testing/test_package_options_importer');
38+
final Directory testPackageToolError =
39+
new Directory('testing/test_package_tool_error');
3840

3941
/// Convenience factory to build a [DartdocGeneratorOptionContext] and associate
4042
/// it with a [DartdocOptionSet] based on the current working directory and/or
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2018, 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+
// Used by tests as an "external tool" that always fails. Has no other useful purpose.
6+
7+
import 'dart:io';
8+
9+
void main(List<String> argList) {
10+
exit(1);
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dartdoc:
2+
tools:
3+
drill:
4+
command: ["bin/drill.dart"]
5+
description: "Puts holes in things."
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
abstract class ToolUser {
2+
/// Invokes a tool that fails.
3+
///
4+
/// {@tool drill}
5+
/// Doesn't matter what's here: it's gonna fail.
6+
/// {@end-tool}
7+
void invokeFailingTool();
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: test_package_tool_error
2+
version: 0.0.1
3+
description: A simple console application.
4+
environment:
5+
sdk: <=3.0.0

0 commit comments

Comments
 (0)