Skip to content

Support documenting unversioned packages #1697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class Dartdoc extends PackageBuilder {
/// An asynchronous factory method that builds Dartdoc's file writers
/// and returns a Dartdoc object with them.
static withDefaultGenerators(DartdocGeneratorOptionContext config) async {
List<Generator> generators =
await initGenerators(config);
List<Generator> generators = await initGenerators(config);
return new Dartdoc._(config, generators);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4396,7 +4396,7 @@ class PackageGraph extends Canonicalization
return _inheritThrough;
}

String get version => packageMeta.version;
String get version => packageMeta.version ?? '0.0.0-unknown';

/// Looks up some [Library] that is reexporting this [Element]; not
/// necessarily the canonical [Library].
Expand Down
3 changes: 2 additions & 1 deletion test/compare_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ void main() {
var result = Process.runSync(Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath);
PackageMeta dartdocMeta = new PackageMeta.fromFilename(dartdocBin);
expect(result.stdout, equals('dartdoc version: ${dartdocMeta.version}\n'));
expect(
result.stdout, equals('dartdoc version: ${dartdocMeta.version}\n'));
});

test("Validate html output of test_package", () async {
Expand Down
39 changes: 27 additions & 12 deletions test/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ void main() {
delete(tempDir);
});

Future<DartdocGeneratorOptionContext> generatorContextFromArgvTemp(List<String> argv) async {
Future<DartdocGeneratorOptionContext> generatorContextFromArgvTemp(
List<String> argv) async {
return await generatorContextFromArgv(argv..addAll(outputParam));
}

test('package without version produces valid semver in docs', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageMinimumDir.path]));
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
assert(p.version == '0.0.0-unknown');
});

test('basic interlinking test', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--link-to-remote']));
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--link-to-remote']));
DartdocResults results = await dartdoc.generateDocs();
PackageGraph p = results.packageGraph;
Package tuple = p.publicPackages.firstWhere((p) => p.name == 'tuple');
Expand All @@ -60,7 +71,6 @@ void main() {
contains(stringLink));
});


test('generate docs for ${pathLib.basename(testPackageDir.path)} works',
() async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
Expand All @@ -79,7 +89,8 @@ void main() {
test('generate docs for ${pathLib.basename(testPackageBadDir.path)} fails',
() async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(['--input', testPackageBadDir.path]));
await generatorContextFromArgvTemp(
['--input', testPackageBadDir.path]));

try {
await dartdoc.generateDocs();
Expand All @@ -91,7 +102,8 @@ void main() {

test('generate docs for a package that does not have a readme', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(['--input', testPackageWithNoReadme.path]));
await generatorContextFromArgvTemp(
['--input', testPackageWithNoReadme.path]));

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -104,8 +116,9 @@ void main() {
});

test('generate docs including a single library', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--include', 'fake']));
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--include', 'fake']));

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -118,8 +131,9 @@ void main() {
});

test('generate docs excluding a single library', () async {
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--exclude', 'fake']));
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageDir.path, '--exclude', 'fake']));

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand All @@ -135,8 +149,9 @@ void main() {
test('generate docs for package with embedder yaml', () async {
PackageMeta meta = new PackageMeta.fromDir(testPackageWithEmbedderYaml);
if (meta.needsPubGet) meta.runPubGet();
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(await generatorContextFromArgvTemp(
['--input', testPackageWithEmbedderYaml.path]));
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
await generatorContextFromArgvTemp(
['--input', testPackageWithEmbedderYaml.path]));

DartdocResults results = await dartdoc.generateDocs();
expect(results.packageGraph, isNotNull);
Expand Down
11 changes: 6 additions & 5 deletions test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ PackageGraph testPackageGraphSdk;

final Directory testPackageBadDir = new Directory('testing/test_package_bad');
final Directory testPackageDir = new Directory('testing/test_package');
final Directory testPackageMinimumDir =
new Directory('testing/test_package_minimum');
final Directory testPackageWithEmbedderYaml =
new Directory('testing/test_package_embedder_yaml');
final Directory testPackageWithNoReadme =
new Directory('testing/test_package_small');


/// Convenience factory to build a [DartdocGeneratorOptionContext] and associate
/// it with a [DartdocOptionSet] based on the current working directory.
Future<DartdocGeneratorOptionContext> generatorContextFromArgv(List<String> argv) async {
DartdocOptionSet optionSet = await DartdocOptionSet
.fromOptionGenerators('dartdoc', [createDartdocOptions, createGeneratorOptions]);
Future<DartdocGeneratorOptionContext> generatorContextFromArgv(
List<String> argv) async {
DartdocOptionSet optionSet = await DartdocOptionSet.fromOptionGenerators(
'dartdoc', [createDartdocOptions, createGeneratorOptions]);
optionSet.parseArguments(argv);
return new DartdocGeneratorOptionContext(optionSet, Directory.current);
}


/// Convenience factory to build a [DartdocOptionContext] and associate it with a
/// [DartdocOptionSet] based on the current working directory.
Future<DartdocOptionContext> contextFromArgv(List<String> argv) async {
Expand Down
2 changes: 2 additions & 0 deletions testing/test_package_minimum/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc/api/
pubspec.lock
1 change: 1 addition & 0 deletions testing/test_package_minimum/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library small;
1 change: 1 addition & 0 deletions testing/test_package_minimum/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: test_package_minimal
5 changes: 2 additions & 3 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,8 @@ testPreviewDart2() async {
List<String> parameters = ['--preview-dart-2', '--enable-asserts'];

// sdk#32901 is really bad on Windows.
for (File dartFile in testFiles
.where((f) =>
!f.path.endsWith('html_generator_test.dart') && !Platform.isWindows)) {
for (File dartFile in testFiles.where((f) =>
!f.path.endsWith('html_generator_test.dart') && !Platform.isWindows)) {
// absolute path to work around dart-lang/sdk#32901
await testFutures.addFuture(new SubprocessLauncher(
'dart2-${pathLib.basename(dartFile.absolute.path)}')
Expand Down