Skip to content

Add back other tests from compare_output_test that weren't actually the compare_output_test #1882

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 19 commits into from
Jan 3, 2019
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1aba175
Cleanup and move test-only code into the test utils library
jcollins-g Dec 20, 2018
7a2517c
Fix coverage for binary-level tests
jcollins-g Dec 21, 2018
89564a8
dartfmt
jcollins-g Dec 21, 2018
1ae1057
Merge branch 'master' into cleanup-more-unused
jcollins-g Dec 21, 2018
21b8d1c
Merge branch 'cleanup-more-unused' into cleanup-more-unused+coverage-…
jcollins-g Dec 21, 2018
5777288
Adjust timeout factor
jcollins-g Dec 22, 2018
288274b
Unconditionally add coverage path environment variable
jcollins-g Dec 22, 2018
5956cf6
Move main up to the top; coverage runs take a bit more time
jcollins-g Jan 2, 2019
1bee3cd
Remove compare_output_test
jcollins-g Jan 2, 2019
deb498e
Merge branch 'master' into cleanup-more-unused+coverage-enhancement
jcollins-g Jan 2, 2019
1ee6c05
Merge branch 'cleanup-more-unused+coverage-enhancement' into coverage…
jcollins-g Jan 2, 2019
f362635
Port tests that weren't actually the compare_output_test to dartdoc_test
jcollins-g Jan 2, 2019
3f6dd5c
git attributes for output test removal
jcollins-g Jan 2, 2019
6837013
Migrate coverage subprocessor correctly
jcollins-g Jan 2, 2019
c7adcab
git attributes for output test removal
jcollins-g Jan 2, 2019
5637a2a
Merge branch 'coverage-enhancement+no-compare-output-test' into no-co…
jcollins-g Jan 2, 2019
d16925e
dartfmt
jcollins-g Jan 2, 2019
d7d6f09
Merge branch 'master' into coverage-enhancement+no-compare-output-test
jcollins-g Jan 2, 2019
a4eada8
Merge branch 'coverage-enhancement+no-compare-output-test' into no-co…
jcollins-g Jan 2, 2019
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
128 changes: 122 additions & 6 deletions test/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library dartdoc.dartdoc_test;

import 'dart:async';
import 'dart:io';
import 'dart:mirrors';

import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/logging.dart';
Expand All @@ -17,6 +18,13 @@ import 'package:test/test.dart';

import 'src/utils.dart';

Uri get _currentFileUri =>
(reflect(main) as ClosureMirror).function.location.sourceUri;
String get _testPackagePath =>
pathLib.fromUri(_currentFileUri.resolve('../testing/test_package'));
String get _testPackageFlutterPluginPath => pathLib
.fromUri(_currentFileUri.resolve('../testing/test_package_flutter_plugin'));

class DartdocLoggingOptionContext extends DartdocGeneratorOptionContext
with LoggingContext {
DartdocLoggingOptionContext(DartdocOptionSet optionSet, Directory dir)
Expand All @@ -27,11 +35,8 @@ void main() {
group('dartdoc with generators', () {
Directory tempDir;
List<String> outputParam;
CoverageSubprocessLauncher subprocessLauncher;

setUpAll(() async {
subprocessLauncher =
new CoverageSubprocessLauncher('dartdoc_test-subprocesses');
tempDir = Directory.systemTemp.createTempSync('dartdoc.test.');
outputParam = ['--output', tempDir.path];
DartdocOptionSet optionSet = await DartdocOptionSet.fromOptionGenerators(
Expand All @@ -42,7 +47,6 @@ void main() {
});

tearDown(() async {
await Future.wait(CoverageSubprocessLauncher.coverageResults);
tempDir.listSync().forEach((FileSystemEntity f) {
f.deleteSync(recursive: true);
});
Expand Down Expand Up @@ -114,7 +118,18 @@ void main() {
});

group('Invoking command-line dartdoc', () {
String dartdocPath = pathLib.join('bin', 'dartdoc.dart');
String dartdocPath =
pathLib.canonicalize(pathLib.join('bin', 'dartdoc.dart'));
CoverageSubprocessLauncher subprocessLauncher;

setUpAll(() {
subprocessLauncher =
new CoverageSubprocessLauncher('dartdoc_test-subprocesses');
});

tearDownAll(() async {
await Future.wait(CoverageSubprocessLauncher.coverageResults);
});

test('errors cause non-zero exit when warnings are off', () async {
expect(
Expand All @@ -136,7 +151,108 @@ void main() {
]),
throwsA(const TypeMatcher<ProcessException>()));
});
});

test('Validate missing FLUTTER_ROOT exception is clean', () async {
StringBuffer output = new StringBuffer();
var args = <String>[dartdocPath];
Future run = subprocessLauncher.runStreamed(
Platform.resolvedExecutable, args,
environment: new Map.from(Platform.environment)
..remove('FLUTTER_ROOT'),
includeParentEnvironment: false,
workingDirectory: _testPackageFlutterPluginPath, perLine: (s) {
output.writeln(s);
});
// Asynchronous exception, but we still need the output, too.
expect(run, throwsA(new TypeMatcher<ProcessException>()));
try {
await run;
} on ProcessException catch (_) {}

expect(
output.toString(),
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(output.toString(), isNot(contains('asynchronous gap')));
});

test("Validate --version works", () async {
StringBuffer output = new StringBuffer();
var args = <String>[dartdocPath, '--version'];
await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath,
perLine: (s) => output.writeln(s));
PackageMeta dartdocMeta = new PackageMeta.fromFilename(dartdocPath);
expect(output.toString(),
endsWith('dartdoc version: ${dartdocMeta.version}\n'));
});

test('Check for sample code in examples', () async {
StringBuffer output = new StringBuffer();
var args = <String>[
dartdocPath,
'--include',
'ex',
'--no-include-source',
'--output',
tempDir.path
];

await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath,
perLine: (s) => output.writeln(s));

// Examples are reported as unfound because we (purposefully)
// did not use --example-path-prefix above.
final sep = '.'; // We don't care what the path separator character is
final firstUnfoundExample =
new RegExp('warning: lib${sep}example.dart: '
'@example file not found.*test_package${sep}dog${sep}food.md');
if (!output.toString().contains(firstUnfoundExample)) {
fail('Should warn about unfound @example files');
}
});

test('Validate JSON output', () async {
var args = <String>[
dartdocPath,
'--include',
'ex',
'--no-include-source',
'--output',
tempDir.path,
'--json'
];

Iterable<Map> jsonValues = await subprocessLauncher.runStreamed(
Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath);

expect(jsonValues, isNotEmpty,
reason: 'All STDOUT lines should be JSON-encoded maps.');
}, timeout: new Timeout.factor(2));

test('--footer-text includes text', () async {
String footerTextPath =
pathLib.join(Directory.systemTemp.path, 'footer.txt');
new File(footerTextPath).writeAsStringSync(' footer text include ');

var args = <String>[
dartdocPath,
'--footer-text=${footerTextPath}',
'--include',
'ex',
'--output',
tempDir.path
];

await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath);

File outFile = new File(pathLib.join(tempDir.path, 'index.html'));
expect(outFile.readAsStringSync(), contains('footer text include'));
});
}, timeout: new Timeout.factor(3));

group('Option handling with cross-linking', () {
DartdocResults results;
Expand Down