Skip to content

Commit 8fccf5b

Browse files
authored
Compare flutter warnings between versions very easily (#1600)
* Compare flutter warnings between versions very easily * Add tests, clean up unused warning delta and its tests * Add compare-flutter-warnings to contributing instructions * dartfmt
1 parent 9da617b commit 8fccf5b

File tree

8 files changed

+288
-132
lines changed

8 files changed

+288
-132
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ yet in the issue tracker, start by opening an issue. Thanks!
2424
1. `grind` is needed to run dartdoc integration tests, see installed via `pub global activate grinder`.
2525
2. When a change is user-facing, please add a new entry to the [changelog](https://github.com/dart-lang/dartdoc/blob/master/CHANGELOG.md)
2626
3. Please include a test for your change. `dartdoc` has both `package:test`-style unittests as well as integration tests. To run the unittests, use `dart test/all.dart`. Most changes can be tested via a unittest, but some require modifying the [test_package](https://github.com/dart-lang/dartdoc/tree/master/testing/test_package) and regenerating its docs via `grind update-test-package-docs`.
27-
4. For major changes, run `grind compare-sdk-warnings` and include the summary results in your pull request.
27+
4. For major changes, run `grind compare-sdk-warnings` and `grind compare-flutter-warnings`, and include the summary results in your pull request.
2828
5. Be sure to format your Dart code using `dartfmt -w`, otherwise travis will complain.
2929
6. Post your change via a pull request for review and integration!
3030

lib/dartdoc.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class DartDoc extends PackageBuilder {
107107
// That seems wrong. dart-lang/dartdoc#1547
108108
for (Source source in sources) {
109109
ErrorsResult errorsResult = await driver.getErrors(source.fullName);
110-
AnalysisErrorInfo info = new AnalysisErrorInfoImpl(errorsResult.errors, errorsResult.lineInfo);
110+
AnalysisErrorInfo info =
111+
new AnalysisErrorInfoImpl(errorsResult.errors, errorsResult.lineInfo);
111112
List<_Error> errors = [info]
112113
.expand((AnalysisErrorInfo info) {
113114
return info.errors.map((error) =>
@@ -133,7 +134,9 @@ class DartDoc extends PackageBuilder {
133134
})
134135
.where((_Error error) => error.isError)
135136
// TODO(jcollins-g): remove after conversion to analysis driver
136-
.where((_Error error) => error.error.errorCode != CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED)
137+
.where((_Error error) =>
138+
error.error.errorCode !=
139+
CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED)
137140
.toList()
138141
..sort();
139142

lib/src/io_utils.dart

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class SubprocessLauncher {
8888
});
8989
}
9090

91-
SubprocessLauncher(this.context, [Map<String, String> environment]) :
92-
this.environment = environment ?? <String, String>{};
91+
SubprocessLauncher(this.context, [Map<String, String> environment])
92+
: this.environment = environment ?? <String, String>{};
9393

9494
/// A wrapper around start/await process.exitCode that will display the
9595
/// output of the executable continuously and fail on non-zero exit codes.
@@ -165,52 +165,3 @@ class SubprocessLauncher {
165165
return jsonObjects;
166166
}
167167
}
168-
169-
/// Output formatter for comparing warnings.
170-
String printWarningDelta(String title, String dartdocOriginalBranch,
171-
Map<String, int> original, Map<String, int> current) {
172-
StringBuffer printBuffer = new StringBuffer();
173-
Set<String> quantityChangedOuts = new Set();
174-
Set<String> onlyOriginal = new Set();
175-
Set<String> onlyCurrent = new Set();
176-
Set<String> allKeys =
177-
new Set.from([]..addAll(original.keys)..addAll(current.keys));
178-
179-
for (String key in allKeys) {
180-
if (original.containsKey(key) && !current.containsKey(key)) {
181-
onlyOriginal.add(key);
182-
} else if (!original.containsKey(key) && current.containsKey(key)) {
183-
onlyCurrent.add(key);
184-
} else if (original.containsKey(key) &&
185-
current.containsKey(key) &&
186-
original[key] != current[key]) {
187-
quantityChangedOuts.add(key);
188-
}
189-
}
190-
191-
if (onlyOriginal.isNotEmpty) {
192-
printBuffer.writeln(
193-
'*** $title : ${onlyOriginal.length} warnings from original ($dartdocOriginalBranch) missing in current:');
194-
onlyOriginal.forEach((warning) => printBuffer.writeln(warning));
195-
}
196-
if (onlyCurrent.isNotEmpty) {
197-
printBuffer.writeln(
198-
'*** $title : ${onlyCurrent.length} new warnings not in original ($dartdocOriginalBranch)');
199-
onlyCurrent.forEach((warning) => printBuffer.writeln(warning));
200-
}
201-
if (quantityChangedOuts.isNotEmpty) {
202-
printBuffer.writeln('*** $title : Identical warning quantity changed');
203-
for (String key in quantityChangedOuts) {
204-
printBuffer.writeln(
205-
"* Appeared ${original[key]} times in original ($dartdocOriginalBranch), now ${current[key]}:");
206-
printBuffer.writeln(key);
207-
}
208-
}
209-
if (onlyOriginal.isEmpty &&
210-
onlyCurrent.isEmpty &&
211-
quantityChangedOuts.isEmpty) {
212-
printBuffer.writeln(
213-
'*** $title : No difference in warning output from original ($dartdocOriginalBranch)${allKeys.isEmpty ? "" : " (${allKeys.length} warnings found)"}');
214-
}
215-
return printBuffer.toString();
216-
}

test/grind_test.dart

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) 2015, 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 dartdoc.io_utils_test;
6+
7+
import 'package:test/test.dart';
8+
9+
import '../tool/grind.dart' hide test;
10+
11+
void main() {
12+
group('printWarningDelta', () {
13+
WarningsCollection original, current;
14+
WarningsCollection originalWithDirs, currentWithDirs;
15+
setUp(() {
16+
original =
17+
new WarningsCollection('/a/tempdir', '/pubcache/path', 'oldbranch');
18+
original.add('originalwarning');
19+
original.add('morewarning');
20+
original.add('duplicateoriginalwarning');
21+
original.add('duplicateoriginalwarning');
22+
current =
23+
new WarningsCollection('/a/tempdir2', '/pubcache/path2', 'current');
24+
current.add('newwarning');
25+
current.add('morewarning');
26+
current.add('duplicateoriginalwarning');
27+
originalWithDirs = new WarningsCollection(
28+
'/a/tempdirFOO', '/pubcache/pathFOO', 'DirsOriginal');
29+
originalWithDirs.add(
30+
'originalWarning found in /a/tempdirFOO/some/subdir/program.dart!!!!');
31+
originalWithDirs.add(
32+
'another originalWarning found in /pubcache/pathFOO/some/package/lib/thingy.dart!!!');
33+
originalWithDirs.add(
34+
'insufficent exclamation mark warning found in /pubcache/pathFOO/some/package/lib/thingy.dart.');
35+
originalWithDirs.add(
36+
'another originalWarning found in /a/tempdirFOO/some/subdir/program.dart');
37+
currentWithDirs = new WarningsCollection(
38+
'/a/tempdirBAR', '/pubcache/pathBAR', 'DirsCurrent');
39+
currentWithDirs.add(
40+
'originalWarning found in /a/tempdirBAR/some/subdir/program.dart!!!!');
41+
currentWithDirs.add(
42+
'another originalWarning found in /pubcache/pathBAR/some/package/lib/thingy.dart!!!');
43+
currentWithDirs.add(
44+
'insufficent exclamation mark warning found in /pubcache/pathBAR/some/package/lib/thingy.dart.');
45+
currentWithDirs.add(
46+
'another originalWarning found in /a/tempdirBAR/some/other/subdir/program.dart');
47+
});
48+
49+
test('verify that paths are substituted when comparing warnings', () {
50+
expect(
51+
originalWithDirs.getPrintableWarningDelta(
52+
'Dirs diff title', currentWithDirs),
53+
equals(
54+
'*** Dirs diff title : 1 warnings from DirsOriginal, missing in DirsCurrent:\n'
55+
'another originalWarning found in /a/tempdirFOO/some/subdir/program.dart\n'
56+
'*** Dirs diff title : 1 new warnings in DirsCurrent, missing in DirsOriginal\n'
57+
'another originalWarning found in /a/tempdirBAR/some/other/subdir/program.dart\n'
58+
'*** Dirs diff title : Difference in warning output found for 2 warnings (5 warnings found)"\n'));
59+
});
60+
61+
test('verify output of printWarningDelta', () {
62+
expect(
63+
original.getPrintableWarningDelta('Diff Title', current),
64+
equals(
65+
'*** Diff Title : 1 warnings from oldbranch, missing in current:\n'
66+
'originalwarning\n'
67+
'*** Diff Title : 1 new warnings in current, missing in oldbranch\n'
68+
'newwarning\n'
69+
'*** Diff Title : Identical warning quantity changed\n'
70+
'* Appeared 2 times in oldbranch, 1 in current:\n'
71+
'duplicateoriginalwarning\n'
72+
'*** Diff Title : Difference in warning output found for 3 warnings (4 warnings found)"\n'));
73+
});
74+
75+
test('verify output when nothing changes', () {
76+
expect(
77+
original.getPrintableWarningDelta('Diff Title 2', original),
78+
equals(
79+
'*** Diff Title 2 : No difference in warning output from oldbranch to oldbranch (3 warnings found)\n'));
80+
});
81+
});
82+
}

test/io_utils_test.dart

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,4 @@ void main() {
1717
expect(getFileNameFor('dartdoc.generator'), 'dartdoc-generator.html');
1818
});
1919
});
20-
21-
group('printWarningDelta', () {
22-
Map<String, int> original;
23-
Map<String, int> current;
24-
setUp(() {
25-
original = new Map.fromIterables(
26-
["originalwarning", "morewarning", "duplicateoriginalwarning"],
27-
[1, 1, 2]);
28-
current = new Map.fromIterables(
29-
["newwarning", "morewarning", "duplicateoriginalwarning"], [1, 1, 1]);
30-
});
31-
32-
test('verify output of printWarningDelta', () {
33-
expect(
34-
printWarningDelta('Diff Title', 'oldbranch', original, current),
35-
equals(
36-
'*** Diff Title : 1 warnings from original (oldbranch) missing in current:\n'
37-
'originalwarning\n'
38-
'*** Diff Title : 1 new warnings not in original (oldbranch)\n'
39-
'newwarning\n'
40-
'*** Diff Title : Identical warning quantity changed\n'
41-
'* Appeared 2 times in original (oldbranch), now 1:\n'
42-
'duplicateoriginalwarning\n'));
43-
});
44-
45-
test('verify output when nothing changes', () {
46-
expect(
47-
printWarningDelta('Diff Title 2', 'oldbranch2', original, original),
48-
equals(
49-
'*** Diff Title 2 : No difference in warning output from original (oldbranch2) (3 warnings found)\n'));
50-
});
51-
});
5220
}

test/model_test.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ void main() {
320320
dog.allInstanceMethods.firstWhere((m) => m.name == 'withMacro');
321321
withMacro2 =
322322
dog.allInstanceMethods.firstWhere((m) => m.name == 'withMacro2');
323-
withPrivateMacro =
324-
dog.allInstanceMethods.firstWhere((m) => m.name == 'withPrivateMacro');
325-
withUndefinedMacro =
326-
dog.allInstanceMethods.firstWhere((m) => m.name == 'withUndefinedMacro');
323+
withPrivateMacro = dog.allInstanceMethods
324+
.firstWhere((m) => m.name == 'withPrivateMacro');
325+
withUndefinedMacro = dog.allInstanceMethods
326+
.firstWhere((m) => m.name == 'withUndefinedMacro');
327327
package.allModelElements.forEach((m) => m.documentation);
328328
});
329329

@@ -342,7 +342,10 @@ void main() {
342342
});
343343

344344
test("a warning is generated for unknown macros", () {
345-
expect(package.packageWarningCounter.hasWarning(withUndefinedMacro, PackageWarning.unknownMacro, 'ThatDoesNotExist'), isTrue);
345+
expect(
346+
package.packageWarningCounter.hasWarning(withUndefinedMacro,
347+
PackageWarning.unknownMacro, 'ThatDoesNotExist'),
348+
isTrue);
346349
});
347350
});
348351

@@ -1908,7 +1911,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
19081911
deprecated =
19091912
exLibrary.constants.firstWhere((c) => c.name == 'deprecated');
19101913
Class Dog = exLibrary.allClasses.firstWhere((c) => c.name == 'Dog');
1911-
customClassPrivate = fakeLibrary.constants.firstWhere((c) => c.name == 'CUSTOM_CLASS_PRIVATE');
1914+
customClassPrivate = fakeLibrary.constants
1915+
.firstWhere((c) => c.name == 'CUSTOM_CLASS_PRIVATE');
19121916
aStaticConstField =
19131917
Dog.allFields.firstWhere((f) => f.name == 'aStaticConstField');
19141918
aName = Dog.allFields.firstWhere((f) => f.name == 'aName');
@@ -1957,7 +1961,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
19571961
});
19581962

19591963
test('MY_CAT is linked', () {
1960-
expect(cat.constantValue, 'const <a href="ex/ConstantCat/ConstantCat.html">ConstantCat</a>(&#39;tabby&#39;)');
1964+
expect(cat.constantValue,
1965+
'const <a href="ex/ConstantCat/ConstantCat.html">ConstantCat</a>(&#39;tabby&#39;)');
19611966
});
19621967

19631968
test('exported property', () {
@@ -2090,7 +2095,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
20902095

20912096
test('linked return type', () {
20922097
expect(t.linkedReturnType, equals('String'));
2093-
expect(generic.linkedReturnType, equals('List<span class="signature">&lt;S&gt;</span>'));
2098+
expect(generic.linkedReturnType,
2099+
equals('List<span class="signature">&lt;S&gt;</span>'));
20942100
});
20952101

20962102
test("name with generics", () {

test/src/utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ init() async {
4242
testPackageGinormous = await bootBasicPackage(
4343
'testing/test_package', ['css', 'code_in_commnets', 'excluded'], true);
4444

45-
testPackageSmall = await bootBasicPackage('testing/test_package_small', [], false);
45+
testPackageSmall =
46+
await bootBasicPackage('testing/test_package_small', [], false);
4647
testPackageSdk = await bootSdkPackage();
4748
}
4849

0 commit comments

Comments
 (0)