mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 15:01:30 +00:00
Put in a teardown for the docs test, fixed dom.py to actually run it correctly.
This also adds a PRESUBMIT.py, which will run on a commit and warn the committer if the docs need to be regenerated. This only runs if the html_dart2js, et. al. files have been modified. Review URL: https://codereview.chromium.org//13251005 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20820 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
e4d9989c3c
commit
40f57a819d
3 changed files with 125 additions and 39 deletions
60
tools/dom/PRESUBMIT.py
Normal file
60
tools/dom/PRESUBMIT.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Copyright (c) 2013, the Dart project authors. 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.
|
||||
|
||||
"""
|
||||
Presubmit tests for dom tools.
|
||||
|
||||
This file is run by git_cl or gcl when an upload or submit happens with
|
||||
any files at this level or lower are in the change list.
|
||||
|
||||
See: http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def _AnySdkFiles(input_api):
|
||||
""" Returns true if any of the changed files are in the sdk, meaning we should
|
||||
check that docs.dart was run.
|
||||
"""
|
||||
for f in input_api.change.AffectedFiles():
|
||||
if f.LocalPath().find('sdk') > -1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
# TODO(amouravski): uncomment this check once docs.dart is faster.
|
||||
# if _AnySdkFiles(input_api):
|
||||
# results.extend(CheckDocs(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
def CheckChangeOnCommit(input_api, output_api):
|
||||
results = []
|
||||
if _AnySdkFiles(input_api):
|
||||
results.extend(CheckDocs(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
def CheckDocs(input_api, output_api):
|
||||
"""Ensure that documentation has been generated if it needs to be generated.
|
||||
|
||||
Prompts with a warning if documentation needs to be generated.
|
||||
"""
|
||||
results = []
|
||||
|
||||
cmd = [os.path.join(input_api.PresubmitLocalPath(), 'dom.py'), 'test_docs']
|
||||
|
||||
try:
|
||||
input_api.subprocess.check_output(cmd,
|
||||
stderr=input_api.subprocess.STDOUT)
|
||||
except (OSError, input_api.subprocess.CalledProcessError), e:
|
||||
results.append(output_api.PresubmitPromptWarning(
|
||||
('Docs test failed!%s\nYou should run `dom.py docs`' % (
|
||||
e if input_api.verbose else ''))))
|
||||
|
||||
return results
|
|
@ -14,38 +14,42 @@ import '../lib/docs.dart';
|
|||
final testJsonPath = scriptDir.append('test.json').canonicalize();
|
||||
|
||||
main() {
|
||||
test('Ensure that docs.json is up to date', () {
|
||||
group('docs', () {
|
||||
var oldJson = new File.fromPath(json_path);
|
||||
var testJson = new File.fromPath(testJsonPath);
|
||||
|
||||
// We should find a json file where we expect it.
|
||||
expect(oldJson.existsSync(), isTrue);
|
||||
|
||||
// Save the last modified time to check it at the end.
|
||||
var oldJsonModified = oldJson.lastModifiedSync();
|
||||
|
||||
// There should be no test file yet.
|
||||
if (testJson.existsSync()) testJson.deleteSync();
|
||||
expect(testJson.existsSync(), isFalse);
|
||||
|
||||
expect(convert(lib_path, testJsonPath)
|
||||
.then((bool anyErrors) {
|
||||
expect(anyErrors, isFalse);
|
||||
|
||||
// We should have a file now.
|
||||
expect(testJson.existsSync(), isTrue);
|
||||
|
||||
// Ensure that there's nothing different between the new JSON and old.
|
||||
expect(testJson.readAsStringSync(), equals(oldJson.readAsStringSync()));
|
||||
|
||||
// Ensure that the old JSON file didn't actually change.
|
||||
expect(oldJsonModified, equals(oldJson.lastModifiedSync()));
|
||||
|
||||
tearDown(() {
|
||||
// Clean up.
|
||||
if (testJson.existsSync()) {
|
||||
testJson.deleteSync();
|
||||
}
|
||||
expect(testJson.existsSync(), isFalse);
|
||||
}), completes);
|
||||
assert(!testJson.existsSync());
|
||||
});
|
||||
|
||||
test('Ensure that docs.json is up to date', () {
|
||||
// We should find a json file where we expect it.
|
||||
expect(oldJson.existsSync(), isTrue);
|
||||
|
||||
// Save the last modified time to check it at the end.
|
||||
var oldJsonModified = oldJson.lastModifiedSync();
|
||||
|
||||
// There should be no test file yet.
|
||||
if (testJson.existsSync()) testJson.deleteSync();
|
||||
assert(!testJson.existsSync());
|
||||
|
||||
expect(convert(lib_path, testJsonPath)
|
||||
.then((bool anyErrors) {
|
||||
expect(anyErrors, isFalse);
|
||||
|
||||
// We should have a file now.
|
||||
expect(testJson.existsSync(), isTrue);
|
||||
|
||||
// Ensure that there's nothing different between the new JSON and old.
|
||||
expect(testJson.readAsStringSync(), equals(oldJson.readAsStringSync()));
|
||||
|
||||
// Ensure that the old JSON file didn't actually change.
|
||||
expect(oldJsonModified, equals(oldJson.lastModifiedSync()));
|
||||
}), completes);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ def help():
|
|||
|
||||
def analyze():
|
||||
''' Runs the dart analyzer. '''
|
||||
call([
|
||||
return call([
|
||||
os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart_analyzer'),
|
||||
os.path.join('tests', 'html', 'element_test.dart'),
|
||||
'--dart-sdk', 'sdk',
|
||||
|
@ -43,7 +43,7 @@ def analyze():
|
|||
|
||||
def build():
|
||||
''' Builds the Dart binary '''
|
||||
call([
|
||||
return call([
|
||||
os.path.join('tools', 'build.py'),
|
||||
'--mode=release',
|
||||
'--arch=ia32',
|
||||
|
@ -54,7 +54,7 @@ def dart2js():
|
|||
compile_dart2js(argv.pop(0), True)
|
||||
|
||||
def dartc():
|
||||
call([
|
||||
return call([
|
||||
os.path.join('tools', 'test.py'),
|
||||
'-m',
|
||||
'release',
|
||||
|
@ -64,6 +64,21 @@ def dartc():
|
|||
'none'
|
||||
])
|
||||
|
||||
def docs():
|
||||
return call([
|
||||
os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart'),
|
||||
'--package-root=%s' % os.path.join(dart_out_dir, 'packages/'),
|
||||
os.path.join('tools', 'dom', 'docs', 'bin', 'docs.dart'),
|
||||
])
|
||||
|
||||
def test_docs():
|
||||
return call([
|
||||
os.path.join('tools', 'test.py'),
|
||||
'--mode=release',
|
||||
'--checked',
|
||||
'docs'
|
||||
])
|
||||
|
||||
def compile_dart2js(dart_file, checked):
|
||||
out_file = dart_file + '.js'
|
||||
dart2js_path = os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart2js')
|
||||
|
@ -82,14 +97,12 @@ def compile_dart2js(dart_file, checked):
|
|||
|
||||
def gen():
|
||||
os.chdir(os.path.join('tools', 'dom', 'scripts'))
|
||||
call([
|
||||
'go.sh',
|
||||
])
|
||||
return call(os.path.join(os.getcwd(), 'go.sh'))
|
||||
|
||||
def http_server():
|
||||
print('Browse tests at '
|
||||
'\033[94mhttp://localhost:5400/root_build/generated_tests/\033[0m')
|
||||
call([
|
||||
return call([
|
||||
utils.DartBinary(),
|
||||
os.path.join('tools', 'testing', 'dart', 'http_server.dart'),
|
||||
'--port=5400',
|
||||
|
@ -103,7 +116,7 @@ def size_check():
|
|||
dart_file = os.path.join('samples', 'swarm', 'swarm.dart')
|
||||
out_file = compile_dart2js(dart_file, False)
|
||||
|
||||
subprocess.call([
|
||||
return call([
|
||||
'du',
|
||||
'-kh',
|
||||
'--apparent-size',
|
||||
|
@ -139,11 +152,13 @@ def test_dart2js(browser, argv):
|
|||
print(
|
||||
'Test commands should be followed by tests to run. Defaulting to html')
|
||||
cmd.append('html')
|
||||
call(cmd)
|
||||
return call(cmd)
|
||||
|
||||
def call(args):
|
||||
print (' '.join(args))
|
||||
subprocess.call(args)
|
||||
print ' '.join(args)
|
||||
return subprocess.call(args,
|
||||
stdout=subprocess.STDOUT,
|
||||
stderr=subprocess.STDERR)
|
||||
|
||||
def init_dir():
|
||||
''' Makes sure that we're always rooted in the dart root folder.'''
|
||||
|
@ -157,8 +172,10 @@ commands = {
|
|||
'build': [build, 'Build dart in release mode'],
|
||||
'dart2js': [dart2js, 'Run dart2js on the .dart file specified'],
|
||||
'dartc': [dartc, 'Runs dartc in release mode'],
|
||||
'docs': [docs, 'Generates docs.json'],
|
||||
'gen': [gen, 'Re-generate DOM generated files (run go.sh)'],
|
||||
'size_check': [size_check, 'Check the size of dart2js compiled Swarm'],
|
||||
'test_docs': [test_docs, 'Tests docs.dart'],
|
||||
'test_chrome': [test_chrome, 'Run tests in checked mode in Chrome.\n'
|
||||
'\t\tOptionally provide name of test to run.'],
|
||||
'test_drt': [test_drt, 'Run tests in checked mode in DumpRenderTree.\n'
|
||||
|
@ -170,10 +187,12 @@ commands = {
|
|||
}
|
||||
|
||||
def main(argv):
|
||||
success = True
|
||||
argv.pop(0)
|
||||
|
||||
if not argv:
|
||||
help()
|
||||
success = False
|
||||
|
||||
while (argv):
|
||||
init_dir()
|
||||
|
@ -181,8 +200,11 @@ def main(argv):
|
|||
|
||||
if not command in commands:
|
||||
help();
|
||||
return
|
||||
commands[command][0]()
|
||||
success = False
|
||||
break
|
||||
success = success and bool(commands[command][0]())
|
||||
|
||||
sys.exit(not success)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv)
|
||||
|
|
Loading…
Reference in a new issue