diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-03-26 16:29:05 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-03-26 16:29:05 -0700 |
commit | 84e50d58496622af351cd27da51479059736923d (patch) | |
tree | 1358a04b895e9692b4a3a2d65522b15ffcf6ca64 | |
parent | 30506b41ea88cf6743c314743ce477e8186a3945 (diff) | |
download | pdfium-84e50d58496622af351cd27da51479059736923d.tar.xz |
Replace linux-specific code in test scripts.
Now that there's a win bot, this needs to be more careful.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1036073002
-rwxr-xr-x | testing/tools/run_corpus_tests.py | 3 | ||||
-rwxr-xr-x | testing/tools/run_javascript_tests.py | 10 | ||||
-rwxr-xr-x | testing/tools/run_pixel_tests.py | 2 | ||||
-rwxr-xr-x | testing/tools/text_diff.py | 32 |
4 files changed, 41 insertions, 6 deletions
diff --git a/testing/tools/run_corpus_tests.py b/testing/tools/run_corpus_tests.py index 2f5c413f61..22f9eefe14 100755 --- a/testing/tools/run_corpus_tests.py +++ b/testing/tools/run_corpus_tests.py @@ -7,6 +7,7 @@ import optparse import os import re import subprocess +import shutil import sys # Nomenclature: @@ -30,8 +31,8 @@ def test_one_file(input_filename, source_dir, working_dir, expected_path_template = os.path.join(source_dir, input_root + '_expected.pdf.%d.png') try: + shutil.copyfile(input_path, pdf_path) sys.stdout.flush() - subprocess.check_call(['cp', input_path, pdf_path]) subprocess.check_call([pdfium_test_path, '--png', pdf_path]) i = 0; while True: diff --git a/testing/tools/run_javascript_tests.py b/testing/tools/run_javascript_tests.py index fd9cf5f870..ff11326e5c 100755 --- a/testing/tools/run_javascript_tests.py +++ b/testing/tools/run_javascript_tests.py @@ -16,7 +16,7 @@ import sys # c_dir - "path/to/a/b/c" def generate_and_test(input_filename, source_dir, working_dir, - fixup_path, pdfium_test_path): + fixup_path, pdfium_test_path, text_diff_path): input_root, _ = os.path.splitext(input_filename) input_path = os.path.join(source_dir, input_root + '.in') pdf_path = os.path.join(working_dir, input_root + '.pdf') @@ -25,10 +25,11 @@ def generate_and_test(input_filename, source_dir, working_dir, try: sys.stdout.flush() subprocess.check_call( - [fixup_path, '--output-dir=' + working_dir, input_path]) + [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) with open(txt_path, 'w') as outfile: subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile) - subprocess.check_call(['diff', expected_path, txt_path]) + subprocess.check_call( + [sys.executable, text_diff_path, expected_path, txt_path]) except subprocess.CalledProcessError as e: print "FAILURE: " + input_filename + "; " + str(e) return False @@ -51,6 +52,7 @@ def main(): # Other scripts are found in the same directory as this one. fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py') + text_diff_path = os.path.join(my_dir, 'text_diff.py') # test files are in .../pdfium/testing/resources/javascript. source_dir = os.path.join(testing_dir, 'resources', 'javascript') @@ -88,7 +90,7 @@ def main(): input_path = os.path.join(source_dir, input_filename) if os.path.isfile(input_path): if not generate_and_test(input_filename, source_dir, working_dir, - fixup_path, pdfium_test_path): + fixup_path, pdfium_test_path, text_diff_path): failures.append(input_path) if failures: diff --git a/testing/tools/run_pixel_tests.py b/testing/tools/run_pixel_tests.py index 0665718ef4..0123583a5e 100755 --- a/testing/tools/run_pixel_tests.py +++ b/testing/tools/run_pixel_tests.py @@ -32,7 +32,7 @@ def generate_and_test(input_filename, source_dir, working_dir, try: sys.stdout.flush() subprocess.check_call( - [fixup_path, '--output-dir=' + working_dir, input_path]) + [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) subprocess.check_call([pdfium_test_path, '--png', pdf_path]) i = 0; while True: diff --git a/testing/tools/text_diff.py b/testing/tools/text_diff.py new file mode 100755 index 0000000000..3a5bd7bf6a --- /dev/null +++ b/testing/tools/text_diff.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# Copyright 2015 The PDFium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import difflib +import sys + +def main(argv): + if len(argv) != 3: + print '%s: invalid arguments' % argv[0] + return 2 + filename1 = argv[1] + filename2 = argv[2] + try: + with open(filename1, "r") as f1: + str1 = f1.readlines(); + with open(filename2, "r") as f2: + str2 = f2.readlines(); + diffs = difflib.unified_diff( + str1, str2, fromfile=filename1, tofile=filename2) + except Exception as e: + print "something went astray: %s" % e + return 1 + status_code = 0 + for diff in diffs: + sys.stdout.write(diff) + status_code = 1 + return status_code + +if __name__ == '__main__': + sys.exit(main(sys.argv)) |