OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Unit tests for doc. | 5 /// Unit tests for doc. |
6 library dartdocTests; | 6 library dartdocTests; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import '../../../../../pkg/pathos/lib/path.dart' as path; | 10 |
11 import 'package:pathos/path.dart' as path; | |
12 import 'package:unittest/unittest.dart'; | |
11 | 13 |
12 // TODO(rnystrom): Use "package:" URL (#4968). | 14 // TODO(rnystrom): Use "package:" URL (#4968). |
Bob Nystrom
2013/03/26 01:55:44
Do you want to fix these imports, or just remove t
nweiz
2013/03/26 02:09:53
These still want to be changed to "package:" impor
| |
13 import '../lib/dartdoc.dart' as dd; | 15 import '../lib/dartdoc.dart' as dd; |
14 import '../lib/markdown.dart'; | 16 import '../lib/markdown.dart'; |
15 import 'markdown_test.dart'; | 17 import 'markdown_test.dart'; |
16 | 18 |
17 // TODO(rnystrom): Better path to unittest. | |
18 import '../../../../../pkg/unittest/lib/unittest.dart'; | |
19 | |
20 // Pretty test config with --human | 19 // Pretty test config with --human |
21 import '../../../../../utils/tests/pub/command_line_config.dart'; | 20 import '../../../../../utils/tests/pub/command_line_config.dart'; |
22 | 21 |
23 main() { | 22 main() { |
24 // Use the human-friendly config. | 23 // Use the human-friendly config. |
25 if (new Options().arguments.contains('--human')) { | 24 if (new Options().arguments.contains('--human')) { |
26 configure(new CommandLineConfiguration()); | 25 configure(new CommandLineConfiguration()); |
27 } | 26 } |
28 | 27 |
29 group('countOccurrences', () { | 28 group('countOccurrences', () { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 expect(result.exitCode, 1); | 229 expect(result.exitCode, 1); |
231 }); | 230 }); |
232 }); | 231 }); |
233 }); | 232 }); |
234 } | 233 } |
235 | 234 |
236 void _testRunDartDoc(List<String> libraryPaths, void eval(ProcessResult)) { | 235 void _testRunDartDoc(List<String> libraryPaths, void eval(ProcessResult)) { |
237 expect(_runDartdoc(libraryPaths).then(eval), completes); | 236 expect(_runDartdoc(libraryPaths).then(eval), completes); |
238 } | 237 } |
239 | 238 |
240 /// Runs dartdoc with the libraryPaths provided, and completes to dartdoc's | 239 /// The path to the root directory of the dartdoc app. |
Bob Nystrom
2013/03/26 01:55:44
"app" -> "entrypoint".
nweiz
2013/03/26 02:09:53
Done.
| |
241 /// ProcessResult. | 240 String get _dartdocDir { |
242 Future<ProcessResult> _runDartdoc(List<String> libraryPaths) { | |
243 var dartBin = new Options().executable; | |
244 | |
245 var dir = path.absolute(new Options().script); | 241 var dir = path.absolute(new Options().script); |
246 while (path.basename(dir) != 'dartdoc') { | 242 while (path.basename(dir) != 'dartdoc') { |
247 if (!path.absolute(dir).contains('dartdoc') || dir == path.dirname(dir)) { | 243 if (!path.absolute(dir).contains('dartdoc') || dir == path.dirname(dir)) { |
248 fail('Unable to find root dartdoc directory.'); | 244 fail('Unable to find root dartdoc directory.'); |
249 } | 245 } |
250 dir = path.dirname(dir); | 246 dir = path.dirname(dir); |
251 } | 247 } |
252 var dartdoc = path.join(path.absolute(dir), 'bin/dartdoc.dart'); | 248 return path.absolute(dir); |
249 } | |
253 | 250 |
254 final runArgs = [dartdoc]; | 251 /// The path to use for the package root for subprocesses. |
252 String get _packageRoot { | |
253 var sdkVersionPath = path.join(_dartdocDir, '..', '..', '..', 'version'); | |
254 if (new File(sdkVersionPath).existsSync()) { | |
255 // It looks like dartdoc is being run from the SDK, so we should set the | |
256 // package root to the SDK's packages directory. | |
257 return path.absolute(path.join(_dartdocDir, '..', '..', '..', 'packages')); | |
258 } | |
259 | |
260 // It looks like Dartdoc is being run from the Dart repo, so the package root | |
261 // is in the build output directory. We can find that directory relative to | |
262 // the Dart executable, but that could be in one of two places: in | |
263 // "$BUILD/dart" or "$BUILD/dart-sdk/bin/dart". | |
264 var executableDir = path.dirname(new Options().executable); | |
265 if (new Directory(path.join(executableDir, 'dart-sdk')).existsSync()) { | |
266 // The executable is in "$BUILD/dart". | |
267 return path.absolute(path.join(executableDir, 'packages')); | |
268 } else { | |
269 // The executable is in "$BUILD/dart-sdk/bin/dart". | |
270 return path.absolute(path.join(executableDir, '..', '..', 'packages')); | |
271 } | |
272 } | |
273 | |
274 /// Runs dartdoc with the libraryPaths provided, and completes to dartdoc's | |
275 /// ProcessResult. | |
276 Future<ProcessResult> _runDartdoc(List<String> libraryPaths) { | |
277 var dartBin = new Options().executable; | |
278 | |
279 var dartdoc = path.join(_dartdocDir, 'bin/dartdoc.dart'); | |
280 | |
281 final runArgs = ['--package-root=$_packageRoot/', dartdoc]; | |
255 | 282 |
256 // Turn relative libraryPaths to absolute ones. | 283 // Turn relative libraryPaths to absolute ones. |
257 runArgs.addAll(libraryPaths | 284 runArgs.addAll(libraryPaths |
258 .map((e) => path.join(dd.scriptDir.toNativePath(), e))); | 285 .map((e) => path.join(dd.scriptDir.toNativePath(), e))); |
259 | 286 |
260 return Process.run(dartBin, runArgs); | 287 return Process.run(dartBin, runArgs); |
261 } | 288 } |
262 | 289 |
263 final _dartdocCompletionRegExp = | 290 final _dartdocCompletionRegExp = |
264 new RegExp(r'Documentation complete -- documented (\d+) libraries, (\d+) types , and (\d+) members\.'); | 291 new RegExp(r'Documentation complete -- documented (\d+) libraries, (\d+) types , and (\d+) members\.'); |
(...skipping 25 matching lines...) Expand all Loading... | |
290 } | 317 } |
291 } | 318 } |
292 | 319 |
293 | 320 |
294 validateDartdocMarkdown(String description, String markdown, | 321 validateDartdocMarkdown(String description, String markdown, |
295 String html) { | 322 String html) { |
296 var dartdoc = new dd.Dartdoc(); | 323 var dartdoc = new dd.Dartdoc(); |
297 validate(description, markdown, html, linkResolver: dartdoc.dartdocResolver, | 324 validate(description, markdown, html, linkResolver: dartdoc.dartdocResolver, |
298 inlineSyntaxes: dartdoc.dartdocSyntaxes); | 325 inlineSyntaxes: dartdoc.dartdocSyntaxes); |
299 } | 326 } |
OLD | NEW |