This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the generate validator use the test syntax
Runs all generators, even if one fails Updated travis.sh
- Loading branch information
Showing
3 changed files
with
103 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2014, Google Inc. Please see the AUTHORS file 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. | ||
|
||
@TestOn('vm') | ||
|
||
// This is explicitly not named with _test.dart extension so it is not run as | ||
// part of the normal test process | ||
library stagehand.test.validate_templates; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:grinder/grinder.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:stagehand/stagehand.dart' as stagehand; | ||
import 'package:test/test.dart'; | ||
import 'package:yaml/yaml.dart' as yaml; | ||
|
||
void main() { | ||
Directory dir; | ||
|
||
setUp(() async { | ||
dir = await Directory.systemTemp.createTemp('stagehand.test.'); | ||
}); | ||
|
||
tearDown(() async { | ||
if (dir != null) { | ||
await dir.delete(recursive: true); | ||
} | ||
}); | ||
|
||
for (stagehand.Generator generator in stagehand.generators) { | ||
test(generator.id, () { | ||
_testGenerator(generator, dir); | ||
}); | ||
} | ||
} | ||
|
||
void _testGenerator(stagehand.Generator generator, Directory tempDir) { | ||
Dart.run(path.join(path.current, 'bin/stagehand.dart'), | ||
arguments: ['--mock-analytics', generator.id], | ||
workingDirectory: tempDir.path); | ||
|
||
var pubspecPath = path.join(tempDir.path, 'pubspec.yaml'); | ||
var pubspecFile = new File(pubspecPath); | ||
|
||
if (!pubspecFile.existsSync()) { | ||
throw 'A pubspec much be defined!'; | ||
} | ||
|
||
run('pub', arguments: ['get'], workingDirectory: tempDir.path); | ||
|
||
var filePath = path.join(tempDir.path, generator.entrypoint.path); | ||
|
||
if (path.extension(filePath) != '.dart' || | ||
!FileSystemEntity.isFileSync(filePath)) { | ||
var parent = new Directory(path.dirname(filePath)); | ||
|
||
var file = _listSync(parent).firstWhere((f) => f.path.endsWith('.dart'), | ||
orElse: () => null); | ||
|
||
if (file == null) { | ||
filePath = null; | ||
} else { | ||
filePath = file.path; | ||
} | ||
} | ||
|
||
// Run the analyzer. | ||
if (filePath != null) { | ||
String packagesDir = path.join(tempDir.path, 'packages'); | ||
|
||
// TODO: We should be able to pass a cwd into `analyzePath`. | ||
Analyzer.analyze(filePath, | ||
fatalWarnings: true, packageRoot: new Directory(packagesDir)); | ||
} | ||
|
||
// | ||
// Run package tests, if test is included | ||
// | ||
var pubspecContent = yaml.loadYaml(pubspecFile.readAsStringSync()); | ||
var devDeps = pubspecContent['dev_dependencies']; | ||
if (devDeps != null) { | ||
if (devDeps.containsKey('test')) { | ||
run('pub', arguments: ['run', 'test'], workingDirectory: tempDir.path); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Return the list of children for the given directory. This list is normalized | ||
* (by sorting on the file path) in order to prevent large merge diffs in the | ||
* generated template data files. | ||
*/ | ||
List<FileSystemEntity> _listSync(Directory dir, | ||
{bool recursive: false, bool followLinks: true}) { | ||
List<FileSystemEntity> results = | ||
dir.listSync(recursive: recursive, followLinks: followLinks); | ||
results.sort((entity1, entity2) => entity1.path.compareTo(entity2.path)); | ||
return results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters