2012-07-08 17:28:19 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# file src/tex2lyx/test/runtests.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# author Georg Baum
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
2012-10-03 11:59:20 +00:00
|
|
|
# This script is a very basic test suite runner for tex2lyx
|
|
|
|
# The defaults for optional command line arguments are tailored to the
|
|
|
|
# standard use case of testing without special build settings like a version
|
|
|
|
# suffix, since I don't know how to transport command line arguments through
|
|
|
|
# the autotools "make check" mechanism.
|
2012-07-08 17:28:19 +00:00
|
|
|
|
|
|
|
import os, string, sys
|
|
|
|
|
|
|
|
|
|
|
|
def usage(prog_name):
|
2012-10-03 11:59:20 +00:00
|
|
|
return "Usage: %s [<tex2lyx binary> [<script dir>] [<output dir>]]" % prog_name
|
2012-07-08 17:28:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
# Parse and manipulate the command line arguments.
|
2012-10-03 11:59:20 +00:00
|
|
|
if len(argv) >= 3:
|
2012-07-30 07:30:16 +00:00
|
|
|
sys.path.append(os.path.join(sys.argv[2]))
|
|
|
|
else:
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../lib/scripts'))
|
|
|
|
|
2012-07-08 17:28:19 +00:00
|
|
|
from lyxpreview_tools import error
|
|
|
|
|
2012-07-30 07:30:16 +00:00
|
|
|
if len(argv) < 2:
|
2012-07-08 17:28:19 +00:00
|
|
|
tex2lyx = './tex2lyx'
|
2012-10-03 11:59:20 +00:00
|
|
|
elif len(argv) <= 4:
|
2012-07-08 17:28:19 +00:00
|
|
|
tex2lyx = argv[1]
|
|
|
|
else:
|
|
|
|
error(usage(argv[0]))
|
|
|
|
|
2012-10-03 11:59:20 +00:00
|
|
|
inputdir = os.path.dirname(argv[0])
|
|
|
|
if len(argv) >= 4:
|
|
|
|
outputdir = sys.argv[3]
|
|
|
|
else:
|
|
|
|
outputdir = inputdir
|
|
|
|
# outputdir = os.path.join(os.path.dirname(tex2lyx), "test")
|
2012-07-08 17:28:19 +00:00
|
|
|
|
|
|
|
files = ['test.ltx', 'test-structure.tex', 'test-insets.tex', \
|
|
|
|
'box-color-size-space-align.tex', 'CJK.tex', \
|
|
|
|
'XeTeX-polyglossia.tex']
|
|
|
|
|
2012-07-08 18:52:26 +00:00
|
|
|
errors = []
|
2012-07-08 17:28:19 +00:00
|
|
|
for f in files:
|
2012-10-03 11:59:20 +00:00
|
|
|
texfile = os.path.join(inputdir, f)
|
|
|
|
if outputdir == inputdir:
|
|
|
|
cmd = '%s -roundtrip -f %s' % (tex2lyx, texfile)
|
|
|
|
else:
|
|
|
|
lyxfile = os.path.join(outputdir, f)
|
|
|
|
cmd = '%s -roundtrip -copyfiles -f %s %s' % (tex2lyx, texfile, lyxfile)
|
2012-07-08 17:28:19 +00:00
|
|
|
if os.system(cmd) != 0:
|
2012-07-08 18:52:26 +00:00
|
|
|
errors.append(f)
|
2012-07-08 17:28:19 +00:00
|
|
|
|
2012-07-08 18:52:26 +00:00
|
|
|
if len(errors) > 0:
|
|
|
|
error('Converting the following files failed: %s' % ', '.join(errors))
|
2012-07-08 17:28:19 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|
|
|
|
|