Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: testing/tools/run_javascript_tests.py

Issue 912803004: Create run_javascript_tests.py (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: typos. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/tools/fixup_pdf_template.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 The PDFium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import optparse
7 import os
8 import re
9 import subprocess
10 import sys
11
12 # Nomenclature:
13 # x_root - "x"
14 # x_filename - "x.ext"
15 # x_path - "path/to/a/b/c/x.ext"
16 # c_dir - "path/to/a/b/c"
17
18 def generate_and_test(input_filename, source_dir, working_dir,
19 fixup_path, pdfium_test_path):
20 input_root, _ = os.path.splitext(input_filename)
21 input_path = os.path.join(source_dir, input_root + '.in')
22 pdf_path = os.path.join(working_dir, input_root + '.pdf')
23 txt_path = os.path.join(working_dir, input_root + '.txt')
24 expected_path = os.path.join(source_dir, input_root + '_expected.txt')
25 try:
26 subprocess.check_call(
27 [fixup_path, '--output-dir=' + working_dir, input_path])
28 with open(txt_path, 'w') as outfile:
29 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile)
30 subprocess.check_call(['diff', expected_path, txt_path])
31 except subprocess.CalledProcessError as e:
32 print "FAILURE: " + input_filename + "; " + str(e)
33
34 def main():
35 parser = optparse.OptionParser()
36 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'))
Lei Zhang 2015/02/11 22:45:34 Add a help message: parser.add_option('--build-
Tom Sepez 2015/02/12 18:18:49 Done.
37 options, args = parser.parse_args()
38
39 # Expect |my_dir| to be .../pdfium/testing/tools.
40 my_dir = os.path.dirname(os.path.realpath(__file__))
41 testing_dir = os.path.dirname(my_dir)
42 pdfium_dir = os.path.dirname(testing_dir)
43 if os.path.basename(pdfium_dir) != 'pdfium':
44 print 'Confused, can not find pdfium directory, aborting.'
45 return 1
46
47 # Other scripts are found in the same directory as this one.
48 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py')
49
50 # test files are in .../pdfium/testing/resources/javascript.
51 source_dir = os.path.join(testing_dir, 'resources', 'javascript')
52
53 # Find path to build directory. This depends on whether this is a
54 # standalone build vs. a build as part of a chromium checkout. For
55 # standalone, we expect a path like .../pdfium/out/Debug, but for
56 # chromium, we expect a path like .../src/out/Debug two levels
57 # higher (to skip over the third_party/pdfium path component under
58 # which chromium sticks pdfium).
59 base_dir = pdfium_dir
60 one_up_dir = os.path.dirname(base_dir)
61 two_up_dir = os.path.dirname(one_up_dir)
62 if (os.path.basename(two_up_dir) == 'src' and
63 os.path.basename(one_up_dir) == 'third_party'):
64 base_dir = two_up_dir
65 build_dir = os.path.join(base_dir, options.build_dir)
66
67 # Compiled binaries are found under the build path.
68 pdfium_test_path = os.path.join(build_dir, 'pdfium_test')
69 if sys.platform.startswith('win'):
70 pdfium_test_path = pdfium_test_path + '.exe'
71 # TODO(tsepez): Mac may require special handling here.
72
73 # Place generated files under the build directory, not source directory.
74 gen_dir = os.path.join(build_dir, 'gen', 'pdfium')
75 working_dir = os.path.join(gen_dir, 'testing', 'javascript')
76 if not os.path.exists(working_dir):
77 os.makedirs(working_dir)
78
79 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
Lei Zhang 2015/02/11 22:45:34 Alternatively, you can use glob: input_paths = gl
Tom Sepez 2015/02/12 18:18:49 Done.
80 for input_filename in os.listdir(source_dir):
81 if input_file_re.match(input_filename):
82 generate_and_test(input_filename, source_dir, working_dir,
83 fixup_path, pdfium_test_path)
84 return 0
85
86
87 if __name__ == '__main__':
88 sys.exit(main())
OLDNEW
« no previous file with comments | « testing/tools/fixup_pdf_template.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698