Skip to content

Commit

Permalink
Move several E2E integration test cases to options_test (#3585)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Nov 21, 2023
1 parent d7723c9 commit 6368fcd
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 94 deletions.
6 changes: 5 additions & 1 deletion lib/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ DartdocProgramOptionContext? parseOptions(
exitCode = 64;
return null;
}
startLogging(config);
startLogging(
isJson: config.json,
isQuiet: config.quiet,
showProgress: config.showProgress,
);
return config;
}

Expand Down
41 changes: 28 additions & 13 deletions lib/src/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class _DartdocLogger {
static _DartdocLogger instance =
_DartdocLogger._(isJson: false, isQuiet: true, showProgress: false);

final StringSink _outSink;
final StringSink _errSink;

final bool _showProgressBar;

ProgressBar? _progressBar;
Expand All @@ -93,7 +96,11 @@ class _DartdocLogger {
required bool isJson,
required bool isQuiet,
required bool showProgress,
}) : _showProgressBar = showProgress && !isJson && !isQuiet {
StringSink? outSink,
StringSink? errSink,
}) : _outSink = outSink ?? io.stdout,
_errSink = errSink ?? io.stderr,
_showProgressBar = showProgress && !isJson && !isQuiet {
// By default, get all log output at `progressLevel` or greater.
// This allows us to capture progress events and print `...`.
// Change this to `Level.FINE` for debug logging.
Expand All @@ -120,7 +127,7 @@ class _DartdocLogger {

Logger.root.onRecord.listen((record) {
if (record.level == progressBarUpdate) {
io.stdout.write(record.message);
_outSink.write(record.message);
return;
}

Expand All @@ -129,10 +136,10 @@ class _DartdocLogger {
showProgress &&
stopwatch.elapsed.inMilliseconds > 125) {
if (writingProgress = false) {
io.stdout.write(' ');
_outSink.write(' ');
}
writingProgress = true;
io.stdout.write('$_backspace${spinner[spinnerIndex]}');
_outSink.write('$_backspace${spinner[spinnerIndex]}');
spinnerIndex = (spinnerIndex + 1) % spinner.length;
stopwatch.reset();
}
Expand All @@ -141,22 +148,22 @@ class _DartdocLogger {

stopwatch.reset();
if (writingProgress) {
io.stdout.write('$_backspace $_backspace');
_outSink.write('$_backspace $_backspace');
}
var message = record.message;
assert(message.isNotEmpty);

if (record.level < Level.WARNING) {
if (!isQuiet) {
print(message);
_outSink.writeln(message);
}
} else {
if (writingProgress) {
// Some console implementations, like IntelliJ, apparently need
// the backspace to occur for stderr as well.
io.stderr.write('$_backspace $_backspace');
_errSink.write('$_backspace $_backspace');
}
io.stderr.writeln(message);
_errSink.writeln(message);
}
writingProgress = false;
});
Expand Down Expand Up @@ -204,15 +211,23 @@ class _DartdocLogger {
output['message'] = record.message;
}

print(json.encode(output));
_outSink.writeln(json.encode(output));
}
}

void startLogging(LoggingContext config) {
void startLogging({
required bool isJson,
required bool isQuiet,
required bool showProgress,
StringSink? outSink,
StringSink? errSink,
}) {
_DartdocLogger.instance = _DartdocLogger._(
isJson: config.json,
isQuiet: config.quiet,
showProgress: config.showProgress,
isJson: isJson,
isQuiet: isQuiet,
showProgress: showProgress,
outSink: outSink ?? io.stdout,
errSink: errSink ?? io.stderr,
);
}

Expand Down
70 changes: 0 additions & 70 deletions test/end2end/dartdoc_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,60 +60,6 @@ void main() {
]);
});

test('with --no-generate-docs is quiet and does not generate docs',
() async {
var process = await runDartdoc(
['--no-generate-docs'],
workingDirectory: packagePath,
);
await expectLater(
process.stderr, emitsThrough('Found 1 warning and 0 errors.'));
await process.shouldExit(0);
var docs = Directory(path.join(packagePath, 'doc', 'api'));
expect(docs.existsSync(), isFalse);
});

test('with --quiet is quiet and does generate docs', () async {
var process = await runDartdoc(
['--quiet'],
workingDirectory: packagePath,
);
await expectLater(process.stderr, emitsThrough(matches('^ warning:')));
await expectLater(
process.stderr, emitsThrough('Found 1 warning and 0 errors.'));
await process.shouldExit(0);
var indexHtml = Directory(path.join(packagePath, 'doc', 'api'));
expect(indexHtml.listSync(), isNotEmpty);
});

test('with invalid options return non-zero and print a fatal-error',
() async {
var process = await runDartdoc(
['--nonexisting'],
workingDirectory: packagePath,
);
await expectLater(
process.stderr,
emitsThrough(
' fatal error: Could not find an option named "nonexisting".'));
await process.shouldExit(64);
});

test('missing a required file path prints a fatal error', () async {
var process = await runDartdoc(
['--input', 'non-existant'],
workingDirectory: packagePath,
);
var fullPath = path.canonicalize(path.join(packagePath, 'non-existant'));
await expectLater(
process.stderr,
emitsThrough(
' fatal error: Argument --input, set to non-existant, resolves to '
'missing path: "$fullPath"'),
);
await process.shouldExit(64);
});

test('with --help prints command line args', () async {
var process = await runDartdoc(
['--help'],
Expand All @@ -136,22 +82,6 @@ void main() {
emitsThrough('dartdoc version: ${dartdocMeta.version}'));
await process.shouldExit(0);
});

test('Validate JSON output', () async {
var process = await runDartdoc(
[
//dartdocPath,
'--no-include-source',
'--json',
],
workingDirectory: packagePath,
);
await expectLater(
process.stdout,
emitsThrough(
'{"level":"WARNING","message":"Found 1 warning and 0 errors."}'));
await process.shouldExit(0);
});
});

test('with tool errors cause non-zero exit when warnings are off', () async {
Expand Down
5 changes: 1 addition & 4 deletions test/end2end/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ void main() {
[createDartdocProgramOptions, createLoggingOptions],
pubPackageMetaProvider);
optionSet.parseArguments([]);
startLogging(DartdocLoggingOptionContext(
optionSet,
_resourceProvider.getFolder(_pathContext.current),
_resourceProvider));
startLogging(isJson: false, isQuiet: true, showProgress: false);

// Set up the pub metadata for our test packages.
runPubGet(testPackageToolError.path);
Expand Down
Loading

0 comments on commit 6368fcd

Please sign in to comment.