Replace linux-specific code in test scripts.
authorTom Sepez <tsepez@chromium.org>
Thu, 26 Mar 2015 23:29:05 +0000 (16:29 -0700)
committerTom Sepez <tsepez@chromium.org>
Thu, 26 Mar 2015 23:29:05 +0000 (16:29 -0700)
Now that there's a win bot, this needs to be more careful.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1036073002

testing/tools/run_corpus_tests.py
testing/tools/run_javascript_tests.py
testing/tools/run_pixel_tests.py
testing/tools/text_diff.py [new file with mode: 0755]

index 2f5c413..22f9eef 100755 (executable)
@@ -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:
index fd9cf5f..ff11326 100755 (executable)
@@ -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:
index 0665718..0123583 100755 (executable)
@@ -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 (executable)
index 0000000..3a5bd7b
--- /dev/null
@@ -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))