Forward port benchmark for type checking
[scons.git] / test / Ghostscript / GSFLAGS.py
blobe1471fa059a8fce941f9335b1d953a8436354ae1
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 getopt
40 import os
41 import sys
42 cmd_opts, args = getopt.getopt(sys.argv[1:], 's:x', [])
43 opt_string = ''
44 for opt, arg in cmd_opts:
45 if opt == '-s':
46 if arg[:11] == 'OutputFile=':
47 out_file = open(arg[11:], 'w')
48 else:
49 opt_string = opt_string + ' ' + opt
50 infile = open(args[0], 'r')
51 out_file.write(opt_string + "\n")
52 for l in infile.readlines():
53 if l[:3] != '#ps':
54 out_file.write(l)
55 sys.exit(0)
56 """)
58 test.write('SConstruct', """
59 env = Environment(GS = r'%(_python_)s mygs.py', GSFLAGS = '-x',
60 tools = ['gs'])
61 env.PDF(target = 'test1.pdf', source = 'test1.ps')
62 """ % locals())
64 test.write('test1.ps', """\
65 This is a .ps test.
66 #ps
67 """)
69 test.run(arguments = '.', stderr = None)
71 test.must_match('test1.pdf', " -x\nThis is a .ps test.\n", mode='r')
75 if sys.platform == 'win32':
76 gs_executable = 'gswin32c'
77 elif sys.platform == 'os2':
78 gs_executable = 'gsos2'
79 else:
80 gs_executable = 'gs'
81 gs = test.where_is(gs_executable)
83 if gs:
85 test.file_fixture('wrapper.py')
87 test.write('SConstruct', """\
88 import os
89 ENV = { 'PATH' : os.environ['PATH'] }
90 foo = Environment(ENV = ENV)
91 foo.Append(GSFLAGS = '-q')
92 foo.PDF(target = 'foo.pdf', source = 'foo.ps')
93 """)
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.run(arguments = 'foo.pdf', stderr = None)
104 test.fail_test(not os.path.exists(test.workpath('foo.pdf')))
106 test.pass_test()
108 # Local Variables:
109 # tab-width:4
110 # indent-tabs-mode:nil
111 # End:
112 # vim: set expandtab tabstop=4 shiftwidth=4: