ffe1c532e5
This reverts commit 645511d7f4.
Reason for revert: Deemed too risky to land so close to the release branch cut
Original change's description:
> Resolve package pubspec of target for relevant dartdev commands
>
> Adds a `--no-pub` flag to those commands
>
> Bug: https://github.com/dart-lang/sdk/issues/50422
> Change-Id: I949605c4ebb4c609eb19159625958317e54523a9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291500
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Jonas Jensen <jonasfj@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Bug: https://github.com/dart-lang/sdk/issues/50422
Change-Id: I465e43c59240e545658dce2e3fd764755d55ca97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293560
Auto-Submit: Ben Konyi <bkonyi@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
132 lines
3.6 KiB
Dart
132 lines
3.6 KiB
Dart
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import '../utils.dart';
|
|
|
|
const int errorExitCode = 64;
|
|
|
|
void main() {
|
|
group('doc', defineDocTests, timeout: longTimeout);
|
|
}
|
|
|
|
void defineDocTests() {
|
|
ensureRunFromSdkBinDart();
|
|
|
|
test('--help', () async {
|
|
final p = project();
|
|
final result = await p.run(['doc', '--help']);
|
|
expect(
|
|
result.stdout,
|
|
contains('Usage: dart doc [arguments] [<directory>]'),
|
|
);
|
|
expect(result.exitCode, 0);
|
|
});
|
|
|
|
test('Passing conflicting options fails', () async {
|
|
final p = project();
|
|
final result =
|
|
await p.run(['doc', '--validate-links', '--dry-run', p.dirPath]);
|
|
expect(
|
|
result.stderr,
|
|
contains("'dart doc' can not validate links when dry-running."),
|
|
);
|
|
expect(result.exitCode, errorExitCode);
|
|
});
|
|
|
|
test('Passing multiple directories fails', () async {
|
|
final p = project();
|
|
final result = await p.run(['doc', 'foo', 'bar']);
|
|
expect(result.stderr,
|
|
contains("'dart doc' only supports one input directory.'"));
|
|
expect(result.exitCode, errorExitCode);
|
|
});
|
|
|
|
test('defaults to documenting cwd', () async {
|
|
final p = project(mainSrc: 'void main() { print("Hello, World"); }');
|
|
p.file('lib/foo.dart', '''
|
|
/// This is Foo. It uses [Bar].
|
|
class Foo {
|
|
Bar bar;
|
|
}
|
|
|
|
/// Bar is very nice.
|
|
class Bar {
|
|
_i = 42;
|
|
}
|
|
''');
|
|
final result = await p.run(['doc'], workingDir: p.dirPath);
|
|
expect(result.stdout, contains('Documenting dartdev_temp'));
|
|
expect(result.exitCode, 0);
|
|
});
|
|
|
|
test('Document a library', () async {
|
|
final p = project(mainSrc: 'void main() { print("Hello, World"); }');
|
|
p.file('lib/foo.dart', '''
|
|
/// This is Foo. It uses [Bar].
|
|
class Foo {
|
|
Bar bar;
|
|
}
|
|
|
|
/// Bar is very nice.
|
|
class Bar {
|
|
_i = 42;
|
|
}
|
|
''');
|
|
final result = await p.run(['doc', '--validate-links', p.dirPath]);
|
|
expect(result.stdout, contains('Documenting dartdev_temp'));
|
|
expect(result.exitCode, 0);
|
|
});
|
|
|
|
test('Document a library dry-run', () async {
|
|
final p = project(mainSrc: 'void main() { print("Hello, World"); }');
|
|
p.file('lib/foo.dart', '''
|
|
/// This is Foo.
|
|
class Foo {
|
|
int i = 42;
|
|
}
|
|
''');
|
|
final result = await p.run(['doc', '--dry-run', '--verbose', p.dirPath]);
|
|
expect(result.stdout, contains('Using the following options: [--input='));
|
|
// TODO(devoncarew): We should update package:dartdoc to emit some
|
|
// "Documenting ..." text here.
|
|
expect(result.stdout, isNot(contains('Documenting dartdev_temp')));
|
|
expect(result.exitCode, 0);
|
|
});
|
|
|
|
test('Errors cause error code', () async {
|
|
final p = project(mainSrc: 'void main() { print("Hello, World"); }');
|
|
p.file('lib/foo.dart', '''
|
|
/// This is Foo. It uses [TypeThatIsntDeclared].
|
|
class Foo {
|
|
int i = 42;
|
|
}
|
|
''');
|
|
p.file('dartdoc_options.yaml', '''
|
|
dartdoc:
|
|
errors:
|
|
- unresolved-doc-reference
|
|
''');
|
|
final result = await p.run(['doc', p.dirPath]);
|
|
expect(result.exitCode, 1);
|
|
});
|
|
|
|
test('Document a library with broken link is flagged', () async {
|
|
final source = '''
|
|
/// This is Foo. It uses [Baz].
|
|
class Foo {
|
|
int i = 42;
|
|
}
|
|
''';
|
|
|
|
final p = project(mainSrc: 'void main() { print("Hello, World"); }');
|
|
p.file('lib/foo.dart', source);
|
|
final result = await p.run(['doc', '--validate-links', p.dirPath]);
|
|
// TODO (mit): Update this test to actually test for the
|
|
// --validate-links flag.
|
|
expect(result.stdout, contains('Documenting dartdev_temp'));
|
|
});
|
|
}
|