Expanded SCons.Scanner.LaTeX.comment_re to not break on \%
[scons.git] / test / TEX / LATEX.py
index 25446961a970af05acbfd2a35148c9c143d515be..03d3a0074ae9764bf909665a24d34af11011d472 100644 (file)
@@ -30,13 +30,9 @@ the produced .dvi, .aux and .log files get removed by the -c option,
 and that we can use this to wrap calls to the real latex utility.
 """
 
-import os
-import os.path
-import string
-import sys
 import TestSCons
 
-python = TestSCons.python
+_python_ = TestSCons._python_
 
 test = TestSCons.TestSCons()
 
@@ -45,8 +41,10 @@ test = TestSCons.TestSCons()
 test.write('mylatex.py', r"""
 import sys
 import os
-base_name = os.path.splitext(sys.argv[1])[0]
-infile = open(sys.argv[1], 'rb')
+import getopt
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
+base_name = os.path.splitext(arg[0])[0]
+infile = open(arg[0], 'rb')
 dvi_file = open(base_name+'.dvi', 'wb')
 aux_file = open(base_name+'.aux', 'wb')
 log_file = open(base_name+'.log', 'wb')
@@ -59,10 +57,10 @@ sys.exit(0)
 """)
 
 test.write('SConstruct', """
-env = Environment(LATEX = r'%s mylatex.py', tools=['latex'])
+env = Environment(LATEX = r'%(_python_)s mylatex.py', tools=['latex'])
 env.DVI(target = 'test1.dvi', source = 'test1.ltx')
 env.DVI(target = 'test2.dvi', source = 'test2.latex')
-""" % python)
+""" % locals())
 
 test.write('test1.ltx', r"""This is a .ltx test.
 \end
@@ -99,11 +97,10 @@ latex = test.where_is('latex')
 if latex:
 
     test.write("wrapper.py", """import os
-import string
 import sys
 open('%s', 'wb').write("wrapper.py\\n")
-os.system(string.join(sys.argv[1:], " "))
-""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
+os.system(" ".join(sys.argv[1:]))
+""" % test.workpath('wrapper.out').replace('\\', '\\\\'))
 
     test.write('SConstruct', """
 import os
@@ -112,15 +109,16 @@ ENV = { 'PATH' : os.environ['PATH'],
 foo = Environment(ENV = ENV)
 latex = foo.Dictionary('LATEX')
 makeindex = foo.Dictionary('MAKEINDEX')
+python_path = r'%(_python_)s'
 bar = Environment(ENV = ENV,
-                  LATEX = r'%s wrapper.py ' + latex,
-                  MAKEINDEX =  r' wrapper.py ' + makeindex)
+                  LATEX = python_path + ' wrapper.py ' + latex,
+                  MAKEINDEX =  python_path + ' wrapper.py ' + makeindex)
 foo.DVI(target = 'foo.dvi', source = 'foo.ltx')
 bar.DVI(target = 'bar', source = 'bar.latex')
 
 bar.DVI(target = 'makeindex', source = 'makeindex.tex')
 foo.DVI(target = 'latexi', source = 'latexi.tex')
-""" % python)
+""" % locals())
 
     latex = r"""
 \documentclass{letter}
@@ -130,7 +128,7 @@ This is the %s LaTeX file.
 """
 
     makeindex =  r"""
-\documentclass{letter}
+\documentclass{report}
 \usepackage{makeidx}
 \makeindex
 \begin{document}
@@ -141,9 +139,9 @@ This is the %s LaTeX file.
 """
 
     latex1 = r"""
-\documentclass{letter}
+\documentclass{report}
 \usepackage{makeidx}
-\makeindex
+\input{latexinputfile}
 \begin{document}
 \index{info}
 This is the %s LaTeX file.
@@ -154,8 +152,12 @@ It has an Index and includes another file.
 """
 
     latex2 = r"""
+\makeindex
+"""
+
+    latex3 = r"""
 \index{include}
-This is the include file.
+This is the include file. mod %s
 \printindex{}
 """
 
@@ -168,7 +170,8 @@ This is the include file.
 
     test.subdir('subdir')
     test.write('latexi.tex',  latex1 % 'latexi.tex');
-    test.write([ 'subdir', 'latexincludefile.tex'], latex2)
+    test.write([ 'subdir', 'latexinputfile'], latex2)
+    test.write([ 'subdir', 'latexincludefile.tex'], latex3 % '1')
 
     test.run(arguments = 'foo.dvi', stderr = None)
     test.must_not_exist('wrapper.out')
@@ -185,6 +188,18 @@ This is the include file.
     test.must_exist('latexi.dvi')
     test.must_exist('latexi.ind')
 
+    test.write([ 'subdir', 'latexincludefile.tex'], latex3 % '2')
+    test.not_up_to_date(arguments = 'latexi.dvi', stderr = None)
+
+    test.run(arguments = '-c', stderr = None)
+    test.must_not_exist('latexi.ind')
+    test.must_not_exist('latexi.ilg')
 
 
 test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: