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.
31 _python_
= TestSCons
._python
_
33 test
= TestSCons
.TestSCons(match
=TestCmd
.match_re
)
35 python
= TestSCons
.python
37 SConstruct_content
= """
38 Decider(r'%(source_signature)s')
41 def __init__(self, value): self.value = value
42 def __str__(self): return "C=" + str(self.value)
44 P = ARGUMENTS.get('prefix', '/usr/local')
48 def create(target, source, env):
49 with open(str(target[0]), 'wb') as f:
50 f.write(source[0].get_contents())
52 DefaultEnvironment(tools=[]) # test speedup
54 env['BUILDERS']['B'] = Builder(action = create)
55 env['BUILDERS']['S'] = Builder(action = r'%(_python_)s put.py $SOURCES into $TARGET')
56 env.B('f1.out', Value(P))
57 env.B('f2.out', env.Value(L))
58 env.B('f3.out', Value(C))
59 env.S('f4.out', Value(L))
61 def create_value (target, source, env):
62 target[0].write(source[0].get_contents())
64 def create_value_file (target, source, env):
65 with open(str(target[0]), 'wb') as f:
66 f.write(source[0].read())
68 env['BUILDERS']['B2'] = Builder(action = create_value)
69 env['BUILDERS']['B3'] = Builder(action = create_value_file)
76 test
.write('put.py', """\
79 with open(sys.argv[-1],'w') as f:
80 f.write(" ".join(sys.argv[1:-2]))
83 # Run all of the tests with both types of source signature
84 # to make sure there's no difference in behavior.
85 for source_signature
in ['MD5', 'timestamp-newer']:
87 print("Testing Value node with source signatures:", source_signature
)
89 test
.write('SConstruct', SConstruct_content
% locals())
91 test
.run(arguments
='-c')
94 out7
= """create_value(['my value'], ["f3.out"])"""
95 out8
= """create_value_file(["f5.out"], ['my value'])"""
97 out1
= """create(["f1.out"], ['/usr/local'])"""
98 out2
= """create(["f2.out"], [10])"""
99 out3
= """create\\(\\["f3.out"\\], \\[<.*.Custom (instance|object) at """
100 #" <- unconfuses emacs syntax highlighting
102 test
.must_contain_all_lines(test
.stdout(), [out1
, out2
, out7
, out8
])
104 test
.fail_test(re
.search(out3
, test
.stdout()) is None)
106 test
.must_match('f1.out', "/usr/local")
107 test
.must_match('f2.out', "10")
108 test
.must_match('f3.out', "C=/usr/local")
109 test
.must_match('f4.out', '10')
110 test
.must_match('f5.out', "C=/usr/local")
112 test
.up_to_date(arguments
='.')
114 test
.run(options
='prefix=/usr')
115 out4
= """create(["f1.out"], ['/usr'])"""
116 out5
= """create(["f2.out"], [4])"""
117 out6
= """create\\(\\["f3.out"\\], \\[<.*.Custom (instance|object) at """
118 #" <- unconfuses emacs syntax highlighting
119 test
.must_contain_all_lines(test
.stdout(), [out4
, out5
])
120 test
.fail_test(re
.search(out6
, test
.stdout()) is None)
122 test
.must_match('f1.out', "/usr")
123 test
.must_match('f2.out', "4")
124 test
.must_match('f3.out', "C=/usr")
125 test
.must_match('f4.out', '4')
127 test
.up_to_date(options
='prefix=/usr', arguments
='.')
129 test
.unlink('f3.out')
131 test
.run(options
='prefix=/var')
132 out4
= """create(["f1.out"], ['/var'])"""
134 test
.must_contain_all_lines(test
.stdout(), [out4
, out7
, out8
])
135 test
.must_not_contain_any_line(test
.stdout(), [out5
])
136 test
.fail_test(re
.search(out6
, test
.stdout()) is None)
138 test
.up_to_date(options
='prefix=/var', arguments
='.')
140 test
.must_match('f1.out', "/var")
141 test
.must_match('f2.out', "4")
142 test
.must_match('f3.out', "C=/var")
143 test
.must_match('f4.out', "4")
144 test
.must_match('f5.out', "C=/var")
150 # indent-tabs-mode:nil
152 # vim: set expandtab tabstop=4 shiftwidth=4: