Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Value.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 import re
28
29 import TestSCons
30 import TestCmd
31
32 _python_ = TestSCons._python_
33
34 test = TestSCons.TestSCons(match=TestCmd.match_re)
35
36 python = TestSCons.python
37
38 SConstruct_content = """
39 Decider(r'%(source_signature)s')
40
41 class Custom:
42     def __init__(self, value):  self.value = value
43     def __str__(self):          return "C=" + str(self.value)
44
45 P = ARGUMENTS.get('prefix', '/usr/local')
46 L = len(P)
47 C = Custom(P)
48
49 def create(target, source, env):
50     open(str(target[0]), 'wb').write(source[0].get_contents())
51
52 env = Environment()
53 env['BUILDERS']['B'] = Builder(action = create)
54 env['BUILDERS']['S'] = Builder(action = r'%(_python_)s put.py $SOURCES into $TARGET')
55 env.B('f1.out', Value(P))
56 env.B('f2.out', env.Value(L))
57 env.B('f3.out', Value(C))
58 env.S('f4.out', Value(L))
59
60 def create_value (target, source, env):
61     target[0].write(source[0].get_contents ())
62
63 def create_value_file (target, source, env):
64     open(str(target[0]), 'wb').write(source[0].read())
65
66 env['BUILDERS']['B2'] = Builder(action = create_value)
67 env['BUILDERS']['B3'] = Builder(action = create_value_file)
68
69 V = Value('my value')
70 env.B2(V, 'f3.out')
71 env.B3('f5.out', V)
72 """
73
74 test.write('put.py', """\
75 import os
76 import sys
77 open(sys.argv[-1],'wb').write(" ".join(sys.argv[1:-2]))
78 """)
79
80 # Run all of the tests with both types of source signature
81 # to make sure there's no difference in behavior.
82 for source_signature in ['MD5', 'timestamp-newer']:
83
84     print "Testing Value node with source signatures:", source_signature
85
86     test.write('SConstruct', SConstruct_content % locals())
87
88     test.run(arguments='-c')
89     test.run()
90
91     out7 = """create_value(['my value'], ["f3.out"])"""
92     out8 = """create_value_file(["f5.out"], ['my value'])"""
93
94     out1 = """create(["f1.out"], ['/usr/local'])"""
95     out2 = """create(["f2.out"], [10])"""
96     out3 = """create\\(\\["f3.out"\\], \\[<.*.Custom instance at """
97     #" <- unconfuses emacs syntax highlighting
98
99     test.must_contain_all_lines(test.stdout(), [out1, out2, out7, out8])
100     test.fail_test(re.search(out3, test.stdout()) == None)
101
102     test.must_match('f1.out', "/usr/local")
103     test.must_match('f2.out', "10")
104     test.must_match('f3.out', "C=/usr/local")
105     test.must_match('f4.out', '10')
106     test.must_match('f5.out', "C=/usr/local")
107
108     test.up_to_date(arguments='.')
109
110     test.run(arguments='prefix=/usr')
111     out4 = """create(["f1.out"], ['/usr'])"""
112     out5 = """create(["f2.out"], [4])"""
113     out6 = """create\\(\\["f3.out"\\], \\[<.*.Custom instance at """
114     #" <- unconfuses emacs syntax highlighting
115     test.must_contain_all_lines(test.stdout(), [out4, out5])
116     test.fail_test(re.search(out6, test.stdout()) == None)
117
118     test.must_match('f1.out', "/usr")
119     test.must_match('f2.out', "4")
120     test.must_match('f3.out', "C=/usr")
121     test.must_match('f4.out', '4')
122
123     test.up_to_date('prefix=/usr', '.')
124
125     test.unlink('f3.out')
126
127     test.run(arguments='prefix=/var')
128     out4 = """create(["f1.out"], ['/var'])"""
129
130     test.must_contain_all_lines(test.stdout(), [out4, out7, out8])
131     test.must_not_contain_any_line(test.stdout(), [out5])
132     test.fail_test(re.search(out6, test.stdout()) == None)
133
134     test.up_to_date('prefix=/var', '.')
135
136     test.must_match('f1.out', "/var")
137     test.must_match('f2.out', "4")
138     test.must_match('f3.out', "C=/var")
139     test.must_match('f4.out', "4")
140     test.must_match('f5.out', "C=/var")
141
142 test.pass_test()
143
144 # Local Variables:
145 # tab-width:4
146 # indent-tabs-mode:nil
147 # End:
148 # vim: set expandtab tabstop=4 shiftwidth=4: