@@ -6,6 +6,7 @@ library dartdoc.dartdoc_test;
6
6
7
7
import 'dart:async' ;
8
8
import 'dart:io' ;
9
+ import 'dart:mirrors' ;
9
10
10
11
import 'package:dartdoc/dartdoc.dart' ;
11
12
import 'package:dartdoc/src/logging.dart' ;
@@ -17,6 +18,13 @@ import 'package:test/test.dart';
17
18
18
19
import 'src/utils.dart' ;
19
20
21
+ Uri get _currentFileUri =>
22
+ (reflect (main) as ClosureMirror ).function.location.sourceUri;
23
+ String get _testPackagePath =>
24
+ pathLib.fromUri (_currentFileUri.resolve ('../testing/test_package' ));
25
+ String get _testPackageFlutterPluginPath => pathLib
26
+ .fromUri (_currentFileUri.resolve ('../testing/test_package_flutter_plugin' ));
27
+
20
28
class DartdocLoggingOptionContext extends DartdocGeneratorOptionContext
21
29
with LoggingContext {
22
30
DartdocLoggingOptionContext (DartdocOptionSet optionSet, Directory dir)
@@ -27,11 +35,8 @@ void main() {
27
35
group ('dartdoc with generators' , () {
28
36
Directory tempDir;
29
37
List <String > outputParam;
30
- CoverageSubprocessLauncher subprocessLauncher;
31
38
32
39
setUpAll (() async {
33
- subprocessLauncher =
34
- new CoverageSubprocessLauncher ('dartdoc_test-subprocesses' );
35
40
tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
36
41
outputParam = ['--output' , tempDir.path];
37
42
DartdocOptionSet optionSet = await DartdocOptionSet .fromOptionGenerators (
@@ -42,7 +47,6 @@ void main() {
42
47
});
43
48
44
49
tearDown (() async {
45
- await Future .wait (CoverageSubprocessLauncher .coverageResults);
46
50
tempDir.listSync ().forEach ((FileSystemEntity f) {
47
51
f.deleteSync (recursive: true );
48
52
});
@@ -114,7 +118,18 @@ void main() {
114
118
});
115
119
116
120
group ('Invoking command-line dartdoc' , () {
117
- String dartdocPath = pathLib.join ('bin' , 'dartdoc.dart' );
121
+ String dartdocPath =
122
+ pathLib.canonicalize (pathLib.join ('bin' , 'dartdoc.dart' ));
123
+ CoverageSubprocessLauncher subprocessLauncher;
124
+
125
+ setUpAll (() {
126
+ subprocessLauncher =
127
+ new CoverageSubprocessLauncher ('dartdoc_test-subprocesses' );
128
+ });
129
+
130
+ tearDownAll (() async {
131
+ await Future .wait (CoverageSubprocessLauncher .coverageResults);
132
+ });
118
133
119
134
test ('errors cause non-zero exit when warnings are off' , () async {
120
135
expect (
@@ -136,7 +151,108 @@ void main() {
136
151
]),
137
152
throwsA (const TypeMatcher <ProcessException >()));
138
153
});
139
- });
154
+
155
+ test ('Validate missing FLUTTER_ROOT exception is clean' , () async {
156
+ StringBuffer output = new StringBuffer ();
157
+ var args = < String > [dartdocPath];
158
+ Future run = subprocessLauncher.runStreamed (
159
+ Platform .resolvedExecutable, args,
160
+ environment: new Map .from (Platform .environment)
161
+ ..remove ('FLUTTER_ROOT' ),
162
+ includeParentEnvironment: false ,
163
+ workingDirectory: _testPackageFlutterPluginPath, perLine: (s) {
164
+ output.writeln (s);
165
+ });
166
+ // Asynchronous exception, but we still need the output, too.
167
+ expect (run, throwsA (new TypeMatcher <ProcessException >()));
168
+ try {
169
+ await run;
170
+ } on ProcessException catch (_) {}
171
+
172
+ expect (
173
+ output.toString (),
174
+ contains (new RegExp (
175
+ 'Top level package requires Flutter but FLUTTER_ROOT environment variable not set|test_package_flutter_plugin requires the Flutter SDK, version solving failed' )));
176
+ expect (output.toString (), isNot (contains ('asynchronous gap' )));
177
+ });
178
+
179
+ test ("Validate --version works" , () async {
180
+ StringBuffer output = new StringBuffer ();
181
+ var args = < String > [dartdocPath, '--version' ];
182
+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
183
+ workingDirectory: _testPackagePath,
184
+ perLine: (s) => output.writeln (s));
185
+ PackageMeta dartdocMeta = new PackageMeta .fromFilename (dartdocPath);
186
+ expect (output.toString (),
187
+ endsWith ('dartdoc version: ${dartdocMeta .version }\n ' ));
188
+ });
189
+
190
+ test ('Check for sample code in examples' , () async {
191
+ StringBuffer output = new StringBuffer ();
192
+ var args = < String > [
193
+ dartdocPath,
194
+ '--include' ,
195
+ 'ex' ,
196
+ '--no-include-source' ,
197
+ '--output' ,
198
+ tempDir.path
199
+ ];
200
+
201
+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
202
+ workingDirectory: _testPackagePath,
203
+ perLine: (s) => output.writeln (s));
204
+
205
+ // Examples are reported as unfound because we (purposefully)
206
+ // did not use --example-path-prefix above.
207
+ final sep = '.' ; // We don't care what the path separator character is
208
+ final firstUnfoundExample =
209
+ new RegExp ('warning: lib${sep }example.dart: '
210
+ '@example file not found.*test_package${sep }dog${sep }food.md' );
211
+ if (! output.toString ().contains (firstUnfoundExample)) {
212
+ fail ('Should warn about unfound @example files' );
213
+ }
214
+ });
215
+
216
+ test ('Validate JSON output' , () async {
217
+ var args = < String > [
218
+ dartdocPath,
219
+ '--include' ,
220
+ 'ex' ,
221
+ '--no-include-source' ,
222
+ '--output' ,
223
+ tempDir.path,
224
+ '--json'
225
+ ];
226
+
227
+ Iterable <Map > jsonValues = await subprocessLauncher.runStreamed (
228
+ Platform .resolvedExecutable, args,
229
+ workingDirectory: _testPackagePath);
230
+
231
+ expect (jsonValues, isNotEmpty,
232
+ reason: 'All STDOUT lines should be JSON-encoded maps.' );
233
+ }, timeout: new Timeout .factor (2 ));
234
+
235
+ test ('--footer-text includes text' , () async {
236
+ String footerTextPath =
237
+ pathLib.join (Directory .systemTemp.path, 'footer.txt' );
238
+ new File (footerTextPath).writeAsStringSync (' footer text include ' );
239
+
240
+ var args = < String > [
241
+ dartdocPath,
242
+ '--footer-text=${footerTextPath }' ,
243
+ '--include' ,
244
+ 'ex' ,
245
+ '--output' ,
246
+ tempDir.path
247
+ ];
248
+
249
+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
250
+ workingDirectory: _testPackagePath);
251
+
252
+ File outFile = new File (pathLib.join (tempDir.path, 'index.html' ));
253
+ expect (outFile.readAsStringSync (), contains ('footer text include' ));
254
+ });
255
+ }, timeout: new Timeout .factor (3 ));
140
256
141
257
group ('Option handling with cross-linking' , () {
142
258
DartdocResults results;
0 commit comments