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

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

Issue 1036073002: Replace linux-specific code in test scripts. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use sys.executable Created 5 years, 9 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/run_corpus_tests.py ('k') | testing/tools/run_pixel_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The PDFium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import optparse 6 import optparse
7 import os 7 import os
8 import re 8 import re
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 11
12 # Nomenclature: 12 # Nomenclature:
13 # x_root - "x" 13 # x_root - "x"
14 # x_filename - "x.ext" 14 # x_filename - "x.ext"
15 # x_path - "path/to/a/b/c/x.ext" 15 # x_path - "path/to/a/b/c/x.ext"
16 # c_dir - "path/to/a/b/c" 16 # c_dir - "path/to/a/b/c"
17 17
18 def generate_and_test(input_filename, source_dir, working_dir, 18 def generate_and_test(input_filename, source_dir, working_dir,
19 fixup_path, pdfium_test_path): 19 fixup_path, pdfium_test_path, text_diff_path):
20 input_root, _ = os.path.splitext(input_filename) 20 input_root, _ = os.path.splitext(input_filename)
21 input_path = os.path.join(source_dir, input_root + '.in') 21 input_path = os.path.join(source_dir, input_root + '.in')
22 pdf_path = os.path.join(working_dir, input_root + '.pdf') 22 pdf_path = os.path.join(working_dir, input_root + '.pdf')
23 txt_path = os.path.join(working_dir, input_root + '.txt') 23 txt_path = os.path.join(working_dir, input_root + '.txt')
24 expected_path = os.path.join(source_dir, input_root + '_expected.txt') 24 expected_path = os.path.join(source_dir, input_root + '_expected.txt')
25 try: 25 try:
26 sys.stdout.flush() 26 sys.stdout.flush()
27 subprocess.check_call( 27 subprocess.check_call(
28 [fixup_path, '--output-dir=' + working_dir, input_path]) 28 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path])
29 with open(txt_path, 'w') as outfile: 29 with open(txt_path, 'w') as outfile:
30 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile) 30 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile)
31 subprocess.check_call(['diff', expected_path, txt_path]) 31 subprocess.check_call(
32 [sys.executable, text_diff_path, expected_path, txt_path])
32 except subprocess.CalledProcessError as e: 33 except subprocess.CalledProcessError as e:
33 print "FAILURE: " + input_filename + "; " + str(e) 34 print "FAILURE: " + input_filename + "; " + str(e)
34 return False 35 return False
35 return True 36 return True
36 37
37 def main(): 38 def main():
38 parser = optparse.OptionParser() 39 parser = optparse.OptionParser()
39 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), 40 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
40 help='relative path from the base source directory') 41 help='relative path from the base source directory')
41 options, args = parser.parse_args() 42 options, args = parser.parse_args()
42 43
43 # Expect |my_dir| to be .../pdfium/testing/tools. 44 # Expect |my_dir| to be .../pdfium/testing/tools.
44 my_dir = os.path.dirname(os.path.realpath(__file__)) 45 my_dir = os.path.dirname(os.path.realpath(__file__))
45 testing_dir = os.path.dirname(my_dir) 46 testing_dir = os.path.dirname(my_dir)
46 pdfium_dir = os.path.dirname(testing_dir) 47 pdfium_dir = os.path.dirname(testing_dir)
47 if (os.path.basename(my_dir) != 'tools' or 48 if (os.path.basename(my_dir) != 'tools' or
48 os.path.basename(testing_dir) != 'testing'): 49 os.path.basename(testing_dir) != 'testing'):
49 print 'Confused, can not find pdfium root directory, aborting.' 50 print 'Confused, can not find pdfium root directory, aborting.'
50 return 1 51 return 1
51 52
52 # Other scripts are found in the same directory as this one. 53 # Other scripts are found in the same directory as this one.
53 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py') 54 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py')
55 text_diff_path = os.path.join(my_dir, 'text_diff.py')
54 56
55 # test files are in .../pdfium/testing/resources/javascript. 57 # test files are in .../pdfium/testing/resources/javascript.
56 source_dir = os.path.join(testing_dir, 'resources', 'javascript') 58 source_dir = os.path.join(testing_dir, 'resources', 'javascript')
57 59
58 # Find path to build directory. This depends on whether this is a 60 # Find path to build directory. This depends on whether this is a
59 # standalone build vs. a build as part of a chromium checkout. For 61 # standalone build vs. a build as part of a chromium checkout. For
60 # standalone, we expect a path like .../pdfium/out/Debug, but for 62 # standalone, we expect a path like .../pdfium/out/Debug, but for
61 # chromium, we expect a path like .../src/out/Debug two levels 63 # chromium, we expect a path like .../src/out/Debug two levels
62 # higher (to skip over the third_party/pdfium path component under 64 # higher (to skip over the third_party/pdfium path component under
63 # which chromium sticks pdfium). 65 # which chromium sticks pdfium).
(...skipping 17 matching lines...) Expand all
81 if not os.path.exists(working_dir): 83 if not os.path.exists(working_dir):
82 os.makedirs(working_dir) 84 os.makedirs(working_dir)
83 85
84 failures = [] 86 failures = []
85 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') 87 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
86 for input_filename in os.listdir(source_dir): 88 for input_filename in os.listdir(source_dir):
87 if input_file_re.match(input_filename): 89 if input_file_re.match(input_filename):
88 input_path = os.path.join(source_dir, input_filename) 90 input_path = os.path.join(source_dir, input_filename)
89 if os.path.isfile(input_path): 91 if os.path.isfile(input_path):
90 if not generate_and_test(input_filename, source_dir, working_dir, 92 if not generate_and_test(input_filename, source_dir, working_dir,
91 fixup_path, pdfium_test_path): 93 fixup_path, pdfium_test_path, text_diff_path):
92 failures.append(input_path) 94 failures.append(input_path)
93 95
94 if failures: 96 if failures:
95 print '\n\nSummary of Failures:' 97 print '\n\nSummary of Failures:'
96 for failure in failures: 98 for failure in failures:
97 print failure 99 print failure
98 return 1 100 return 1
99 return 0 101 return 0
100 102
101 103
102 if __name__ == '__main__': 104 if __name__ == '__main__':
103 sys.exit(main()) 105 sys.exit(main())
OLDNEW
« no previous file with comments | « testing/tools/run_corpus_tests.py ('k') | testing/tools/run_pixel_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698