[ci skip] update generated files
[scons.git] / test / TEMPFILE / TEMPFILEPREFIX.py
blob3bda5eb17298531fab3f44aa6bb286638de7bbff
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Verify that setting the $TEMPFILEPREFIX variable will cause
28 it to appear at the front of name of the generated tempfile
29 used for long command lines.
30 """
32 import TestSCons
34 test = TestSCons.TestSCons(match=TestSCons.match_re)
36 test.write('SConstruct', """
37 import os
39 env = Environment(
40 BUILDCOM='${TEMPFILE("xxx.py $TARGET $SOURCES")}',
41 MAXLINELENGTH=16,
42 TEMPFILEPREFIX='-via',
44 env.AppendENVPath('PATH', os.curdir)
45 env.Command('foo.out', 'foo.in', '$BUILDCOM')
46 """)
48 test.write('foo.in', "foo.in\n")
50 test.run(
51 arguments='-n -Q .',
52 stdout="""\
53 Using tempfile \\S+ for command line:
54 xxx.py foo.out foo.in
55 xxx.py -via\\S+
56 """)
58 test.write('SConstruct', """
59 import os
61 def print_cmd_line(s, targets, sources, env):
62 pass
64 env = Environment(
65 BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}',
66 MAXLINELENGTH = 16,
67 TEMPFILEPREFIX = '-via',
68 PRINT_CMD_LINE_FUNC=print_cmd_line
70 env.AppendENVPath('PATH', os.curdir)
71 env.Command('foo.out', 'foo.in', '$BUILDCOM')
72 """)
74 test.run(arguments='-n -Q .', stdout="")
76 test.write('SConstruct', """
77 import os
78 from SCons.Platform import TempFileMunge
80 class TestTempFileMunge(TempFileMunge):
81 def __init__(self, cmd, cmdstr=None):
82 super().__init__(cmd, cmdstr)
84 def _print_cmd_str(self, target, source, env, cmdstr):
85 super()._print_cmd_str(target, source, None, cmdstr)
87 env = Environment(
88 TEMPFILE=TestTempFileMunge,
89 BUILDCOM='${TEMPFILE("xxx.py $TARGET $SOURCES")}',
90 MAXLINELENGTH=16,
91 TEMPFILEPREFIX='-via',
93 env.AppendENVPath('PATH', os.curdir)
94 env.Command('foo.out', 'foo.in', '$BUILDCOM')
95 """)
97 test.run(
98 arguments='-n -Q .',
99 stdout="""\
100 Using tempfile \\S+ for command line:
101 xxx.py foo.out foo.in
102 xxx.py -via\\S+
103 """)
105 # make sure an empty prefix works too
106 test.write('SConstruct', """
107 import os
108 from SCons.Platform import TempFileMunge
110 class TestTempFileMunge(TempFileMunge):
111 def __init__(self, cmd, cmdstr=None):
112 super().__init__(cmd, cmdstr)
114 def _print_cmd_str(self, target, source, env, cmdstr):
115 super()._print_cmd_str(target, source, None, cmdstr)
117 env = Environment(
118 TEMPFILE=TestTempFileMunge,
119 BUILDCOM='${TEMPFILE("xxx.py $TARGET $SOURCES")}',
120 MAXLINELENGTH=16,
121 TEMPFILEPREFIX='',
123 env.AppendENVPath('PATH', os.curdir)
124 env.Command('foo.out', 'foo.in', '$BUILDCOM')
125 """)
127 test.run(
128 arguments='-n -Q .',
129 stdout="""\
130 Using tempfile \\S+ for command line:
131 xxx.py foo.out foo.in
132 xxx.py [^@]\\S+
133 """)
135 test.pass_test()
137 # Local Variables:
138 # tab-width:4
139 # indent-tabs-mode:nil
140 # End:
141 # vim: set expandtab tabstop=4 shiftwidth=4: