Merge pull request #4677 from mwichmann/issue/debug-memoizer
[scons.git] / test / Ghostscript / GS.py
blob68f74276fe89424017fa84676ddb9b5c2cdff6de
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 import os
28 import sys
30 import TestSCons
32 _python_ = TestSCons._python_
34 test = TestSCons.TestSCons()
38 test.write('mygs.py', r"""
39 import os
40 import sys
41 outfile = open(sys.argv[1], 'w')
42 infile = open(sys.argv[2], 'r')
43 for l in infile.readlines():
44 if l[:3] != '#ps':
45 outfile.write(l)
46 sys.exit(0)
47 """)
49 test.write('SConstruct', """
50 env = Environment(GS = r'%(_python_)s mygs.py',
51 GSCOM = r'$GS $TARGET $SOURCE',
52 tools=['gs'])
53 env.PDF(target = 'test1.pdf', source = 'test1.ps')
54 env.Gs(target = 'test2.pdf', source = 'test1.ps')
55 """ % locals())
57 test.write('test1.ps', r"""This is a .ps test.
58 #ps
59 """)
61 test.run(arguments = '.', stderr = None)
63 test.must_match('test1.pdf', "This is a .ps test.\n", mode='r')
64 test.must_match('test2.pdf', "This is a .ps test.\n", mode='r')
68 if sys.platform == 'win32':
69 gs_executable = 'gswin32c'
70 elif sys.platform == 'os2':
71 gs_executable = 'gsos2'
72 else:
73 gs_executable = 'gs'
74 gs = test.where_is(gs_executable)
76 if gs:
77 test.write("wrapper.py", """\
78 import subprocess
79 import sys
80 cmd = " ".join(sys.argv[1:])
81 open('%s', 'a').write("%%s\\n" %% cmd)
82 subprocess.run(cmd, shell=True)
83 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
85 test.write('SConstruct', """\
86 import os
87 foo = Environment(ENV = { 'PATH' : os.environ['PATH'] })
88 gs = foo.Dictionary('GS')
89 bar = Environment(ENV = { 'PATH' : os.environ['PATH'] },
90 GS = r'%(_python_)s wrapper.py ' + gs)
91 foo.PDF(target = 'foo.pdf', source = 'foo.ps')
92 bar.PDF(target = 'bar.pdf', source = 'bar.ps')
93 """ % locals())
95 input = """\
96 %!PS-Adobe
97 100 100 moveto /Times-Roman findfont 24 scalefont (Hello, world!) show showpage
98 """
100 test.write('foo.ps', input)
102 test.write('bar.ps', input)
104 test.run(arguments = 'foo.pdf', stderr = None)
106 test.fail_test(os.path.exists(test.workpath('wrapper.out')))
108 test.fail_test(not os.path.exists(test.workpath('foo.pdf')))
110 test.run(arguments = 'bar.pdf', stderr = None)
112 test.must_match('wrapper.out', "%s -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=bar.pdf bar.ps\n" % gs_executable, mode='r')
114 test.fail_test(not os.path.exists(test.workpath('bar.pdf')))
116 test.pass_test()
118 # Local Variables:
119 # tab-width:4
120 # indent-tabs-mode:nil
121 # End:
122 # vim: set expandtab tabstop=4 shiftwidth=4: