| 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 | 10 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 }); | 187 }); |
| 188 }); | 188 }); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void _testRunDartDoc(List<String> libraryPaths, void eval(ProcessResult)) { | 191 void _testRunDartDoc(List<String> libraryPaths, void eval(ProcessResult)) { |
| 192 expect(_runDartdoc(libraryPaths).then(eval), completes); | 192 expect(_runDartdoc(libraryPaths).then(eval), completes); |
| 193 } | 193 } |
| 194 | 194 |
| 195 /// The path to the root directory of the dartdoc entrypoint. | 195 /// The path to the root directory of the dartdoc entrypoint. |
| 196 String get _dartdocDir { | 196 String get _dartdocDir { |
| 197 var dir = path.absolute(new Options().script); | 197 var dir = path.absolute(Platform.script); |
| 198 while (path.basename(dir) != 'dartdoc') { | 198 while (path.basename(dir) != 'dartdoc') { |
| 199 if (!path.absolute(dir).contains('dartdoc') || dir == path.dirname(dir)) { | 199 if (!path.absolute(dir).contains('dartdoc') || dir == path.dirname(dir)) { |
| 200 fail('Unable to find root dartdoc directory.'); | 200 fail('Unable to find root dartdoc directory.'); |
| 201 } | 201 } |
| 202 dir = path.dirname(dir); | 202 dir = path.dirname(dir); |
| 203 } | 203 } |
| 204 return path.absolute(dir); | 204 return path.absolute(dir); |
| 205 } | 205 } |
| 206 | 206 |
| 207 /// The path to use for the package root for subprocesses. | 207 /// The path to use for the package root for subprocesses. |
| 208 String get _packageRoot { | 208 String get _packageRoot { |
| 209 var sdkVersionPath = path.join(_dartdocDir, '..', '..', '..', 'version'); | 209 var sdkVersionPath = path.join(_dartdocDir, '..', '..', '..', 'version'); |
| 210 if (new File(sdkVersionPath).existsSync()) { | 210 if (new File(sdkVersionPath).existsSync()) { |
| 211 // It looks like dartdoc is being run from the SDK, so we should set the | 211 // It looks like dartdoc is being run from the SDK, so we should set the |
| 212 // package root to the SDK's packages directory. | 212 // package root to the SDK's packages directory. |
| 213 return path.absolute(path.join(_dartdocDir, '..', '..', '..', 'packages')); | 213 return path.absolute(path.join(_dartdocDir, '..', '..', '..', 'packages')); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // It looks like Dartdoc is being run from the Dart repo, so the package root | 216 // It looks like Dartdoc is being run from the Dart repo, so the package root |
| 217 // is in the build output directory. We can find that directory relative to | 217 // is in the build output directory. We can find that directory relative to |
| 218 // the Dart executable, but that could be in one of two places: in | 218 // the Dart executable, but that could be in one of two places: in |
| 219 // "$BUILD/dart" or "$BUILD/dart-sdk/bin/dart". | 219 // "$BUILD/dart" or "$BUILD/dart-sdk/bin/dart". |
| 220 var executableDir = path.dirname(new Options().executable); | 220 var executableDir = path.dirname(Platform.executable); |
| 221 if (new Directory(path.join(executableDir, 'dart-sdk')).existsSync()) { | 221 if (new Directory(path.join(executableDir, 'dart-sdk')).existsSync()) { |
| 222 // The executable is in "$BUILD/dart". | 222 // The executable is in "$BUILD/dart". |
| 223 return path.absolute(path.join(executableDir, 'packages')); | 223 return path.absolute(path.join(executableDir, 'packages')); |
| 224 } else { | 224 } else { |
| 225 // The executable is in "$BUILD/dart-sdk/bin/dart". | 225 // The executable is in "$BUILD/dart-sdk/bin/dart". |
| 226 return path.absolute(path.join(executableDir, '..', '..', 'packages')); | 226 return path.absolute(path.join(executableDir, '..', '..', 'packages')); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 /// Runs dartdoc with the libraryPaths provided, and completes to dartdoc's | 230 /// Runs dartdoc with the libraryPaths provided, and completes to dartdoc's |
| 231 /// ProcessResult. | 231 /// ProcessResult. |
| 232 Future<ProcessResult> _runDartdoc(List<String> libraryPaths) { | 232 Future<ProcessResult> _runDartdoc(List<String> libraryPaths) { |
| 233 var dartBin = new Options().executable; | 233 var dartBin = Platform.executable; |
| 234 | 234 |
| 235 var dartdoc = path.join(_dartdocDir, 'bin/dartdoc.dart'); | 235 var dartdoc = path.join(_dartdocDir, 'bin/dartdoc.dart'); |
| 236 | 236 |
| 237 final runArgs = ['--package-root=$_packageRoot/', dartdoc]; | 237 final runArgs = ['--package-root=$_packageRoot/', dartdoc]; |
| 238 | 238 |
| 239 // Turn relative libraryPaths to absolute ones. | 239 // Turn relative libraryPaths to absolute ones. |
| 240 runArgs.addAll(libraryPaths | 240 runArgs.addAll(libraryPaths |
| 241 .map((e) => path.join(dd.scriptDir.toNativePath(), e))); | 241 .map((e) => path.join(dd.scriptDir.toNativePath(), e))); |
| 242 | 242 |
| 243 return Process.run(dartBin, runArgs); | 243 return Process.run(dartBin, runArgs); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 | 276 |
| 277 validateDartdocMarkdown(String description, String markdown, | 277 validateDartdocMarkdown(String description, String markdown, |
| 278 String html) { | 278 String html) { |
| 279 var dartdoc = new dd.Dartdoc(); | 279 var dartdoc = new dd.Dartdoc(); |
| 280 validate(description, markdown, html, linkResolver: dartdoc.dartdocResolver, | 280 validate(description, markdown, html, linkResolver: dartdoc.dartdocResolver, |
| 281 inlineSyntaxes: dartdoc.dartdocSyntaxes); | 281 inlineSyntaxes: dartdoc.dartdocSyntaxes); |
| 282 } | 282 } |
| OLD | NEW |