Skip to content

Commit 7e5da60

Browse files
authored
Simplify some end2end tests into smaller tests (#3795)
1 parent 36f1fc7 commit 7e5da60

File tree

4 files changed

+49
-64
lines changed

4 files changed

+49
-64
lines changed

lib/src/dartdoc_options.dart

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,6 @@ class DartdocProgramOptionContext extends DartdocGeneratorOptionContext
14241424

14251425
/// Whether to generate docs or perform a dry run.
14261426
bool get generateDocs => optionSet['generateDocs'].valueAt(context);
1427-
bool get help => optionSet['help'].valueAt(context);
1428-
bool get version => optionSet['version'].valueAt(context);
14291427
}
14301428

14311429
List<DartdocOption<bool>> createDartdocProgramOptions(
@@ -1472,12 +1470,14 @@ DartdocProgramOptionContext? parseOptions(
14721470
return null;
14731471
}
14741472
if (optionRoot['help'].valueAtCurrent() as bool) {
1475-
_printHelp(optionRoot.argParser);
1473+
logInfo('dartdoc version: $dartdocVersion');
1474+
logInfo('Generate HTML documentation for Dart libraries.\n');
1475+
logInfo(optionRoot.argParser.usage);
14761476
exitCode = 0;
14771477
return null;
14781478
}
14791479
if (optionRoot['version'].valueAtCurrent() as bool) {
1480-
_printVersion(optionRoot.argParser);
1480+
logInfo('dartdoc version: $dartdocVersion');
14811481
exitCode = 0;
14821482
return null;
14831483
}
@@ -1501,23 +1501,12 @@ DartdocProgramOptionContext? parseOptions(
15011501
return config;
15021502
}
15031503

1504-
/// Print help if we are passed the help option.
1505-
void _printHelp(ArgParser parser) {
1506-
print('Generate HTML documentation for Dart libraries.\n');
1507-
print(parser.usage);
1508-
}
1509-
15101504
/// Print usage information on invalid command lines.
15111505
void _printUsage(ArgParser parser) {
15121506
print('Usage: dartdoc [OPTIONS]\n');
15131507
print(parser.usage);
15141508
}
15151509

1516-
/// Print version information.
1517-
void _printVersion(ArgParser parser) {
1518-
print('dartdoc version: $dartdocVersion');
1519-
}
1520-
15211510
/// Instantiate dartdoc's configuration file and options parser with the
15221511
/// given command line arguments.
15231512
List<DartdocOption> createDartdocOptions(

lib/src/logging.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ void logProgress(String message) {
3939
_logger.log(_progressLevel, message);
4040
}
4141

42-
void logPrint(String message) {
43-
_logger.log(printLevel, message);
44-
}
45-
4642
/// Creates a new deterministic progress bar, and displays it (with zero
4743
/// progress).
4844
void progressBarStart(int totalTickCount) {

test/end2end/dartdoc_integration_test.dart

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ library;
88
import 'dart:async';
99
import 'dart:io';
1010

11-
import 'package:dartdoc/src/package_meta.dart';
1211
import 'package:path/path.dart' as path;
1312
import 'package:test/test.dart';
1413
import 'package:test_process/test_process.dart';
@@ -34,50 +33,6 @@ Future<TestProcess> runDartdoc(
3433
);
3534

3635
void main() {
37-
test('invoking dartdoc on an empty package does not crash', () async {
38-
var packagePath = await d.createPackage('empty');
39-
var process = await runDartdoc([], workingDirectory: packagePath);
40-
await expectLater(
41-
process.stderr,
42-
emitsThrough(
43-
contains('package:test_package has no documentable libraries')),
44-
);
45-
await process.shouldExit(0);
46-
});
47-
48-
group('invoking dartdoc on a basic package', () {
49-
late String packagePath;
50-
51-
setUp(() async {
52-
packagePath = await d.createPackage('test_package', libFiles: [
53-
d.file('lib.dart', '/// [dead] reference\nclass C {}'),
54-
]);
55-
});
56-
57-
test('with --help prints command line args', () async {
58-
var process = await runDartdoc(
59-
['--help'],
60-
workingDirectory: packagePath,
61-
);
62-
await expectLater(process.stdout,
63-
emitsThrough('Generate HTML documentation for Dart libraries.'));
64-
await expectLater(process.stdout,
65-
emitsThrough(matches('^-h, --help[ ]+Show command help.')));
66-
await process.shouldExit(0);
67-
});
68-
69-
test('Validate --version works', () async {
70-
var process = await runDartdoc(
71-
['--version'],
72-
workingDirectory: packagePath,
73-
);
74-
var dartdocMeta = pubPackageMetaProvider.fromFilename(_dartdocPath)!;
75-
await expectLater(process.stdout,
76-
emitsThrough('dartdoc version: ${dartdocMeta.version}'));
77-
await process.shouldExit(0);
78-
});
79-
});
80-
8136
test('with tool errors cause non-zero exit when warnings are off', () async {
8237
// TODO(srawlins): Remove test_package_tool_error and generate afresh.
8338
var packagePath = await d.createPackage('test_package');

test/options_test.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:args/args.dart';
66
import 'package:dartdoc/src/dartdoc_options.dart';
77
import 'package:dartdoc/src/failure.dart';
8+
import 'package:dartdoc/src/logging.dart';
89
import 'package:path/path.dart' as path;
910
import 'package:test/test.dart';
1011
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -472,6 +473,37 @@ class Foo {}
472473
'message', startsWith('Missing required template file'))));
473474
}
474475

476+
void test_emptyPackage() async {
477+
await createPackage();
478+
await (await buildDartdoc()).generateDocs();
479+
480+
expect(outBuffer, isEmpty);
481+
expect(
482+
errBuffer.toString(),
483+
matches('warning: package:test_package has no documentable libraries'),
484+
);
485+
}
486+
487+
void test_helpOption_resultsInPrintedHelp() async {
488+
startLogging(
489+
isJson: false,
490+
isQuiet: false,
491+
showProgress: false,
492+
outSink: outBuffer,
493+
errSink: errBuffer,
494+
);
495+
parseOptions(packageMetaProvider, ['--help']);
496+
497+
expect(
498+
outBuffer.toString().split('\n'),
499+
containsAll([
500+
'Generate HTML documentation for Dart libraries.',
501+
matches('^-h, --help[ ]+Show command help.')
502+
]),
503+
);
504+
expect(errBuffer.toString(), isEmpty);
505+
}
506+
475507
void test_quietOption_resultsInNoProgressOrOtherLogging() async {
476508
await createPackage(
477509
libFiles: [
@@ -647,4 +679,17 @@ class Foo {
647679
additionalArguments: ['--max-total-size', '15000000']);
648680
await dartdoc.generateDocs();
649681
}
682+
683+
void test_versionOption_resultsInPrintedVersion() async {
684+
startLogging(
685+
isJson: false,
686+
isQuiet: false,
687+
showProgress: false,
688+
outSink: outBuffer,
689+
errSink: errBuffer,
690+
);
691+
parseOptions(packageMetaProvider, ['--version']);
692+
693+
expect(outBuffer.toString(), matches(r'dartdoc version: \d+.\d+.\d+'));
694+
}
650695
}

0 commit comments

Comments
 (0)