Skip to content
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

Fix flutter root exception #1714

Merged
merged 9 commits into from
Jun 14, 2018
21 changes: 12 additions & 9 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,12 @@ Future<List<DartdocOption>> createDartdocOptions() async {
// This could be a ArgOnly, but trying to not provide too many ways
// to set the flutter root.
new DartdocOptionSyntheticOnly<String>(
'flutterRoot',
(DartdocSyntheticOption<String> option, Directory dir) =>
resolveTildePath(Platform.environment['FLUTTER_ROOT']),
isDir: true,
help: 'Root of the Flutter SDK, specified from environment.',
mustExist: true,
),
'flutterRoot',
(DartdocSyntheticOption<String> option, Directory dir) =>
resolveTildePath(Platform.environment['FLUTTER_ROOT']),
isDir: true,
help: 'Root of the Flutter SDK, specified from environment.',
mustExist: true),
new DartdocOptionArgOnly<bool>('hideSdkText', false,
hide: true,
help:
Expand Down Expand Up @@ -1120,8 +1119,12 @@ Future<List<DartdocOption>> createDartdocOptions() async {
if (!option.parent['sdkDocs'].valueAt(dir) &&
(option.root['topLevelPackageMeta'].valueAt(dir) as PackageMeta)
.requiresFlutter) {
return pathLib.join(option.root['flutterRoot'].valueAt(dir), 'bin',
'cache', 'dart-sdk');
String flutterRoot = option.root['flutterRoot'].valueAt(dir);
if (flutterRoot == null) {
throw new DartdocOptionError(
'Top level package requires Flutter but FLUTTER_ROOT environment variable not set');
}
return pathLib.join(flutterRoot, 'bin', 'cache', 'dart-sdk');
}
return defaultSdkDir.absolute.path;
}, help: 'Path to the SDK directory.', isDir: true, mustExist: true),
Expand Down
18 changes: 18 additions & 0 deletions test/compare_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ String get _testPackageDocsPath =>
String get _testPackagePath =>
pathLib.fromUri(_currentFileUri.resolve('../testing/test_package'));

String get _testPackageFlutterPluginPath => pathLib
.fromUri(_currentFileUri.resolve('../testing/test_package_flutter_plugin'));

void main() {
group('compare outputs', () {
Directory tempDir;
Expand All @@ -44,6 +47,21 @@ void main() {
}
});

test('Validate missing FLUTTER_ROOT exception is clean', () async {
var args = <String>[dartdocBin];
var result = Process.runSync(Platform.resolvedExecutable, args,
environment: new Map.from(Platform.environment)
..remove('FLUTTER_ROOT'),
includeParentEnvironment: false,
workingDirectory: _testPackageFlutterPluginPath);
expect(
result.stderr,
contains(new RegExp(
'Top level package requires Flutter but FLUTTER_ROOT environment variable not set|test_package_flutter_plugin requires the Flutter SDK, version solving failed')));
expect(result.stderr, isNot(contains('asynchronous gap')));
expect(result.exitCode, isNot(0));
});

test("Validate --version works", () async {
var args = <String>[dartdocBin, '--version'];
var result = Process.runSync(Platform.resolvedExecutable, args,
Expand Down