]> git.lyx.org Git - features.git/commitdiff
1.) Add format to CJK.lyx.lyx(missed in previous commit)
authorKornel Benko <kornel@lyx.org>
Fri, 28 Dec 2012 15:22:25 +0000 (16:22 +0100)
committerKornel Benko <kornel@lyx.org>
Fri, 28 Dec 2012 15:22:25 +0000 (16:22 +0100)
2.) Add lyx2lyx test to runtests.py. This is done with extra parameter only,
  and does not change the behaviour without this parameter.

src/tex2lyx/test/CJK.lyx.lyx
src/tex2lyx/test/CMakeLists.txt
src/tex2lyx/test/runtests.py

index ef1b7fbad3c83ca0eeebf59d84047c8792364ca6..6ebad1a19a287f7716b3d25919ea80717d78defe 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 453
+\lyxformat 456
 \begin_document
 \begin_header
 \textclass article
index 4994641a1c73e9d2d27a4d2924cb0fbb57bde8bf..36be3606781dc0fe43a08069a35483781f819bb0 100644 (file)
@@ -23,6 +23,13 @@ foreach(_fl ${_tex_tests})
     "${TOP_SRC_DIR}/lib/scripts"
     "${CMAKE_CURRENT_BINARY_DIR}"
     ${fl})
+  add_test(NAME tex2lyx2lyx/roundtrip/${_fl}
+    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+    COMMAND ${LYX_PYTHON_EXECUTABLE} "${TOP_SRC_DIR}/src/tex2lyx/test/runtests.py" "uselyx2lyx"
+    "$<TARGET_FILE:${_tex2lyx}>"
+    "${TOP_SRC_DIR}/lib/scripts"
+    "${CMAKE_CURRENT_BINARY_DIR}"
+    ${fl})
 endforeach()
 
 add_dependencies(lyx_run_tests ${_tex2lyx} ${_lyx})
index 406a96e22e3e65936118f53e94f37a99da4680b1..bfa4c2a2e3f13496f1c45a4f134dd16ca382db6e 100755 (executable)
 import os, string, sys, time, difflib, filecmp, subprocess, re
 
 def usage(prog_name):
-  return "Usage: %s [<tex2lyx binary> [[<script dir>] [[<output dir>] [testfile]]]]" % prog_name
+  return "Usage: %s [uselyx2lyx] [<tex2lyx binary> [[<script dir>] [[<output dir>] [testfile]]]]" % prog_name
 
 
 def main(argv):
     # Parse and manipulate the command line arguments.
-    if len(argv) >= 3:
-       sys.path.append(os.path.join(sys.argv[2]))
+    skipcount = 0
+    uselyx2lyx = False
+    if len(argv) > 1:
+        if argv[1] == "uselyx2lyx":
+            uselyx2lyx = True
+            skipcount = 1
+    if len(argv) >= 3+skipcount:
+       sys.path.append(os.path.join(sys.argv[2+skipcount]))
     else:
        sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../lib/scripts'))
 
     from lyxpreview_tools import error
 
-    if len(argv) < 2:
+    if len(argv) < 2+skipcount:
         tex2lyx = './tex2lyx'
-    elif len(argv) <= 5:
-        tex2lyx = argv[1]
+    elif len(argv) <= 5+skipcount:
+        tex2lyx = argv[1+skipcount]
     else:
         error(usage(argv[0]))
 
     lyx = os.path.join(os.path.dirname(tex2lyx), "lyx")
     inputdir = os.path.dirname(argv[0])
-    if len(argv) >= 4:
-        outputdir = sys.argv[3]
+    if len(argv) >= 4+skipcount:
+        outputdir = sys.argv[3+skipcount]
     else:
 #        outputdir = inputdir
         outputdir = os.path.join(os.path.dirname(tex2lyx), "test")
 
-    if len(argv) >= 5:
-        files = [sys.argv[4]]
+    if len(argv) >= 5+skipcount:
+        files = [sys.argv[4+skipcount]]
     else:
         files = ['test.ltx', 'test-structure.tex', 'test-insets.tex', \
              'test-modules.tex', 'box-color-size-space-align.tex', \
@@ -63,7 +69,7 @@ def main(argv):
             cmd = '%s -roundtrip -f %s' % (tex2lyx, texfile)
         else:
             lyxfile = os.path.join(outputdir, base + ".lyx")
-            cmd = '%s -copyfiles -f %s %s' % (tex2lyx, texfile, lyxfile)
+            cmd = '%s -roundtrip -copyfiles -f %s %s' % (tex2lyx, texfile, lyxfile)
         proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
         proc.wait()
         err = proc.returncode
@@ -73,24 +79,43 @@ def main(argv):
         if err != 0:
             errors.append(f)
         elif not overwrite:
-            lyxfile1 = os.path.join(inputdir, base + ".lyx.lyx")
-            lyxfile2 = os.path.join(outputdir, base + ".lyx")
-            if not filecmp.cmp(lyxfile1, lyxfile2, False):
-                t1 = time.ctime(os.path.getmtime(lyxfile1))
-                t2 = time.ctime(os.path.getmtime(lyxfile2))
-                f1 = open(lyxfile1, 'r')
-                f2 = open(lyxfile2, 'r')
-                lines1 = f1.readlines()
-                lines2 = f2.readlines()
-                diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
-                f1.close()
-                f2.close()
-                sys.stdout.writelines(diff)
+            lyxfile1 = getlyxinput(lyx,
+                        os.path.join(inputdir, base + ".lyx.lyx"),
+                        os.path.join(outputdir, base + ".lyx1.lyx") , uselyx2lyx)
+            if lyxfile1 is None:
                 errors.append(f)
+            else:
+                lyxfile2 = getlyxinput(lyx,
+                          os.path.join(outputdir, base + ".lyx"),
+                          os.path.join(outputdir, base + ".lyx2.lyx"), uselyx2lyx)
+                if lyxfile2 is None:
+                    errors.append(f)
+                elif not filecmp.cmp(lyxfile1, lyxfile2, False):
+                    t1 = time.ctime(os.path.getmtime(lyxfile1))
+                    t2 = time.ctime(os.path.getmtime(lyxfile2))
+                    f1 = open(lyxfile1, 'r')
+                    f2 = open(lyxfile2, 'r')
+                    lines1 = f1.readlines()
+                    lines2 = f2.readlines()
+                    diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
+                    f1.close()
+                    f2.close()
+                    sys.stdout.writelines(diff)
+                    errors.append(f)
 
     if len(errors) > 0:
         error('Converting the following files failed: %s' % ', '.join(errors))
 
+def getlyxinput(lyx, lyxfx, lyxf, uselyx2lyx):
+    if uselyx2lyx:
+        cmd = '%s -E lyx %s %s' % (lyx, lyxf, lyxfx)
+        sys.stdout.writelines(cmd)
+        if os.system(cmd) != 0:
+            return None
+        return lyxf
+    else:
+        return lyxfx
+
 if __name__ == "__main__":
     main(sys.argv)