Skip to content

Commit

Permalink
Simplify some end2end tests into smaller tests (#3795)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jun 26, 2024
1 parent 36f1fc7 commit 7e5da60
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 64 deletions.
19 changes: 4 additions & 15 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,6 @@ class DartdocProgramOptionContext extends DartdocGeneratorOptionContext

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

List<DartdocOption<bool>> createDartdocProgramOptions(
Expand Down Expand Up @@ -1472,12 +1470,14 @@ DartdocProgramOptionContext? parseOptions(
return null;
}
if (optionRoot['help'].valueAtCurrent() as bool) {
_printHelp(optionRoot.argParser);
logInfo('dartdoc version: $dartdocVersion');
logInfo('Generate HTML documentation for Dart libraries.\n');
logInfo(optionRoot.argParser.usage);
exitCode = 0;
return null;
}
if (optionRoot['version'].valueAtCurrent() as bool) {
_printVersion(optionRoot.argParser);
logInfo('dartdoc version: $dartdocVersion');
exitCode = 0;
return null;
}
Expand All @@ -1501,23 +1501,12 @@ DartdocProgramOptionContext? parseOptions(
return config;
}

/// Print help if we are passed the help option.
void _printHelp(ArgParser parser) {
print('Generate HTML documentation for Dart libraries.\n');
print(parser.usage);
}

/// Print usage information on invalid command lines.
void _printUsage(ArgParser parser) {
print('Usage: dartdoc [OPTIONS]\n');
print(parser.usage);
}

/// Print version information.
void _printVersion(ArgParser parser) {
print('dartdoc version: $dartdocVersion');
}

/// Instantiate dartdoc's configuration file and options parser with the
/// given command line arguments.
List<DartdocOption> createDartdocOptions(
Expand Down
4 changes: 0 additions & 4 deletions lib/src/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ void logProgress(String message) {
_logger.log(_progressLevel, message);
}

void logPrint(String message) {
_logger.log(printLevel, message);
}

/// Creates a new deterministic progress bar, and displays it (with zero
/// progress).
void progressBarStart(int totalTickCount) {
Expand Down
45 changes: 0 additions & 45 deletions test/end2end/dartdoc_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ library;
import 'dart:async';
import 'dart:io';

import 'package:dartdoc/src/package_meta.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';
Expand All @@ -34,50 +33,6 @@ Future<TestProcess> runDartdoc(
);

void main() {
test('invoking dartdoc on an empty package does not crash', () async {
var packagePath = await d.createPackage('empty');
var process = await runDartdoc([], workingDirectory: packagePath);
await expectLater(
process.stderr,
emitsThrough(
contains('package:test_package has no documentable libraries')),
);
await process.shouldExit(0);
});

group('invoking dartdoc on a basic package', () {
late String packagePath;

setUp(() async {
packagePath = await d.createPackage('test_package', libFiles: [
d.file('lib.dart', '/// [dead] reference\nclass C {}'),
]);
});

test('with --help prints command line args', () async {
var process = await runDartdoc(
['--help'],
workingDirectory: packagePath,
);
await expectLater(process.stdout,
emitsThrough('Generate HTML documentation for Dart libraries.'));
await expectLater(process.stdout,
emitsThrough(matches('^-h, --help[ ]+Show command help.')));
await process.shouldExit(0);
});

test('Validate --version works', () async {
var process = await runDartdoc(
['--version'],
workingDirectory: packagePath,
);
var dartdocMeta = pubPackageMetaProvider.fromFilename(_dartdocPath)!;
await expectLater(process.stdout,
emitsThrough('dartdoc version: ${dartdocMeta.version}'));
await process.shouldExit(0);
});
});

test('with tool errors cause non-zero exit when warnings are off', () async {
// TODO(srawlins): Remove test_package_tool_error and generate afresh.
var packagePath = await d.createPackage('test_package');
Expand Down
45 changes: 45 additions & 0 deletions test/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:args/args.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
Expand Down Expand Up @@ -472,6 +473,37 @@ class Foo {}
'message', startsWith('Missing required template file'))));
}

void test_emptyPackage() async {
await createPackage();
await (await buildDartdoc()).generateDocs();

expect(outBuffer, isEmpty);
expect(
errBuffer.toString(),
matches('warning: package:test_package has no documentable libraries'),
);
}

void test_helpOption_resultsInPrintedHelp() async {
startLogging(
isJson: false,
isQuiet: false,
showProgress: false,
outSink: outBuffer,
errSink: errBuffer,
);
parseOptions(packageMetaProvider, ['--help']);

expect(
outBuffer.toString().split('\n'),
containsAll([
'Generate HTML documentation for Dart libraries.',
matches('^-h, --help[ ]+Show command help.')
]),
);
expect(errBuffer.toString(), isEmpty);
}

void test_quietOption_resultsInNoProgressOrOtherLogging() async {
await createPackage(
libFiles: [
Expand Down Expand Up @@ -647,4 +679,17 @@ class Foo {
additionalArguments: ['--max-total-size', '15000000']);
await dartdoc.generateDocs();
}

void test_versionOption_resultsInPrintedVersion() async {
startLogging(
isJson: false,
isQuiet: false,
showProgress: false,
outSink: outBuffer,
errSink: errBuffer,
);
parseOptions(packageMetaProvider, ['--version']);

expect(outBuffer.toString(), matches(r'dartdoc version: \d+.\d+.\d+'));
}
}

0 comments on commit 7e5da60

Please sign in to comment.