Skip to content

Migrate most end2end tests; null safety tweaks #2882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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.

// @dart=2.9

library dartdoc.bin;

import 'dart:async';
Expand Down
23 changes: 12 additions & 11 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1071,34 +1071,35 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
_OptionValueWithContext<T>? _valueAtFromArgsWithContext() {
if (!_argResults.wasParsed(argName)) return null;

T retval;
// Unlike in _DartdocFileOption, we throw here on inputs being invalid
// rather than silently proceeding. This is because the user presumably
// typed something wrong on the command line and can therefore fix it.
// dartdoc_option.yaml files from other packages may not be fully in the
// user's control.
if (_isBool || _isListString || _isString) {
retval = _argResults[argName];
return _OptionValueWithContext(
_argResults[argName], _directoryCurrentPath);
} else if (_isInt) {
retval = int.tryParse(_argResults[argName]) as T;
if (retval == null) _throwErrorForTypes(_argResults[argName]);
var value = int.tryParse(_argResults[argName]);
if (value == null) _throwErrorForTypes(_argResults[argName]);
return _OptionValueWithContext(value as T, _directoryCurrentPath);
} else if (_isDouble) {
retval = double.tryParse(_argResults[argName]) as T;
if (retval == null) _throwErrorForTypes(_argResults[argName]);
var value = double.tryParse(_argResults[argName]);
if (value == null) _throwErrorForTypes(_argResults[argName]);
return _OptionValueWithContext(value as T, _directoryCurrentPath);
} else if (_isMapString) {
retval = <String, String>{} as T;
var value = <String, String>{};
for (String pair in _argResults[argName]) {
var pairList = pair.split('::');
if (pairList.length != 2) {
_throwErrorForTypes(pair);
}
assert(pairList.length == 2);
(retval as Map<String, String>)[pairList.first] = pairList.last;
value[pairList.first] = pairList.last;
}
return _OptionValueWithContext(value as T, _directoryCurrentPath);
} else {
throw UnsupportedError('Type $T is not supported');
}
return _OptionValueWithContext(retval, _directoryCurrentPath);
}

/// The name of this option as a command line argument.
Expand Down Expand Up @@ -1130,7 +1131,7 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
if (_isBool) {
argParser.addFlag(argName,
abbr: abbr,
defaultsTo: defaultsTo as bool,
defaultsTo: defaultsTo as bool?,
help: help,
hide: hide,
negatable: negatable);
Expand Down
12 changes: 6 additions & 6 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,13 @@ mixin DocumentationComment
return await config.tools.runner.run(args, content: basicMatch[2]!,
toolErrorCallback: (String message) async {
warn(PackageWarning.toolError, message: message);
},
environment: _toolsEnvironment(invocationIndex: invocationIndex)
as Map<String, String>);
}, environment: _toolsEnvironment(invocationIndex: invocationIndex));
});
}

/// The environment variables to use when running a tool.
Map<String, String?> _toolsEnvironment({required int invocationIndex}) {
return {
Map<String, String> _toolsEnvironment({required int invocationIndex}) {
var env = {
'SOURCE_LINE': characterLocation?.lineNumber.toString(),
'SOURCE_COLUMN': characterLocation?.columnNumber.toString(),
if (sourceFileName != null && package?.packagePath != null)
Expand All @@ -292,7 +290,9 @@ mixin DocumentationComment
'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
'INVOCATION_INDEX': invocationIndex.toString(),
'PACKAGE_INVOCATION_INDEX': (package?.toolInvocationIndex++).toString(),
}..removeWhere((key, value) => value == null);
};
return (env..removeWhere((key, value) => value == null))
.cast<String, String>();
}

/// Replace &#123;@example ...&#125; in API comments with the content of named file.
Expand Down
6 changes: 2 additions & 4 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import 'package:dartdoc/src/package_meta.dart'
import 'package:dartdoc/src/quiver.dart' as quiver;
import 'package:dartdoc/src/render/renderer_factory.dart';
import 'package:dartdoc/src/special_elements.dart';
import 'package:package_config/package_config.dart';
import 'package:path/path.dart' as path show Context;

/// Everything you need to instantiate a PackageGraph object for documenting.
Expand Down Expand Up @@ -251,9 +250,8 @@ class PubPackageBuilder implements PackageBuilder {
var packageDirs = {basePackageDir};

if (autoIncludeDependencies) {
var info = await (packageConfigProvider
.findPackageConfig(resourceProvider.getFolder(basePackageDir))
as FutureOr<PackageConfig>);
var info = (await packageConfigProvider
.findPackageConfig(resourceProvider.getFolder(basePackageDir)))!;
for (var package in info.packages) {
if (!filterExcludes || !config.exclude.contains(package.name)) {
packageDirs.add(_pathContext.dirname(
Expand Down
73 changes: 35 additions & 38 deletions test/dartdoc_options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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.

// @dart=2.9

library dartdoc.options_test;

import 'package:analyzer/file_system/file_system.dart';
Expand All @@ -15,16 +13,16 @@ import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

class ConvertedOption {
final String param1;
final String param2;
final String? param1;
final String? param2;
final String myContextPath;

ConvertedOption._(this.param1, this.param2, this.myContextPath);

static ConvertedOption fromYamlMap(YamlMap yamlMap, String canonicalYamlPath,
ResourceProvider resourceProvider) {
String p1;
String p2;
String? p1;
String? p2;

for (var entry in yamlMap.entries) {
switch (entry.key.toString()) {
Expand All @@ -43,20 +41,19 @@ class ConvertedOption {
void main() {
var resourceProvider = pubPackageMetaProvider.resourceProvider;

DartdocOptionRoot dartdocOptionSetFiles;
DartdocOptionRoot dartdocOptionSetArgs;
DartdocOptionRoot dartdocOptionSetAll;
DartdocOptionRoot dartdocOptionSetSynthetic;
Folder tempDir;
Folder firstDir;
Folder secondDir;
Folder secondDirFirstSub;
Folder secondDirSecondSub;

File dartdocOptionsOne;
File dartdocOptionsTwo;
File dartdocOptionsTwoFirstSub;
File firstExisting;
late final DartdocOptionRoot dartdocOptionSetFiles;
late final DartdocOptionRoot dartdocOptionSetArgs;
late final DartdocOptionRoot dartdocOptionSetAll;
late final DartdocOptionRoot dartdocOptionSetSynthetic;
late final Folder tempDir;
late final Folder firstDir;
late final Folder secondDir;
late final Folder secondDirFirstSub;
late final Folder secondDirSecondSub;

late final File dartdocOptionsOne;
late final File dartdocOptionsTwo;
late final File firstExisting;

setUpAll(() {
dartdocOptionSetSynthetic = DartdocOptionRoot('dartdoc', resourceProvider);
Expand Down Expand Up @@ -98,24 +95,24 @@ void main() {
dartdocOptionSetFiles.add(DartdocOptionFileOnly<List<String>>(
'fileOptionList', [], resourceProvider,
optionIs: OptionKind.file, mustExist: true));
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String>(
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String?>(
'fileOption', null, resourceProvider,
optionIs: OptionKind.file, mustExist: true));
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String>(
'parentOverride', 'oops', resourceProvider,
parentDirOverridesChild: true));
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String>(
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String?>(
'nonCriticalFileOption', null, resourceProvider,
optionIs: OptionKind.file));
dartdocOptionSetFiles.add(DartdocOptionSet('nestedOption', resourceProvider)
..addAll([DartdocOptionFileOnly<bool>('flag', false, resourceProvider)]));
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String>(
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String?>(
'dirOption', null, resourceProvider,
optionIs: OptionKind.dir, mustExist: true));
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String>(
dartdocOptionSetFiles.add(DartdocOptionFileOnly<String?>(
'nonCriticalDirOption', null, resourceProvider,
optionIs: OptionKind.dir));
dartdocOptionSetFiles.add(DartdocOptionFileOnly<ConvertedOption>(
dartdocOptionSetFiles.add(DartdocOptionFileOnly<ConvertedOption?>(
'convertThisMap',
null,
resourceProvider,
Expand Down Expand Up @@ -166,7 +163,7 @@ void main() {
'mapOption', {'hi': 'there'}, resourceProvider));
dartdocOptionSetAll.add(DartdocOptionArgFile<String>(
'notInAnyFile', 'so there', resourceProvider));
dartdocOptionSetAll.add(DartdocOptionArgFile<String>(
dartdocOptionSetAll.add(DartdocOptionArgFile<String?>(
'fileOption', null, resourceProvider,
optionIs: OptionKind.file, mustExist: true));
dartdocOptionSetAll.add(DartdocOptionArgFile<List<String>>(
Expand Down Expand Up @@ -202,7 +199,7 @@ void main() {
.join(firstDir.path, 'dartdoc_options.yaml'));
dartdocOptionsTwo = resourceProvider.getFile(resourceProvider.pathContext
.join(secondDir.path, 'dartdoc_options.yaml'));
dartdocOptionsTwoFirstSub = resourceProvider.getFile(resourceProvider
var dartdocOptionsTwoFirstSub = resourceProvider.getFile(resourceProvider
.pathContext
.join(secondDirFirstSub.path, 'dartdoc_options.yaml'));

Expand Down Expand Up @@ -265,7 +262,7 @@ dartdoc:
dartdocOptionSetSynthetic['vegetableLoaderChecked'].valueAt(firstDir),
orderedEquals([path.canonicalize(firstExisting.path)]));

String errorMessage;
String? errorMessage;
try {
dartdocOptionSetSynthetic['vegetableLoaderChecked'].valueAt(tempDir);
} on DartdocFileMissing catch (e) {
Expand Down Expand Up @@ -313,7 +310,7 @@ dartdoc:
() {
dartdocOptionSetAll
.parseArguments(['--file-option', 'override-not-existing.dart']);
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetAll['fileOption'].valueAt(firstDir);
} on DartdocFileMissing catch (e) {
Expand All @@ -338,7 +335,7 @@ dartdoc:

test('File errors still get passed through', () {
dartdocOptionSetAll.parseArguments([]);
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetAll['fileOption'].valueAt(secondDir);
} on DartdocFileMissing catch (e) {
Expand Down Expand Up @@ -456,7 +453,7 @@ dartdoc:
});

test('DartdocOptionArgOnly checks file existence', () {
String errorMessage;
String? errorMessage;
dartdocOptionSetArgs.parseArguments(['--single-file', 'not_found.txt']);
try {
dartdocOptionSetArgs['singleFile'].valueAt(tempDir);
Expand All @@ -474,7 +471,7 @@ dartdoc:
});

test('DartdocOptionArgOnly checks file existence on multi-options', () {
String errorMessage;
String? errorMessage;
dartdocOptionSetArgs.parseArguments([
'--files-flag',
resourceProvider.pathContext.absolute(firstExisting.path),
Expand Down Expand Up @@ -571,7 +568,7 @@ dartdoc:

test('DartdocOptionArgOnly throws on double type mismatch', () {
dartdocOptionSetArgs.parseArguments(['--respawn-probability', 'unknown']);
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetArgs['respawnProbability'].valueAt(tempDir);
} on DartdocOptionError catch (e) {
Expand All @@ -587,7 +584,7 @@ dartdoc:
dartdocOptionSetArgs.parseArguments(['--number-of-heads', '3.6']);
expect(() => dartdocOptionSetArgs['number_of_heads'].valueAt(tempDir),
throwsA(const TypeMatcher<DartdocOptionError>()));
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetArgs['number_of_heads'].valueAt(tempDir);
} on DartdocOptionError catch (e) {
Expand All @@ -602,7 +599,7 @@ dartdoc:
test('DartdocOptionArgOnly throws on a map type mismatch', () {
dartdocOptionSetArgs
.parseArguments(['--a-fancy-map-variable', 'not a map']);
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetArgs['aFancyMapVariable'].valueAt(tempDir);
} on DartdocOptionError catch (e) {
Expand All @@ -628,7 +625,7 @@ dartdoc:
});

test('DartdocOptionSetFile checks file existence when appropriate', () {
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetFiles['fileOptionList'].valueAt(secondDir);
} on DartdocFileMissing catch (e) {
Expand All @@ -654,7 +651,7 @@ dartdoc:
test(
'DartdocOptionSetFile resolves paths for files relative to where they are declared',
() {
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetFiles['fileOption'].valueAt(secondDirFirstSub);
} on DartdocFileMissing catch (e) {
Expand All @@ -681,7 +678,7 @@ dartdoc:
test('DartdocOptionSetFile checks errors for directory options', () {
expect(dartdocOptionSetFiles['dirOption'].valueAt(secondDir),
equals(path.canonicalize(path.join(secondDir.path, 'firstSub'))));
String errorMessage;
String? errorMessage;
try {
dartdocOptionSetFiles['dirOption'].valueAt(firstDir);
} on DartdocFileMissing catch (e) {
Expand Down
14 changes: 6 additions & 8 deletions test/end2end/dartdoc_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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.

// @dart=2.9

library dartdoc.dartdoc_integration_test;

import 'dart:async';
Expand All @@ -18,7 +16,7 @@ import '../../tool/subprocess_launcher.dart';
import '../src/utils.dart';

Uri get _currentFileUri =>
(reflect(main) as ClosureMirror).function.location.sourceUri;
(reflect(main) as ClosureMirror).function.location!.sourceUri;
String get _testPackagePath =>
path.fromUri(_currentFileUri.resolve('../../testing/test_package'));
String get _testPackageFlutterPluginPath => path.fromUri(_currentFileUri
Expand All @@ -29,8 +27,8 @@ String get _testPackageMinimumPath =>
void main() {
group('Invoking command-line dartdoc', () {
var dartdocPath = path.canonicalize(path.join('bin', 'dartdoc.dart'));
CoverageSubprocessLauncher subprocessLauncher;
Directory tempDir;
late final CoverageSubprocessLauncher subprocessLauncher;
late final Directory tempDir;

setUpAll(() async {
tempDir =
Expand Down Expand Up @@ -181,7 +179,7 @@ void main() {
await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath,
perLine: (s) => output.writeln(s));
var dartdocMeta = pubPackageMetaProvider.fromFilename(dartdocPath);
var dartdocMeta = pubPackageMetaProvider.fromFilename(dartdocPath)!;
expect(output.toString(),
endsWith('dartdoc version: ${dartdocMeta.version}\n'));
});
Expand Down Expand Up @@ -238,9 +236,9 @@ void main() {
var footerRegex =
RegExp(r'<footer>(.*\s*?\n?)+?</footer>', multiLine: true);
// get footer, check for version number
var m = footerRegex.firstMatch(outFile.readAsStringSync());
var m = footerRegex.firstMatch(outFile.readAsStringSync())!;
var version = RegExp(r'(\d+\.)?(\d+\.)?(\*|\d+)');
expect(version.hasMatch(m.group(0)), false);
expect(version.hasMatch(m.group(0)!), false);
});
}, timeout: Timeout.factor(8));
}
Loading