Skip to content

Commit 6368fcd

Browse files
authored
Move several E2E integration test cases to options_test (#3585)
1 parent d7723c9 commit 6368fcd

File tree

6 files changed

+177
-94
lines changed

6 files changed

+177
-94
lines changed

lib/options.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ DartdocProgramOptionContext? parseOptions(
127127
exitCode = 64;
128128
return null;
129129
}
130-
startLogging(config);
130+
startLogging(
131+
isJson: config.json,
132+
isQuiet: config.quiet,
133+
showProgress: config.showProgress,
134+
);
131135
return config;
132136
}
133137

lib/src/logging.dart

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class _DartdocLogger {
8585
static _DartdocLogger instance =
8686
_DartdocLogger._(isJson: false, isQuiet: true, showProgress: false);
8787

88+
final StringSink _outSink;
89+
final StringSink _errSink;
90+
8891
final bool _showProgressBar;
8992

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

121128
Logger.root.onRecord.listen((record) {
122129
if (record.level == progressBarUpdate) {
123-
io.stdout.write(record.message);
130+
_outSink.write(record.message);
124131
return;
125132
}
126133

@@ -129,10 +136,10 @@ class _DartdocLogger {
129136
showProgress &&
130137
stopwatch.elapsed.inMilliseconds > 125) {
131138
if (writingProgress = false) {
132-
io.stdout.write(' ');
139+
_outSink.write(' ');
133140
}
134141
writingProgress = true;
135-
io.stdout.write('$_backspace${spinner[spinnerIndex]}');
142+
_outSink.write('$_backspace${spinner[spinnerIndex]}');
136143
spinnerIndex = (spinnerIndex + 1) % spinner.length;
137144
stopwatch.reset();
138145
}
@@ -141,22 +148,22 @@ class _DartdocLogger {
141148

142149
stopwatch.reset();
143150
if (writingProgress) {
144-
io.stdout.write('$_backspace $_backspace');
151+
_outSink.write('$_backspace $_backspace');
145152
}
146153
var message = record.message;
147154
assert(message.isNotEmpty);
148155

149156
if (record.level < Level.WARNING) {
150157
if (!isQuiet) {
151-
print(message);
158+
_outSink.writeln(message);
152159
}
153160
} else {
154161
if (writingProgress) {
155162
// Some console implementations, like IntelliJ, apparently need
156163
// the backspace to occur for stderr as well.
157-
io.stderr.write('$_backspace $_backspace');
164+
_errSink.write('$_backspace $_backspace');
158165
}
159-
io.stderr.writeln(message);
166+
_errSink.writeln(message);
160167
}
161168
writingProgress = false;
162169
});
@@ -204,15 +211,23 @@ class _DartdocLogger {
204211
output['message'] = record.message;
205212
}
206213

207-
print(json.encode(output));
214+
_outSink.writeln(json.encode(output));
208215
}
209216
}
210217

211-
void startLogging(LoggingContext config) {
218+
void startLogging({
219+
required bool isJson,
220+
required bool isQuiet,
221+
required bool showProgress,
222+
StringSink? outSink,
223+
StringSink? errSink,
224+
}) {
212225
_DartdocLogger.instance = _DartdocLogger._(
213-
isJson: config.json,
214-
isQuiet: config.quiet,
215-
showProgress: config.showProgress,
226+
isJson: isJson,
227+
isQuiet: isQuiet,
228+
showProgress: showProgress,
229+
outSink: outSink ?? io.stdout,
230+
errSink: errSink ?? io.stderr,
216231
);
217232
}
218233

test/end2end/dartdoc_integration_test.dart

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -60,60 +60,6 @@ void main() {
6060
]);
6161
});
6262

63-
test('with --no-generate-docs is quiet and does not generate docs',
64-
() async {
65-
var process = await runDartdoc(
66-
['--no-generate-docs'],
67-
workingDirectory: packagePath,
68-
);
69-
await expectLater(
70-
process.stderr, emitsThrough('Found 1 warning and 0 errors.'));
71-
await process.shouldExit(0);
72-
var docs = Directory(path.join(packagePath, 'doc', 'api'));
73-
expect(docs.existsSync(), isFalse);
74-
});
75-
76-
test('with --quiet is quiet and does generate docs', () async {
77-
var process = await runDartdoc(
78-
['--quiet'],
79-
workingDirectory: packagePath,
80-
);
81-
await expectLater(process.stderr, emitsThrough(matches('^ warning:')));
82-
await expectLater(
83-
process.stderr, emitsThrough('Found 1 warning and 0 errors.'));
84-
await process.shouldExit(0);
85-
var indexHtml = Directory(path.join(packagePath, 'doc', 'api'));
86-
expect(indexHtml.listSync(), isNotEmpty);
87-
});
88-
89-
test('with invalid options return non-zero and print a fatal-error',
90-
() async {
91-
var process = await runDartdoc(
92-
['--nonexisting'],
93-
workingDirectory: packagePath,
94-
);
95-
await expectLater(
96-
process.stderr,
97-
emitsThrough(
98-
' fatal error: Could not find an option named "nonexisting".'));
99-
await process.shouldExit(64);
100-
});
101-
102-
test('missing a required file path prints a fatal error', () async {
103-
var process = await runDartdoc(
104-
['--input', 'non-existant'],
105-
workingDirectory: packagePath,
106-
);
107-
var fullPath = path.canonicalize(path.join(packagePath, 'non-existant'));
108-
await expectLater(
109-
process.stderr,
110-
emitsThrough(
111-
' fatal error: Argument --input, set to non-existant, resolves to '
112-
'missing path: "$fullPath"'),
113-
);
114-
await process.shouldExit(64);
115-
});
116-
11763
test('with --help prints command line args', () async {
11864
var process = await runDartdoc(
11965
['--help'],
@@ -136,22 +82,6 @@ void main() {
13682
emitsThrough('dartdoc version: ${dartdocMeta.version}'));
13783
await process.shouldExit(0);
13884
});
139-
140-
test('Validate JSON output', () async {
141-
var process = await runDartdoc(
142-
[
143-
//dartdocPath,
144-
'--no-include-source',
145-
'--json',
146-
],
147-
workingDirectory: packagePath,
148-
);
149-
await expectLater(
150-
process.stdout,
151-
emitsThrough(
152-
'{"level":"WARNING","message":"Found 1 warning and 0 errors."}'));
153-
await process.shouldExit(0);
154-
});
15585
});
15686

15787
test('with tool errors cause non-zero exit when warnings are off', () async {

test/end2end/dartdoc_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ void main() {
5050
[createDartdocProgramOptions, createLoggingOptions],
5151
pubPackageMetaProvider);
5252
optionSet.parseArguments([]);
53-
startLogging(DartdocLoggingOptionContext(
54-
optionSet,
55-
_resourceProvider.getFolder(_pathContext.current),
56-
_resourceProvider));
53+
startLogging(isJson: false, isQuiet: true, showProgress: false);
5754

5855
// Set up the pub metadata for our test packages.
5956
runPubGet(testPackageToolError.path);

0 commit comments

Comments
 (0)