[ci skip] update generated files
[scons.git] / test / strfunction.py
blob04e23aae5954290ea61c6b4b53e2d0f95a3c27c2
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 """
28 Test how using strfunction() to report different types of
29 """
31 import TestSCons
33 _python_ = TestSCons._python_
35 test = TestSCons.TestSCons()
37 test.write('cat.py', """\
38 import sys
39 with open(sys.argv[2], "wb") as f, open(sys.argv[1], "rb") as ifp:
40 f.write(ifp.read())
41 sys.exit(0)
42 """)
44 test.write('SConstruct', """\
45 def strfunction(target, source, env):
46 t = str(target[0])
47 s = str(source[0])
48 return "Building %%s from %%s" %% (t, s)
50 def func(target, source, env):
51 t = str(target[0])
52 s = str(source[0])
53 with open(t, 'w') as f, open(s, 'r') as ifp:
54 f.write(ifp.read())
55 func1action = Action(func, strfunction)
56 func2action = Action(func, strfunction=strfunction)
58 cmd = r'%(_python_)s cat.py $SOURCE $TARGET'
59 cmd1action = Action(cmd, strfunction)
60 cmd2action = Action(cmd, strfunction=strfunction)
62 list = [ r'%(_python_)s cat.py $SOURCE .temp',
63 r'%(_python_)s cat.py .temp $TARGET' ]
64 listaction = Action(list, strfunction=strfunction)
66 lazy = '$LAZY'
67 lazy1action = Action(lazy, strfunction)
68 lazy2action = Action(lazy, strfunction=strfunction)
70 targetaction = Action(func, '$TARGET')
72 dict = {
73 '.cmd' : cmd,
74 '.cmdstr' : cmd2action,
75 '.func' : func,
76 '.funcstr' : func2action,
77 '.list' : list,
78 '.liststr' : listaction,
79 '.lazy' : lazy,
80 '.lazystr' : lazy2action,
83 env = Environment(BUILDERS = {
84 'Cmd' : Builder(action=cmd),
85 'Cmd1Str' : Builder(action=cmd1action),
86 'Cmd2Str' : Builder(action=cmd2action),
87 'Func' : Builder(action=func),
88 'Func1Str' : Builder(action=func1action),
89 'Func2Str' : Builder(action=func2action),
90 'Lazy' : Builder(action=lazy),
91 'Lazy1Str' : Builder(action=lazy1action),
92 'Lazy2Str' : Builder(action=lazy2action),
93 'List' : Builder(action=list),
94 'ListStr' : Builder(action=listaction),
95 'Target' : Builder(action=targetaction),
97 'Dict' : Builder(action=dict),
99 LAZY = r'%(_python_)s cat.py $SOURCE $TARGET')
101 env.Cmd('cmd.out', 'cmd.in')
102 env.Cmd1Str('cmd1str.out', 'cmdstr.in')
103 env.Cmd2Str('cmd2str.out', 'cmdstr.in')
104 env.Func('func.out', 'func.in')
105 env.Func1Str('func1str.out', 'funcstr.in')
106 env.Func2Str('func2str.out', 'funcstr.in')
107 env.Lazy('lazy.out', 'lazy.in')
108 env.Lazy1Str('lazy1str.out', 'lazystr.in')
109 env.Lazy2Str('lazy2str.out', 'lazystr.in')
110 env.List('list.out', 'list.in')
111 env.ListStr('liststr.out', 'liststr.in')
112 env.Target('target.out', 'target.in')
114 env.Dict('dict1.out', 'dict1.cmd')
115 env.Dict('dict2.out', 'dict2.cmdstr')
116 env.Dict('dict3.out', 'dict3.func')
117 env.Dict('dict4.out', 'dict4.funcstr')
118 env.Dict('dict5.out', 'dict5.lazy')
119 env.Dict('dict6.out', 'dict6.lazystr')
120 env.Dict('dict7.out', 'dict7.list')
121 env.Dict('dict8.out', 'dict8.liststr')
122 """ % locals())
124 test.write('func.in', "func.in\n")
125 test.write('funcstr.in', "funcstr.in\n")
126 test.write('cmd.in', "cmd.in\n")
127 test.write('cmdstr.in', "cmdstr.in\n")
128 test.write('lazy.in', "lazy.in\n")
129 test.write('lazystr.in', "lazystr.in\n")
130 test.write('list.in', "list.in\n")
131 test.write('liststr.in', "liststr.in\n")
132 test.write('target.in', "target.in\n")
134 test.write('dict1.cmd', "dict1.cmd\n")
135 test.write('dict2.cmdstr', "dict2.cmdstr\n")
136 test.write('dict3.func', "dict3.func\n")
137 test.write('dict4.funcstr', "dict4.funcstr\n")
138 test.write('dict5.lazy', "dict4.lazy\n")
139 test.write('dict6.lazystr', "dict6.lazystr\n")
140 test.write('dict7.list', "dict7.list\n")
141 test.write('dict8.liststr', "dict8.liststr\n")
143 expect = test.wrap_stdout("""\
144 %(_python_)s cat.py cmd.in cmd.out
145 Building cmd1str.out from cmdstr.in
146 Building cmd2str.out from cmdstr.in
147 %(_python_)s cat.py dict1.cmd dict1.out
148 Building dict2.out from dict2.cmdstr
149 func(["dict3.out"], ["dict3.func"])
150 Building dict4.out from dict4.funcstr
151 %(_python_)s cat.py dict5.lazy dict5.out
152 Building dict6.out from dict6.lazystr
153 %(_python_)s cat.py dict7.list .temp
154 %(_python_)s cat.py .temp dict7.out
155 Building dict8.out from dict8.liststr
156 Building dict8.out from dict8.liststr
157 func(["func.out"], ["func.in"])
158 Building func1str.out from funcstr.in
159 Building func2str.out from funcstr.in
160 %(_python_)s cat.py lazy.in lazy.out
161 Building lazy1str.out from lazystr.in
162 Building lazy2str.out from lazystr.in
163 %(_python_)s cat.py list.in .temp
164 %(_python_)s cat.py .temp list.out
165 Building liststr.out from liststr.in
166 Building liststr.out from liststr.in
167 target.out
168 """ % locals())
170 test.run(arguments = '.', stdout=expect)
172 test.pass_test()
174 # Local Variables:
175 # tab-width:4
176 # indent-tabs-mode:nil
177 # End:
178 # vim: set expandtab tabstop=4 shiftwidth=4: