Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit 1fdead5

Browse files
committed
Make the generate validator use the test syntax
Runs all generators, even if one fails Updated travis.sh
1 parent 3ddfec3 commit 1fdead5

File tree

3 files changed

+103
-57
lines changed

3 files changed

+103
-57
lines changed

test/validate_templates.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
2+
// All rights reserved. Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
@TestOn('vm')
6+
7+
// This is explicitly not named with _test.dart extension so it is not run as
8+
// part of the normal test process
9+
library stagehand.test.validate_templates;
10+
11+
import 'dart:io';
12+
13+
import 'package:grinder/grinder.dart';
14+
import 'package:path/path.dart' as path;
15+
import 'package:stagehand/stagehand.dart' as stagehand;
16+
import 'package:test/test.dart';
17+
import 'package:yaml/yaml.dart' as yaml;
18+
19+
void main() {
20+
Directory dir;
21+
22+
setUp(() async {
23+
dir = await Directory.systemTemp.createTemp('stagehand.test.');
24+
});
25+
26+
tearDown(() async {
27+
if (dir != null) {
28+
await dir.delete(recursive: true);
29+
}
30+
});
31+
32+
for (stagehand.Generator generator in stagehand.generators) {
33+
test(generator.id, () {
34+
_testGenerator(generator, dir);
35+
});
36+
}
37+
}
38+
39+
void _testGenerator(stagehand.Generator generator, Directory tempDir) {
40+
Dart.run(path.join(path.current, 'bin/stagehand.dart'),
41+
arguments: ['--mock-analytics', generator.id],
42+
workingDirectory: tempDir.path);
43+
44+
var pubspecPath = path.join(tempDir.path, 'pubspec.yaml');
45+
var pubspecFile = new File(pubspecPath);
46+
47+
if (!pubspecFile.existsSync()) {
48+
throw 'A pubspec much be defined!';
49+
}
50+
51+
run('pub', arguments: ['get'], workingDirectory: tempDir.path);
52+
53+
var filePath = path.join(tempDir.path, generator.entrypoint.path);
54+
55+
if (path.extension(filePath) != '.dart' ||
56+
!FileSystemEntity.isFileSync(filePath)) {
57+
var parent = new Directory(path.dirname(filePath));
58+
59+
var file = _listSync(parent).firstWhere((f) => f.path.endsWith('.dart'),
60+
orElse: () => null);
61+
62+
if (file == null) {
63+
filePath = null;
64+
} else {
65+
filePath = file.path;
66+
}
67+
}
68+
69+
// Run the analyzer.
70+
if (filePath != null) {
71+
String packagesDir = path.join(tempDir.path, 'packages');
72+
73+
// TODO: We should be able to pass a cwd into `analyzePath`.
74+
Analyzer.analyze(filePath,
75+
fatalWarnings: true, packageRoot: new Directory(packagesDir));
76+
}
77+
78+
//
79+
// Run package tests, if test is included
80+
//
81+
var pubspecContent = yaml.loadYaml(pubspecFile.readAsStringSync());
82+
var devDeps = pubspecContent['dev_dependencies'];
83+
if (devDeps != null) {
84+
if (devDeps.containsKey('test')) {
85+
run('pub', arguments: ['run', 'test'], workingDirectory: tempDir.path);
86+
}
87+
}
88+
}
89+
90+
/**
91+
* Return the list of children for the given directory. This list is normalized
92+
* (by sorting on the file path) in order to prevent large merge diffs in the
93+
* generated template data files.
94+
*/
95+
List<FileSystemEntity> _listSync(Directory dir,
96+
{bool recursive: false, bool followLinks: true}) {
97+
List<FileSystemEntity> results =
98+
dir.listSync(recursive: recursive, followLinks: followLinks);
99+
results.sort((entity1, entity2) => entity1.path.compareTo(entity2.path));
100+
return results;
101+
}

tool/grind.dart

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:ghpages_generator/ghpages_generator.dart' as ghpages;
99
import 'package:grinder/grinder.dart';
1010
import 'package:path/path.dart' as path;
1111
import 'package:stagehand/stagehand.dart' as stagehand;
12-
import 'package:yaml/yaml.dart' as yaml;
1312

1413
final RegExp _binaryFileTypes = new RegExp(
1514
r'\.(jpe?g|png|gif|ico|svg|ttf|eot|woff|woff2)$', caseSensitive: false);
@@ -61,61 +60,7 @@ void updateGhPages() {
6160

6261
@Task('Run each generator and analyze the output')
6362
void test() {
64-
for (stagehand.Generator generator in stagehand.generators) {
65-
Directory dir = Directory.systemTemp.createTempSync('stagehand.test.');
66-
try {
67-
_testGenerator(generator, dir);
68-
} finally {
69-
dir.deleteSync(recursive: true);
70-
}
71-
}
72-
}
73-
74-
void _testGenerator(stagehand.Generator generator, Directory tempDir) {
75-
log('');
76-
log('${generator.id} template:');
77-
78-
Dart.run(path.join(path.current, 'bin/stagehand.dart'),
79-
arguments: ['--mock-analytics', generator.id],
80-
workingDirectory: tempDir.path);
81-
82-
var pubspecPath = path.join(tempDir.path, 'pubspec.yaml');
83-
var pubspecFile = new File(pubspecPath);
84-
85-
if (!pubspecFile.existsSync()) {
86-
throw 'A pubspec much be defined!';
87-
}
88-
89-
run('pub', arguments: ['get'], workingDirectory: tempDir.path);
90-
91-
var filePath = path.join(tempDir.path, generator.entrypoint.path);
92-
93-
if (path.extension(filePath) != '.dart' ||
94-
!FileSystemEntity.isFileSync(filePath)) {
95-
var parent = new Directory(path.dirname(filePath));
96-
97-
var file = _listSync(parent).firstWhere((f) => f.path.endsWith('.dart'),
98-
orElse: () => null);
99-
100-
if (file == null) {
101-
filePath = null;
102-
} else {
103-
filePath = file.path;
104-
}
105-
}
106-
107-
// Run the analyzer.
108-
if (filePath != null) {
109-
Analyzer.analyze(filePath, fatalWarnings: true,
110-
packageRoot: new Directory(path.join(tempDir.path, 'packages')));
111-
}
112-
113-
// Run package tests, if `test` is included.
114-
var pubspecContent = yaml.loadYaml(pubspecFile.readAsStringSync());
115-
var devDeps = pubspecContent['dev_dependencies'];
116-
if (devDeps != null && devDeps.containsKey('test')) {
117-
new PubApp.local('test').run([], workingDirectory: tempDir.path);
118-
}
63+
new PubApp.local('test').run(['test/validate_templates.dart']);
11964
}
12065

12166
void _concatenateFiles(Directory src, File target) {

tool/travis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dartanalyzer --fatal-warnings \
1717
dart test/all.dart
1818

1919
# Run all the generators and analyze the generated code.
20-
dart tool/grind.dart test
20+
pub run test test/validate_templates.dart
2121

2222
# Install dart_coveralls; gather and send coverage data.
2323
if [ "$COVERALLS_TOKEN" ]; then

0 commit comments

Comments
 (0)