Added fix for TeX includes with same name as subdirs.
[scons.git] / test / strfunction.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test how using strfunction() to report different types of
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37 test.write('cat.py', """\
38 import sys
39 open(sys.argv[2], "wb").write(open(sys.argv[1], "rb").read())
40 sys.exit(0)
41 """)
42
43 test.write('SConstruct', """\
44 def strfunction(target, source, env):
45     t = str(target[0])
46     s = str(source[0])
47     return "Building %%s from %%s" %% (t, s)
48
49 def func(target, source, env):
50     t = str(target[0])
51     s = str(source[0])
52     open(t, 'w').write(open(s, 'r').read())
53 func1action = Action(func, strfunction)
54 func2action = Action(func, strfunction=strfunction)
55
56 cmd = r'%(_python_)s cat.py $SOURCE $TARGET'
57 cmd1action = Action(cmd, strfunction)
58 cmd2action = Action(cmd, strfunction=strfunction)
59
60 list = [ r'%(_python_)s cat.py $SOURCE .temp',
61          r'%(_python_)s cat.py .temp $TARGET' ]
62 listaction = Action(list, strfunction=strfunction)
63
64 lazy = '$LAZY'
65 lazy1action = Action(lazy, strfunction)
66 lazy2action = Action(lazy, strfunction=strfunction)
67
68 targetaction = Action(func, '$TARGET')
69
70 dict = {
71     '.cmd'      : cmd,
72     '.cmdstr'   : cmd2action,
73     '.func'     : func,
74     '.funcstr'  : func2action,
75     '.list'     : list,
76     '.liststr'  : listaction,
77     '.lazy'     : lazy,
78     '.lazystr'  : lazy2action,
79 }
80
81 env = Environment(BUILDERS = {
82                         'Cmd'           : Builder(action=cmd),
83                         'Cmd1Str'       : Builder(action=cmd1action),
84                         'Cmd2Str'       : Builder(action=cmd2action),
85                         'Func'          : Builder(action=func),
86                         'Func1Str'      : Builder(action=func1action),
87                         'Func2Str'      : Builder(action=func2action),
88                         'Lazy'          : Builder(action=lazy),
89                         'Lazy1Str'      : Builder(action=lazy1action),
90                         'Lazy2Str'      : Builder(action=lazy2action),
91                         'List'          : Builder(action=list),
92                         'ListStr'       : Builder(action=listaction),
93                         'Target'        : Builder(action=targetaction),
94
95                         'Dict'          : Builder(action=dict),
96                   },
97                   LAZY = r'%(_python_)s cat.py $SOURCE $TARGET')
98
99 env.Cmd('cmd.out', 'cmd.in')
100 env.Cmd1Str('cmd1str.out', 'cmdstr.in')
101 env.Cmd2Str('cmd2str.out', 'cmdstr.in')
102 env.Func('func.out', 'func.in')
103 env.Func1Str('func1str.out', 'funcstr.in')
104 env.Func2Str('func2str.out', 'funcstr.in')
105 env.Lazy('lazy.out', 'lazy.in')
106 env.Lazy1Str('lazy1str.out', 'lazystr.in')
107 env.Lazy2Str('lazy2str.out', 'lazystr.in')
108 env.List('list.out', 'list.in')
109 env.ListStr('liststr.out', 'liststr.in')
110 env.Target('target.out', 'target.in')
111
112 env.Dict('dict1.out', 'dict1.cmd')
113 env.Dict('dict2.out', 'dict2.cmdstr')
114 env.Dict('dict3.out', 'dict3.func')
115 env.Dict('dict4.out', 'dict4.funcstr')
116 env.Dict('dict5.out', 'dict5.lazy')
117 env.Dict('dict6.out', 'dict6.lazystr')
118 env.Dict('dict7.out', 'dict7.list')
119 env.Dict('dict8.out', 'dict8.liststr')
120 """ % locals())
121
122 test.write('func.in',           "func.in\n")
123 test.write('funcstr.in',        "funcstr.in\n")
124 test.write('cmd.in',            "cmd.in\n")
125 test.write('cmdstr.in',         "cmdstr.in\n")
126 test.write('lazy.in',           "lazy.in\n")
127 test.write('lazystr.in',        "lazystr.in\n")
128 test.write('list.in',           "list.in\n")
129 test.write('liststr.in',        "liststr.in\n")
130 test.write('target.in',         "target.in\n")
131
132 test.write('dict1.cmd',         "dict1.cmd\n")
133 test.write('dict2.cmdstr',      "dict2.cmdstr\n")
134 test.write('dict3.func',        "dict3.func\n")
135 test.write('dict4.funcstr',     "dict4.funcstr\n")
136 test.write('dict5.lazy',        "dict4.lazy\n")
137 test.write('dict6.lazystr',     "dict6.lazystr\n")
138 test.write('dict7.list',        "dict7.list\n")
139 test.write('dict8.liststr',     "dict8.liststr\n")
140
141 expect = test.wrap_stdout("""\
142 %(_python_)s cat.py cmd.in cmd.out
143 Building cmd1str.out from cmdstr.in
144 Building cmd2str.out from cmdstr.in
145 %(_python_)s cat.py dict1.cmd dict1.out
146 Building dict2.out from dict2.cmdstr
147 func(["dict3.out"], ["dict3.func"])
148 Building dict4.out from dict4.funcstr
149 %(_python_)s cat.py dict5.lazy dict5.out
150 Building dict6.out from dict6.lazystr
151 %(_python_)s cat.py dict7.list .temp
152 %(_python_)s cat.py .temp dict7.out
153 Building dict8.out from dict8.liststr
154 Building dict8.out from dict8.liststr
155 func(["func.out"], ["func.in"])
156 Building func1str.out from funcstr.in
157 Building func2str.out from funcstr.in
158 %(_python_)s cat.py lazy.in lazy.out
159 Building lazy1str.out from lazystr.in
160 Building lazy2str.out from lazystr.in
161 %(_python_)s cat.py list.in .temp
162 %(_python_)s cat.py .temp list.out
163 Building liststr.out from liststr.in
164 Building liststr.out from liststr.in
165 target.out
166 """ % locals())
167
168 test.run(arguments = '.', stdout=expect)
169
170 test.pass_test()
171
172 # Local Variables:
173 # tab-width:4
174 # indent-tabs-mode:nil
175 # End:
176 # vim: set expandtab tabstop=4 shiftwidth=4: