Skip to content

Commit 6e3c1dd

Browse files
committed
add a test to check that resources are copied
Closes #758 Closes #757 LGTM given by: @devoncarew, @sethladd Squashed commit of the following: commit f0a8f8f Author: Seth Ladd <[email protected]> Date: Mon Aug 3 10:26:20 2015 -0700 more exact matcher commit 38aca6e Author: Seth Ladd <[email protected]> Date: Mon Aug 3 10:09:09 2015 -0700 add a test to check that resources are copied
1 parent 3bdd312 commit 6e3c1dd

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

lib/src/html_generator.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ class Templates {
124124
}
125125

126126
class HtmlGenerator extends Generator {
127+
/// Optional URL for where the docs will be hosted.
127128
final String url;
128129
final Templates _templates;
129130

131+
/// [url] can be null.
132+
// TODO: make url an optional parameter
130133
HtmlGenerator(this.url, {String header, String footer})
131134
: _templates = new Templates(header, footer);
132135

@@ -149,6 +152,19 @@ class HtmlGeneratorInstance {
149152
Future generate() async {
150153
await _templates.init();
151154
if (!out.existsSync()) out.createSync();
155+
156+
if (package != null) {
157+
_generateDocs();
158+
}
159+
160+
//if (url != null) generateSiteMap();
161+
162+
await _copyResources();
163+
}
164+
165+
void _generateDocs() {
166+
if (package == null) return;
167+
152168
generatePackage();
153169

154170
package.libraries.forEach((Library lib) {
@@ -206,10 +222,6 @@ class HtmlGeneratorInstance {
206222
generateTypeDef(package, lib, typeDef);
207223
});
208224
});
209-
210-
//if (url != null) generateSiteMap();
211-
212-
await _copyResources();
213225
}
214226

215227
void generatePackage() {

test/html_generator_test.dart

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
library dartdoc.html_generator_test;
66

7-
import 'package:test/test.dart';
7+
import 'dart:io' show File, Directory, FileSystemEntity, FileSystemEntityType;
88

9+
import 'package:path/path.dart' as p;
10+
import 'package:test/test.dart';
911
import 'package:dartdoc/src/html_generator.dart';
1012

1113
void main() {
@@ -66,6 +68,54 @@ void main() {
6668

6769
group('HtmlGenerator', () {
6870
// TODO: Run the HtmlGenerator and validate important constraints.
69-
71+
group('for a null package', () {
72+
HtmlGenerator generator;
73+
Directory tempOutput;
74+
75+
setUp(() async {
76+
generator = new HtmlGenerator(null);
77+
tempOutput = Directory.systemTemp.createTempSync('doc_test_temp');
78+
return generator.generate(null, tempOutput);
79+
});
80+
81+
tearDown(() {
82+
if (tempOutput != null) {
83+
tempOutput.deleteSync(recursive: true);
84+
}
85+
});
86+
87+
test('resources are put into the right place', () {
88+
Directory output =
89+
new Directory(p.join(tempOutput.path, 'static-assets'));
90+
expect(output, doesExist);
91+
new Directory(p.join('lib', 'resources'))
92+
.listSync(recursive: true)
93+
.forEach((FileSystemEntity f) {
94+
if (f.statSync().type == FileSystemEntityType.FILE) {
95+
String subPath =
96+
f.path.substring(p.join('lib', 'resources').length + 1);
97+
expect(new File(p.join(output.path, subPath)), doesExist);
98+
}
99+
});
100+
});
101+
});
70102
});
71103
}
104+
105+
const Matcher doesExist = const _DoesExist();
106+
107+
class _DoesExist extends Matcher {
108+
const _DoesExist();
109+
bool matches(item, Map matchState) => item.existsSync();
110+
Description describe(Description description) => description.add('exists');
111+
Description describeMismatch(
112+
item, Description mismatchDescription, Map matchState, bool verbose) {
113+
if (item is! File && item is! Directory) {
114+
return mismatchDescription
115+
.addDescriptionOf(item)
116+
.add('is not a file or directory');
117+
} else {
118+
return mismatchDescription.add(' does not exist');
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)